ValueError
chromadb.errors.ValueError: Collection not found
Stack trace
Traceback (most recent call last):
File "app.py", line 42, in <module>
results = collection.query(query_texts=["example query"])
File "/usr/local/lib/python3.9/site-packages/chromadb/api/collection.py", line 120, in query
raise ValueError("Collection not found")
chromadb.errors.ValueError: Collection not found Why it happens
ChromaDB requires collections to be explicitly created before querying. If the collection name used in the query does not match any existing collection, the client raises this ValueError. This often happens due to typos, missing initialization, or querying before collection creation.
Detection
Check for ValueError exceptions with the message 'Collection not found' immediately after collection query calls to catch missing or misnamed collections before app failure.
Causes & fixes
The collection was never created before querying.
Create the collection explicitly using client.create_collection('collection_name') before querying it.
The collection name used in the query is misspelled or does not match the created collection name.
Verify and correct the collection name string to exactly match the created collection's name, including case sensitivity.
The client instance is connected to a different or empty ChromaDB database where the collection does not exist.
Ensure the client is connected to the correct ChromaDB instance and database where the collection was created.
Code: broken vs fixed
from chromadb import Client
client = Client()
collection = client.get_collection('my_collection')
# This line raises ValueError: Collection not found
results = collection.query(query_texts=["test query"])
print(results) import os
from chromadb import Client
# Use environment variable for any config if needed
client = Client()
# Create collection before querying (fix applied here)
collection = client.create_collection('my_collection')
results = collection.query(query_texts=["test query"])
print(results) # Now works without error Workaround
Catch the ValueError on query, then create the collection dynamically with client.create_collection() and retry the query.
Prevention
Always create and verify collections exist at application startup or deployment time before running queries to avoid runtime collection-not-found errors.