[Python] ChromaDB get list of unique metadata field

Discussão em 'Python' iniciado por Stack, Setembro 9, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working with a ChromaDB collection and need to efficiently extract a list of all unique values for a specific metadata field.


    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



    currently I using this inefficient way

    all_metadatas = collection.get(include=["metadatas"]).get('metadatas')
    distinct_keys = set([x.get('metadata_key') for x in all_metadatas])

    Continue reading...

Compartilhe esta Página