Created
January 23, 2024 19:34
-
-
Save dudanogueira/b08e60952631d3b90cb1f4e1de432134 to your computer and use it in GitHub Desktop.
Weaviate Dimension and Object Count
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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