匠人学院 JR Academy
Skip to article
Learning guide
ChromaDB Guide

Build local and lightweight retrieval systems with ChromaDB, embeddings, and RAG workflows.

2 chapters·4 guides·Access varies by chapter
Collections
On this page

ChromaDB Collections

A collection defines a retrieval boundary. Stable IDs, metadata and deletion/archive policy become increasingly important as the corpus grows.

#Collection operations

python
collection = client.create_collection(name="test_name") collection = client.get_or_create_collection(name="test_name") collection = client.get_collection(name="test_name") # Destructive: removes the named collection. # client.delete_collection(name="test_name")

#Record fields

ids identify records. embeddings hold supplied vectors. documents hold source text and can be embedded by a configured function. metadatas hold filterable attributes. Field requirements and valid combinations should match the client version.

Agree on IDs and useful fields such as source, language, document type and update time. These are retrieval decisions as well as maintenance conventions.

#Update or upsert

python
collection.update(ids=["id1"], metadatas=[{"status": "archived"}]) collection.upsert( ids=["id1", "id3"], documents=["Updated content", "New content"], ) # Destructive examples; review the target first: # collection.delete(ids=["id1"]) # collection.delete(where={"status": "archived"})

#Filter the query

python
results = collection.query( query_texts=["Find relevant guidance"], where={"source": "notion"}, n_results=5, ) results = collection.query( query_texts=["Find relevant guidance"], where_document={"$contains": "important"}, )

#Distance metrics

The source discusses squared L2, inner product and cosine distance, with a legacy metadata={"hnsw:space": "cosine"} configuration example. Check your installed Chroma version's collection configuration API before copying it.

Evaluate chunking and metadata before repeatedly switching metrics. Relevant boundaries often matter more than changing the distance formula.

#Next step

Published by
JR Academy
Learning resources

Individual authors and reviewers are credited where recorded.

System Design

Core system design concepts and practical case studies

Learn the trade-offs and patterns that matter in technical interviews.

Open System Design →

Related Roadmaps

Done reading? Next steps