QdrantCollectionNotFoundError
qdrant_client.http.exceptions.QdrantCollectionNotFoundError
Stack trace
qdrant_client.http.exceptions.QdrantCollectionNotFoundError: Collection 'my_collection' not found
File "/app/rag_qdrant.py", line 42, in query_collection
response = client.search(collection_name='my_collection', query_vector=vec)
File "/usr/local/lib/python3.9/site-packages/qdrant_client/http/api_client.py", line 123, in search
raise QdrantCollectionNotFoundError(f"Collection '{collection_name}' not found") Why it happens
This error occurs when the Qdrant client attempts to access a collection that does not exist in the Qdrant database. It can happen if the collection was never created, was deleted, or the collection name is misspelled in the code.
Detection
Catch QdrantCollectionNotFoundError exceptions during collection access calls and log the collection name to verify existence before proceeding.
Causes & fixes
The collection name specified in the client call does not exist in Qdrant.
Create the collection in Qdrant before querying or inserting, or verify the collection name matches exactly.
The collection was deleted or dropped after initial creation.
Recreate the collection or update the code to use an existing collection.
Typo or case mismatch in the collection name string used in the code.
Double-check and correct the collection name string to match the exact name in Qdrant.
Code: broken vs fixed
from qdrant_client import QdrantClient
client = QdrantClient()
# This line triggers QdrantCollectionNotFoundError if collection doesn't exist
results = client.search(collection_name='my_collection', query_vector=[0.1, 0.2, 0.3]) import os
from qdrant_client import QdrantClient
client = QdrantClient(api_key=os.environ.get('QDRANT_API_KEY'))
# Create collection if not exists before searching
if 'my_collection' not in [col.name for col in client.get_collections().collections]:
client.recreate_collection(collection_name='my_collection', vector_size=3, distance='Cosine')
results = client.search(collection_name='my_collection', query_vector=[0.1, 0.2, 0.3])
print(results) # Now works without error Workaround
Wrap the search or insert calls in try/except QdrantCollectionNotFoundError, and on exception, create the collection dynamically before retrying the operation.
Prevention
Implement collection existence checks and automated creation during app startup or deployment to ensure collections are always present before any RAG operations.