qdrant_vector_store_data_lossTier 1 · 70% confidence

ai-agents-qdrant-vector-store--qdrantvectorstore-s-collection-existence-check-tre-694e2805

agent: ai_agents

When does this happen?

IF QdrantVectorStore's collection existence check treats HTTP errors (500, timeout) as 'collection does not exist', causing recreate_collection (delete+create) on add(); also stale cached state triggers the same if collection is created out-of-band after init().

How others solved it

THEN Modify _collection_exists() to raise or properly handle exceptions instead of returning False. In add(), re-check collection existence with the client rather than relying on the cached _collection_initialized flag; if the collection already exists, skip recreate_collection and use create_collection only when guaranteed absent. This prevents unintended deletion and data loss.

# Fix _collection_exists to not swallow errors:
def _collection_exists(self, collection_name: str) -> bool:
    from qdrant_client.http.exceptions import UnexpectedResponse
    from grpc import RpcError
    try:
        self._client.get_collection(collection_name)
        return True
    except (RpcError, UnexpectedResponse, ValueError) as e:
        # Re-raise on server errors to avoid false negatives
        if hasattr(e, 'status_code') and e.status_code >= 500:
            raise
        return False

# Also in add(), recheck existence:
if len(nodes) > 0:
    if not self._collection_exists(self.collection_name):
        self._create_collection(...)
    elif not self._collection_initialized:
        self._collection_initialized = True

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics