A Chroma vector store gives a LangChain application a local collection for embedded documents and similarity search. It fits RAG prototypes where the first milestone is proving that source text can be stored, reopened, and queried before a hosted vector database is introduced.
The current integration uses the separate langchain-chroma package and the Chroma class from langchain_chroma. The smoke test uses a small deterministic embedding class so the workflow needs no API key and returns the same match on every run.
For production retrieval, replace the deterministic embeddings with the embedding provider used by the rest of the RAG project. The same vector-store calls add Document objects, read the stored IDs, reopen the persistent directory, and run similarity_search().
$ python3 -m pip install --upgrade langchain-chroma Collecting langchain-chroma Downloading langchain_chroma-1.1.0-py3-none-any.whl.metadata (1.9 kB) ##### snipped ##### Successfully installed chromadb-1.5.9 langchain-chroma-1.1.0 langchain-core-1.4.8 numpy-2.5.1
langchain-chroma installs chromadb and langchain-core. Install langchain separately only when the project also uses agents, models, or other application APIs.
Related: How to install LangChain with pip
from pathlib import Path from shutil import rmtree from langchain_chroma import Chroma from langchain_core.documents import Document from langchain_core.embeddings import Embeddings class KeywordEmbeddings(Embeddings): vocabulary = ( "chroma", "persistent", "collection", "password", "invoice", "billing", ) def _embed(self, text: str) -> list[float]: lower_text = text.lower() return [float(lower_text.count(term)) for term in self.vocabulary] def embed_documents(self, texts: list[str]) -> list[list[float]]: return [self._embed(text) for text in texts] def embed_query(self, text: str) -> list[float]: return self._embed(text) persist_directory = Path("chroma_langchain_db") if persist_directory.exists(): rmtree(persist_directory) collection_name = "support_knowledge" embeddings = KeywordEmbeddings() documents = [ Document( page_content=( "Chroma stores embedded support notes in a local persistent collection." ), metadata={"source": "architecture"}, ), Document( page_content="Password reset tickets should route to the identity queue.", metadata={"source": "accounts"}, ), Document( page_content="Invoice export failures should route to billing operations.", metadata={"source": "billing"}, ), ] vector_store = Chroma( collection_name=collection_name, embedding_function=embeddings, persist_directory=str(persist_directory), ) vector_store.add_documents( documents=documents, ids=["architecture-chroma", "accounts-password", "billing-invoice"], ) stored_ids = vector_store.get()["ids"] reopened_store = Chroma( collection_name=collection_name, embedding_function=embeddings, persist_directory=str(persist_directory), ) reopened_ids = reopened_store.get()["ids"] query = "persistent Chroma collection" top_match = reopened_store.similarity_search(query, k=1)[0] print(f"collection: {collection_name}") print(f"documents stored: {len(stored_ids)}") print(f"reopened documents: {len(reopened_ids)}") print(f"query: {query}") print(f"top match source: {top_match.metadata['source']}") print(f"top match text: {top_match.page_content}")
The script removes only chroma_langchain_db in the current directory before rebuilding the demo collection. Rename persist_directory if that path already contains data.
$ python3 build_chroma_store.py collection: support_knowledge documents stored: 3 reopened documents: 3 query: persistent Chroma collection top match source: architecture top match text: Chroma stores embedded support notes in a local persistent collection.
$ rm -r build_chroma_store.py chroma_langchain_db