Intermediate level · Module 8: Vector Databases and Semantic Retrieval · Lesson 1 of 3
Chroma Collections and Persistence
Learners store chunks, embeddings and metadata in a persistent local Chroma database and query it.
In this lesson you will
- Create and persist a Chroma collection
- Query it by embedding similarity
Key concepts
PersistentClientcollectionadd with ids, documents, metadatasquery with n_resultsrebuild script
The lesson
Chroma (Apache-2.0) runs locally: chromadb.PersistentClient(path='db') stores data on disk, client.get_or_create_collection('docs') creates a collection, and collection.add(ids=..., documents=..., metadatas=..., embeddings=...) stores chunks.
collection.query(query_embeddings=[q], n_results=5) returns the nearest chunks with their metadata and distances. Use the same embedding model for documents and queries.
Keep a rebuild script so the database can always be recreated from the approved documents.
Step by step
- Create a persistent collection.
- Add the project chunks with metadata and embeddings.
- Query ten questions.
- Delete the database and rebuild it with the script.
Practice activity
Store the project collection in Chroma with a rebuild script.
Expected result: A persistent, rebuildable collection that answers queries.
Check your understanding
-
Why must documents and queries use the same embedding model?
Show answer
Vectors from different models are not comparable.
-
Why keep a rebuild script?
Show answer
So the database can always be recreated from approved documents.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.