DS DevShelfHub Projects · AI tools
Tutorials / LangChain / Reference / Classes / Chroma
Vector Store langchain-chroma Beginner

Chroma: Reference Guide

By DevShelfHub

Store and search embeddings with Chroma vector database.

What is Chroma?

Chroma is an open-source, embeddings-first vector database and the default store most LangChain RAG tutorials reach for. It runs in-process — no server to provision — and can hold vectors purely in memory for tests or persist them to a local directory for development that survives restarts. In LangChain it is wrapped by the Chroma vectorstore class from the langchain-chroma package, which adds the standard add_documents, similarity_search, and as_retriever surface on top of the native client.

You typically create a store with Chroma.from_documents(docs, embeddings), which embeds each chunk and writes it in one call, or construct an empty Chroma(embedding_function=...) and add documents incrementally. Pass persist_directory to write to disk; in recent versions persistence is automatic, so the old manual .persist() call is no longer required. Each record carries the original text, your metadata, and an id, which means you can filter by metadata at query time and upsert by id to update documents in place.

Retrieval supports plain similarity_search, similarity_search_with_score when you need the distances, max-marginal-relevance for diversity, and metadata where-filters for hybrid lookups. The most common mistake is querying with a different embedding model than you indexed with — Chroma cannot detect the mismatch and silently returns garbage neighbours. Chroma is ideal for prototypes and small-to-medium corpora; once you need horizontal scale, replication, or managed uptime, graduate to Pinecone or Qdrant, both of which expose the same LangChain retriever interface so the swap is mostly config.

When to Use

You're developing a RAG system or building a prototype. Use Chroma for rapid iteration without infrastructure complexity.

Use Cases

  • RAG prototyping
  • Development and testing
  • Small to medium datasets
  • Semantic search
  • Documentation search
  • Chat with documents

Key Features

  • Easy setup
  • In-memory and persistent
  • Fast similarity search
  • Metadata filtering
  • No external dependencies
  • LangChain integration

When NOT to Use

For production at scale—use Pinecone or Qdrant. For very large datasets.

Notes

Index and query with the same embeddings

Chroma stores raw vectors and has no idea which model produced them. If you index with OpenAIEmbeddings and later query with a different model or dimension, results are silently wrong. Pin one embedding_function and re-index from scratch whenever you change it.

Persistence is automatic now

Pass persist_directory to write to disk. In current langchain-chroma releases data is flushed automatically, so the old .persist() call is gone — calling it raises AttributeError. To reopen a saved collection, construct Chroma with the same collection_name, embedding_function, and persist_directory.

Metadata filters and MMR

as_retriever accepts search_type='mmr' for diversity and a filter dict for metadata constraints, e.g. {"source": "handbook"}. Use similarity_search_with_score when you need the raw distance to apply a relevance threshold rather than a fixed k.

Know the scale ceiling

Chroma is in-process and single-node. It is excellent up to a few hundred thousand vectors, but it has no built-in replication or managed uptime. When you outgrow it, Pinecone and Qdrant expose the same LangChain retriever interface, so the migration is mostly configuration.

Import

python
from langchain_chroma import Chroma

Initialization Parameters

Parameter Type Default Purpose
embedding_function Embeddings None Embedding model to use

Code Examples

Index documents and run a similarity search

python
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings

vector_store = Chroma.from_documents(documents, OpenAIEmbeddings())
hits = vector_store.similarity_search('refund policy', k=4)
for doc in hits:
    print(doc.page_content[:100])

Persist a collection to disk

python
from langchain_chroma import Chroma
from langchain_openai import OpenAIEmbeddings

store = Chroma(
    collection_name='docs',
    embedding_function=OpenAIEmbeddings(),
    persist_directory='./chroma_db',
)
store.add_documents(documents)

MMR retriever with a metadata filter

python
retriever = vector_store.as_retriever(
    search_type='mmr',
    search_kwargs={'k': 4, 'filter': {'source': 'handbook'}},
)
results = retriever.invoke('vacation accrual')

Common Mistakes

❌ Forget to provide embeddings

✅ vector_store = Chroma.from_documents(docs, embeddings)

Alternative Vector Stores

Store When to Use
Pinecone For production scale and high availability

Browse the full LangChain API reference index to explore more classes, methods, and decorators, or start with the LangChain introduction tutorial for end-to-end context on building with Chroma and the wider framework.

Chroma FAQ

What is Chroma in LangChain?

Store and search embeddings with Chroma vector database. Chroma is an open-source, embeddings-first vector database and the default store most LangChain RAG tutorials reach for. It runs in-process — no server to provision — and can hold vectors purely in memory for tests or persist them to a local directory for development that survives restarts. In LangChain it is wrapped by the Chroma vectorstore class from the langchain-chroma package, which adds the standard add_documents, similarity_search, and as_retriever surface on top of t…

Which package provides Chroma?

DevShelfHub documents Chroma from the langchain-chroma package. Pin your installed LangChain version and match imports to the snippet on this page.

When should I use Chroma?

You're developing a RAG system or building a prototype. Use Chroma for rapid iteration without infrastructure complexity.

When should I avoid using Chroma?

For production at scale—use Pinecone or Qdrant. For very large datasets.

How do I import Chroma in Python?

from langchain_chroma import Chroma

Where can I explore more LangChain API reference pages?

Open the LangChain API reference index on DevShelfHub to browse classes, methods, and decorators, each with runnable examples, parameters, common mistakes, and cross-links.