Skip to main content

Read all objects

Weaviate provides the necessary APIs to iterate through all your data. This is useful when you want to manually copy/migrate your data (and vector embeddings) from one place to another.

This is done with the help of the after operator, also called the cursor API.

Iterator

The new API clients (currently supported by the Python Client v4), encapsulate this functionality as an Iterator.

Read object properties and ids

The following code iterates through all objects, providing the properties and id for each object.

collection = client.collections.get("WineReview")

for item in collection.iterator():
print(item.uuid, item.properties)

Read all objects including vectors

Read through all data including the vectors. (Also applicable where named vectors are used.)

collection = client.collections.get("WineReview")

for item in collection.iterator(
include_vector=True # If using named vectors, you can specify ones to include e.g. ['title', 'body'], or True to include all
):
print(item.properties)
print(item.vector)

Read all objects - Multi-tenant collections

Iterate through all tenants and read data for each.

Multi-tenancy

For classes where multi-tenancy is enabled, you need to specify the tenant name when reading or creating objects. See Manage data: multi-tenancy operations for details.

multi_collection = client.collections.get("WineReviewMT")

# Get a list of tenants
tenants = multi_collection.tenants.get()

# Iterate through tenants
for tenant_name in tenants.keys():
# Iterate through objects within each tenant
for item in multi_collection.with_tenant(tenant_name).iterator():
print(f"{tenant_name}: {item.properties}")

Questions and feedback

If you have any questions or feedback, let us know in the user forum.