High severity beginner · Fix: 2-5 min

ValueError

langchain.vectorstores.chroma.ValueError

What this error means
LangChain raises a ValueError when the specified ChromaDB collection does not exist or cannot be found.

Stack trace

traceback
ValueError: Collection 'my_collection' not found in ChromaDB. Please create the collection before querying.
QUICK FIX
Ensure the ChromaDB collection exists by calling create_collection() with the correct name before any queries.

Why it happens

This error occurs because LangChain tries to access a ChromaDB collection that has not been created or was deleted. The Chroma client expects the collection to exist before performing vector operations. If the collection name is misspelled or the database was reset, this error is raised.

Detection

Check for ValueError exceptions when initializing or querying ChromaDB collections. Log the collection name and verify its existence in the ChromaDB instance before proceeding.

Causes & fixes

1

The ChromaDB collection was never created before querying.

✓ Fix

Create the collection explicitly using chroma_client.create_collection('collection_name') before querying or adding vectors.

2

The collection name is misspelled or inconsistent between creation and usage.

✓ Fix

Verify and unify the collection name string exactly in all parts of your code to avoid mismatches.

3

ChromaDB was reset or cleared, deleting existing collections.

✓ Fix

Recreate the required collections after any database reset or migration before running queries.

Code: broken vs fixed

Broken - triggers the error
python
from langchain.vectorstores import Chroma

client = Chroma()
collection = client.get_collection('my_collection')  # This line raises ValueError if collection missing
Fixed - works correctly
python
import os
from langchain.vectorstores import Chroma

client = Chroma()
# Create collection if it does not exist
try:
    collection = client.get_collection('my_collection')
except ValueError:
    collection = client.create_collection('my_collection')  # Fixed: create collection before use

print('Collection ready:', collection.name)
Added a try/except block to create the ChromaDB collection if it does not exist, preventing the ValueError.

Workaround

Wrap the get_collection call in try/except ValueError and create the collection dynamically if missing to avoid crashes.

Prevention

Implement initialization logic that ensures all required ChromaDB collections are created at app startup or deployment time to avoid runtime errors.

Python 3.9+ · langchain >=0.1.0 · tested on 0.3.x
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.