Skip to content

Instantly share code, notes, and snippets.

@ctindel
Created January 27, 2025 19:43
Show Gist options
  • Save ctindel/344eb77be3df69458eebcddf01ad6dc1 to your computer and use it in GitHub Desktop.
Save ctindel/344eb77be3df69458eebcddf01ad6dc1 to your computer and use it in GitHub Desktop.
Print all Weaviate Collections along with document counts
import weaviate
import weaviate.classes as wvc
import weaviate.classes.config as wc
import os
import json
try:
client = weaviate.connect_to_local(headers={})
assert client.is_live()
collections = client.collections.list_all()
# Print all collection names
for name in collections:
print(name)
collection = client.collections.get(name)
aggregation = collection.aggregate.over_all(total_count=True)
print(aggregation.total_count)
except Exception as e:
print(e)
finally: # This will always be executed, even if an exception is raised
client.close() # Close the connection & release resources
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment