| name | chroma |
| description | Open-source embedding database for AI applications. Store embeddings and metadata, perform vector and full-text search, filter by metadata. Simple 4-function API. Scales from notebooks to production clusters. Use for semantic search, RAG applications, or document retrieval. Best for local development and open-source projects. |
| version | 1.0.0 |
| author | Orchestra Research |
| license | MIT |
| dependencies | ["chromadb","sentence-transformers"] |
| platforms | ["linux","macos","windows"] |
| metadata | {"hermes":{"tags":["RAG","Chroma","Vector Database","Embeddings","Semantic Search","Open Source","Self-Hosted","Document Retrieval","Metadata Filtering"]}} |
Chroma - Open-Source Embedding Database
The AI-native database for building LLM applications with memory.
When to use Chroma
Use Chroma when:
- Building RAG (retrieval-augmented generation) applications
- Need local/self-hosted vector database
- Want open-source solution (Apache 2.0)
- Prototyping in notebooks
- Semantic search over documents
- Storing embeddings with metadata
Metrics:
- 24,300+ GitHub stars
- 1,900+ forks
- v1.3.3 (stable, weekly releases)
- Apache 2.0 license
Use alternatives instead:
- Pinecone: Managed cloud, auto-scaling
- FAISS: Pure similarity search, no metadata
- Weaviate: Production ML-native database
- Qdrant: High performance, Rust-based
Quick start
Installation
pip install chromadb
npm install chromadb @chroma-core/default-embed
Basic usage (Python)
import chromadb
client = chromadb.Client()
collection = client.create_collection(name="my_collection")
collection.add(
documents=["This is document 1", "This is document 2"],
metadatas=[{"source": "doc1"}, {"source": "doc2"}],
ids=["id1", "id2"]
)
results = collection.query(
query_texts=["document about topic"],
n_results=2
)
print(results)
Core operations
1. Create collection
collection = client.create_collection("my_docs")
from chromadb.utils import embedding_functions
openai_ef = embedding_functions.OpenAIEmbeddingFunction(
api_key="your-key",
model_name="text-embedding-3-small"
)
collection = client.create_collection(
name="my_docs",
embedding_function=openai_ef
)
collection = client.get_collection("my_docs")
client.delete_collection("my_docs")
2. Add documents
collection.add(
documents=["Doc 1", "Doc 2", "Doc 3"],
metadatas=[
{"source": "web", "category": "tutorial"},
{"source": "pdf", "page": 5},
{"source": "api", "timestamp": "2025-01-01"}
],
ids=["id1", "id2", "id3"]
)
collection.add(
embeddings=[[0.1, 0.2, ...], [0.3, 0.4, ...]],
documents=["Doc 1", "Doc 2"],
ids=["id1", "id2"]
)
3. Query (similarity search)
results = collection.query(
query_texts=["machine learning tutorial"],
n_results=5
)
results = collection.query(
query_texts=["Python programming"],
n_results=3,
where={"source": "web"}
)
results = collection.query(
query_texts=["advanced topics"],
where={
"$and": [
{"category": "tutorial"},
{"difficulty": {"$gte": 3}}
]
}
)
print(results["documents"])
print(results["metadatas"])
print(results["distances"])
print(results["ids"])
4. Get documents
docs = collection.get(
ids=["id1", "id2"]
)
docs = collection.get(
where={"category": "tutorial"},
limit=10
)
docs = collection.get()
5. Update documents
collection.update(
ids=["id1"],
documents=["Updated content"],
metadatas=[{"source": "updated"}]
)
6. Delete documents
collection.delete(ids=["id1", "id2"])
collection.delete(
where={"source": "outdated"}
)
Persistent storage
client = chromadb.PersistentClient(path="./chroma_db")
collection = client.create_collection("my_docs")
collection.add(documents=["Doc 1"], ids=["id1"])
client = chromadb.PersistentClient(path="./chroma_db")
collection = client.get_collection("my_docs")
Embedding functions
Default (Sentence Transformers)
collection = client.create_collection("my_docs")
OpenAI
from chromadb.utils import embedding_functions
openai_ef = embedding_functions.OpenAIEmbeddingFunction(
api_key="your-key",
model_name="text-embedding-3-small"
)
collection = client.create_collection(
name="openai_docs",
embedding_function=openai_ef
)
HuggingFace
huggingface_ef = embedding_functions.HuggingFaceEmbeddingFunction(
api_key="your-key",
model_name="sentence-transformers/all-mpnet-base-v2"
)
collection = client.create_collection(
name="hf_docs",
embedding_function=huggingface_ef
)
Custom embedding function
from chromadb import Documents, EmbeddingFunction, Embeddings
class MyEmbeddingFunction(EmbeddingFunction):
def __call__(self, input: Documents) -> Embeddings:
return embeddings
my_ef = MyEmbeddingFunction()
collection = client.create_collection(
name="custom_docs",
embedding_function=my_ef
)
Metadata filtering
results = collection.query(
query_texts=["query"],
where={"category": "tutorial"}
)
results = collection.query(
query_texts=["query"],
where={"page": {"$gt": 10}}
)
results = collection.query(
query_texts=["query"],
where={
"$and": [
{"category": "tutorial"},
{"difficulty": {"$lte": 3}}
]
}
)
results = collection.query(
query_texts=["query"],
where={"tags": {"$in": ["python", "ml"]}}
)
LangChain integration
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings
from langchain.text_splitter import RecursiveCharacterTextSplitter
text_splitter = RecursiveCharacterTextSplitter(chunk_size=1000)
docs = text_splitter.split_documents(documents)
vectorstore = Chroma.from_documents(
documents=docs,
embedding=OpenAIEmbeddings(),
persist_directory="./chroma_db"
)
results = vectorstore.similarity_search("machine learning", k=3)
retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
LlamaIndex integration
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.core import VectorStoreIndex, StorageContext
import chromadb
db = chromadb.PersistentClient(path="./chroma_db")
collection = db.get_or_create_collection("my_collection")
vector_store = ChromaVectorStore(chroma_collection=collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
index = VectorStoreIndex.from_documents(
documents,
storage_context=storage_context
)
query_engine = index.as_query_engine()
response = query_engine.query("What is machine learning?")
Server mode
import chromadb
from chromadb.config import Settings
client = chromadb.HttpClient(
host="localhost",
port=8000,
settings=Settings(anonymized_telemetry=False)
)
collection = client.get_or_create_collection("my_docs")
Best practices
- Use persistent client - Don't lose data on restart
- Add metadata - Enables filtering and tracking
- Batch operations - Add multiple docs at once
- Choose right embedding model - Balance speed/quality
- Use filters - Narrow search space
- Unique IDs - Avoid collisions
- Regular backups - Copy chroma_db directory
- Monitor collection size - Scale up if needed
- Test embedding functions - Ensure quality
- Use server mode for production - Better for multi-user
Performance
| Operation | Latency | Notes |
|---|
| Add 100 docs | ~1-3s | With embedding |
| Query (top 10) | ~50-200ms | Depends on collection size |
| Metadata filter | ~10-50ms | Fast with proper indexing |
Resources