Chroma: Collections and Metadata
What you'll learn: How to organize your vectors in Chroma using collections and add metadata filters for more precise semantic searches.
The Core Idea
In Chroma, a collection is like a table in a traditional database—it's a named container that holds your vectors, documents, and associated metadata. You can create multiple collections to organize different types of data (like "customer_reviews" vs "product_docs").
Metadata are key-value pairs attached to each vector that describe non-semantic attributes (like {"author": "Alice", "year": 2023}). The magic happens when you combine semantic search with metadata filtering using where clauses—this lets you find documents that are semantically similar and match specific criteria.
How It Works
Think of it like searching a library: semantic search finds books with similar content, while metadata filters let you narrow down by publication year, genre, or author. Together, they give you filtered semantic search.
In Chroma, you query with conditions like:
where={"author": "Alice"}- exact matchwhere={"year": {"$gt": 2020}}- greater than 2020where={"$and": [{"type": "blog"}, {"year": 2023}]}- combined conditions
Collections in Action
When you create a collection, you give it a unique name. You add documents with metadata alongside their embeddings. Later, when querying, your where clause pre-filters the vectors before similarity search runs, making searches faster and more relevant.
Key Takeaway: Chroma collections organize your vectors, while metadata and where clauses let you filter semantic search by structured attributes—combining the best of both worlds for precise, context-aware retrieval.