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.
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.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
collection = client.collections.use("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.)
If a snippet doesn't work or you have feedback, please open a GitHub issue.
collection = client.collections.use("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.
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.
If a snippet doesn't work or you have feedback, please open a GitHub issue.
multi_collection = client.collections.use("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}")
Related pages
- Connect to Weaviate
- How-to: Read objects
- References: GraphQL - Additional Operators
- Manage data: multi-tenancy operations
Questions and feedback
If you have any questions or feedback, let us know in the user forum.