我正在使用 ChromaDB 集合,需要有效地提取特定元数据字段的所有唯一值的列表。
collection = client.get_collection(collection_name)
unique_keys = collection.get(where={"$distinct": "metadata_key"}) #not working as expected
#in db `metadata_key` is like `sentiment` that can have value like good, bad, etc
目前我使用这种低效的方式
all_metadatas = collection.get(include=["metadatas"]).get('metadatas')
distinct_keys = set([x.get('metadata_key') for x in all_metadatas])