Skip to content

Instantly share code, notes, and snippets.

@dudanogueira
Created January 23, 2024 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudanogueira/b08e60952631d3b90cb1f4e1de432134 to your computer and use it in GitHub Desktop.
Save dudanogueira/b08e60952631d3b90cb1f4e1de432134 to your computer and use it in GitHub Desktop.
Weaviate Dimension and Object Count
dim = 0
objects = 0
for c in client.schema.get()["classes"]:
# get class name
class_name = c["class"]
# get object count
count_query = client.query.aggregate(class_name).with_meta_count().do()
if not count_query.get("errors"):
object_count = count_query["data"]["Aggregate"][class_name][0]["meta"]["count"]
# get one object, to discover the dimensions length
dimension_query = client.query.get(class_name).with_additional("vector").with_limit(1).do()
if dimension_query["data"]["Get"][class_name]:
dimension_length = len(dimension_query["data"]["Get"][class_name][0]["_additional"]["vector"])
# add up the dimensions for each object
dim += object_count * dimension_length
else:
dimension_length = 0
# add up the object count for each collection
objects += object_count
print(class_name, object_count, dimension_length)
else:
print("ERROR!", class_name, count_query.get("errors"))
print("####")
print("total_dimensions", dim)
print("objects", objects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment