Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

Chroma data is empty after a restart in LangChain

Errorsimilarity_search returns an empty list on the second run

Short 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.

  • Applies to langchain-chroma 0.1.2 and later, chromadb 1.x, Docker
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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())
    PY
  2. 2Match what you see, then jump to its fix

    1. 1Data works inside one run and is gone on the nextThe store was created without a persist directory or persistent clientFix
    2. 2A 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. 3HttpClient mode: data vanishes when the container is recreated, or the connection is refusedThe Chroma server has no volume or is not reachableFix

What does the error look like?

  • similarity_search returns an empty list on the second run
  • The collection is empty after the app restarts
  • The 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

Did this fix it?

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
pwd

2Fix

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 directory

Confirmed by docs.trychroma.com

Did this fix it?

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

Did this fix it?

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

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 fix

AI

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.