Chroma data is empty after a restart in LangChain
similarity_search returns an empty list on the second runShort answer
Chroma only keeps data when you ask it to. The in-memory client loses everything when the program ends. A persistent client needs the same path every run, and a Chroma server needs a mounted data folder. Check which client LangChain built, then point every run at the same stored location.
Fix it fast
1Find out which cause you have
Count the stored documents right after you reopen the store. A count of 0 on a run that should see old data means this page applies.
python - <<'PY' import chromadb client = chromadb.PersistentClient(path="/var/lib/my-app/chroma") # your path for c in client.list_collections(): print(c.name, client.get_collection(name=c.name).count()) PY2Match what you see, then jump to its fix
- 1
Data works inside one run and is gone on the nextThe store was created without a persist directory or persistent clientFix - 2
A new chroma folder appears next to whichever script or notebook you ran, and the old one still holds the dataEach run opens a different folderFix - 3
HttpClient mode: data vanishes when the container is recreated, or the connection is refusedThe Chroma server has no volume or is not reachableFix
- 1
What does the error look like?
similarity_search returns an empty list on the second runThe collection is empty after the app restartsThe vector store works but nothing is written to the persist folder
Cause 1 of 3
The store was created without a persist directory or persistent client
1Check
Chroma's docs say the in-memory client loses its data when the program terminates. LangChain's page shows persistence only when you pass persist_directory or a PersistentClient.
grep -rn "Chroma(\|Chroma.from_" --include='*.py' .2Fix
Pass persist_directory, or build a PersistentClient and give it to Chroma.
from langchain_chroma import Chroma
vector_store = Chroma(
collection_name="example_collection",
embedding_function=embeddings,
persist_directory="/var/lib/my-app/chroma",
)3Verify
Add documents, stop the script, run it again and count what the client sees.
import chromadb
client = chromadb.PersistentClient(path="/var/lib/my-app/chroma")
print(client.get_collection(name="example_collection").count())Confirmed by docs.langchain.com
Cause 2 of 3
Each run opens a different folder
1Check
A path like ./chroma_langchain_db is relative. Chroma's PersistentClient also falls back to .chroma when you omit path, so two runs from different working directories use two stores.
ls -d ./.chroma ./chroma_langchain_db 2>/dev/null
pwd2Fix
Use one absolute path, read from configuration, in every entry point.
import chromadb
client = chromadb.PersistentClient(path="/var/lib/my-app/chroma")3Verify
Run the script from two different directories and compare the counts.
print(client.list_collections()) # same names from every directoryConfirmed by docs.trychroma.com
Cause 3 of 3
The Chroma server has no volume or is not reachable
1Check
Chroma's server docs persist data only through --path for the CLI, or a host folder mounted at /data for Docker. They also warn against the old IS_PERSISTENT and PERSIST_DIRECTORY variables with the v1.x Docker image.
docker inspect chromadb --format '{{ json .Mounts }}'
python -c "import chromadb; print(chromadb.HttpClient(host='localhost', port=8000).heartbeat())"2Fix
Start the server with a data folder, then connect with HttpClient using the same host and port.
docker run -d --name chromadb -p 8000:8000 -v ./chroma-data:/data chromadb/chroma:1.5.3
# python
import chromadb
client = chromadb.HttpClient(host="localhost", port=8000, ssl=False)3Verify
Recreate the container with the same mount and count again.
docker rm -f chromadb
docker run -d --name chromadb -p 8000:8000 -v ./chroma-data:/data chromadb/chroma:1.5.3
python -c "import chromadb; c=chromadb.HttpClient(host='localhost', port=8000); print([x.name for x in c.list_collections()])"Confirmed by cookbook.chromadb.dev
How do I stop it coming back?
- Keep the Chroma path or server address in one config value, not in each script.
- Mount the server's data folder as a volume from the first day.
- Pin the Chroma image version in Docker and Compose files.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
AI
The shell says ollama: command not found
command not found: ollama
The shell can only run ollama if the binary is installed in the same place the shell runs.
2 causes, each with a fixAI
Ollama is slow and the GPU is not being used
Replies arrive a few tokens per second on a machine with a GPU
Run ollama ps and read the PROCESSOR column: 100% GPU means the model is on the card, anything with CPU means it is not fully there.
4 causes, each with a fixAI
Open WebUI or another Docker app cannot connect to Ollama
Connect call failed ('127.0.0.1', 11434)
Inside a container, localhost is the container itself, not your machine, so a call to 127.0.0.1:11434 never reaches Ollama.
3 causes, each with a fixAI
Open WebUI web search with SearXNG fails with 403
Web search returns no results with SearXNG selected
Open WebUI asks SearXNG for JSON results, and SearXNG refuses that unless json is listed in the formats in settings.yml.
2 causes, each with a fixAI
pymilvus times out connecting to Milvus on localhost:19530 from a container
MilvusException: (code=2, message=Fail connecting to server on localhost:19530. Timeout)
Inside a container, localhost is the container itself, not the machine or the Milvus container, so the app gets a timeout on port 19530.
2 causes, each with a fixAI
Azure OpenAI says the API deployment for this resource does not exist
The API deployment for this resource does not exist
Azure OpenAI does not take a model name in the model field.
2 causes, each with a fix