From 1c5ea463787cbf0a8e4c56a78405707a18e9c697 Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Wed, 11 Jun 2025 14:49:50 +0200 Subject: [PATCH] fix: Qdrant adapter faulty limit=0 behavior in search (#965) ## Description Fixes Qdrant adapter faulty limit=0 behavior ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --- .../databases/vector/qdrant/QDrantAdapter.py | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py b/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py index 1532176de..08ab9b180 100644 --- a/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py +++ b/cognee/infrastructure/databases/vector/qdrant/QDrantAdapter.py @@ -391,13 +391,7 @@ class QDrantAdapter(VectorDBInterface): if query_text is None and query_vector is None: raise InvalidValueError(message="One of query_text or query_vector must be provided!") - if limit <= 0: - return [] - if not await self.has_collection(collection_name): - logger.warning( - f"Collection '{collection_name}' not found in QdrantAdapter.search; returning []." - ) return [] if query_vector is None: @@ -405,6 +399,8 @@ class QDrantAdapter(VectorDBInterface): try: client = self.get_qdrant_client() + if limit == 0: + collection_size = await client.count(collection_name=collection_name) results = await client.search( collection_name=collection_name, @@ -414,7 +410,7 @@ class QDrantAdapter(VectorDBInterface): if query_vector is not None else (await self.embed_data([query_text]))[0], ), - limit=limit if limit > 0 else None, + limit=limit if limit > 0 else collection_size.count, with_vectors=with_vector, ) @@ -431,13 +427,6 @@ class QDrantAdapter(VectorDBInterface): ) for result in results ] - except UnexpectedResponse as error: - if "Collection not found" in str(error): - raise CollectionNotFoundError( - message=f"Collection {collection_name} not found!" - ) from error - else: - raise error finally: await client.close()