ValueError
langchain.vectorstores.chroma.ValueError
Stack trace
ValueError: Collection 'my_collection' not found in ChromaDB. Please create the collection before querying.
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
The ChromaDB collection was never created before querying.
Create the collection explicitly using chroma_client.create_collection('collection_name') before querying or adding vectors.
The collection name is misspelled or inconsistent between creation and usage.
Verify and unify the collection name string exactly in all parts of your code to avoid mismatches.
ChromaDB was reset or cleared, deleting existing collections.
Recreate the required collections after any database reset or migration before running queries.
Code: broken vs fixed
from langchain.vectorstores import Chroma
client = Chroma()
collection = client.get_collection('my_collection') # This line raises ValueError if collection missing 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) 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.