Search code examples
large-language-modelchromadb

ChromaDB limit queries by metadata


I have a ChromaDB that has "source_type" = 'guideline' | 'practice' | 'open_letter'. If my k/p_value is the default of 6, is there a way I can limit my similarity search first based on "source_type", THEN get the 6 pieces of evidence? Is this a thing LangChain can help with?

From a mechanical perspective I just have 3 databases now and query each separately, but it would be nice to have one that can be queried in this way. It's fine for now, but I'm just thinking this would be cleaner. If another database solves this problem and Chroma doesn't have the capability yet I'm all ears.

Thanks,

Mark


Solution

  • Have you used where when querying ?

    results = collection.query(
        query_texts=["This is a question or text"],
        n_results=5,
        where={"source_type": "guideline"}
    )