Fetch_objects only returns 10 items is limit is no specified

I have a simple collection with 1700 items
I want to retrieve all of them
to do so, I am using the following code:

collection = client.collections.get('collection_name')
response = collection.query.fetch_objects()
all_items = [i.properties for i in response.objects]
print(len(all_items)) -> this prints 10

but if i do the following:

collection = client.collections.get('collection_name')
response = collection.query.fetch_objects(limit = 2000)
all_items = [i.properties for i in response.objects]
print(len(all_items)) -> this prints 1700

Is there a way to get all the items in a collection without having to specify the limit?

Hi @Sharhad_Bashar,

Welcome to our community and it’s great to have you here.

You can fetch all objects and print them out using the following way:
I provide an example with a counter for demonstration:

I’ve 88 objects in my dataset

collection = client.collections.get(“docs”)
counter = 0
for item in collection.iterator(
include_vector=False
):
counter += 1
print(item.properties)
print(counter)

Result:

image

Ref:

This is what I did to get all files in the collection:

collection = client.collections.get('collection_name')
file_list = []
for obj in collection.iterator():
  file_list.append(obj.properties['file_path'])

Using that, you can print the number of documents too:

print(len(file_list))
1 Like