From 476fb328ee0b93b53d3c7cd6ed2cc6510767fb82 Mon Sep 17 00:00:00 2001 From: Antonio Morales <35844399+AntonioMorales97@users.noreply.github.com> Date: Tue, 16 Jan 2024 04:57:09 +0100 Subject: [PATCH] community[patch]: implement adelete from VectorStore in Qdrant (#16005) **Description:** Implement `adelete` function from `VectorStore` in `Qdrant` to support other asynchronous flows such as async indexing (`aindex`) which requires `adelete` to be implemented. Since `Qdrant` can be passed an async qdrant client, this can be supported easily. --------- Co-authored-by: Bagatur --- .../vectorstores/qdrant.py | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/libs/community/langchain_community/vectorstores/qdrant.py b/libs/community/langchain_community/vectorstores/qdrant.py index 5073943819b..ce64d054d1a 100644 --- a/libs/community/langchain_community/vectorstores/qdrant.py +++ b/libs/community/langchain_community/vectorstores/qdrant.py @@ -1138,8 +1138,7 @@ class Qdrant(VectorStore): **kwargs: Other keyword arguments that subclasses might use. Returns: - Optional[bool]: True if deletion is successful, - False otherwise, None if not implemented. + True if deletion is successful, False otherwise. """ from qdrant_client.http import models as rest @@ -1149,6 +1148,37 @@ class Qdrant(VectorStore): ) return result.status == rest.UpdateStatus.COMPLETED + @sync_call_fallback + async def adelete( + self, ids: Optional[List[str]] = None, **kwargs: Any + ) -> Optional[bool]: + """Delete by vector ID or other criteria. + + Args: + ids: List of ids to delete. + **kwargs: Other keyword arguments that subclasses might use. + + Returns: + True if deletion is successful, False otherwise. + """ + from qdrant_client.local.async_qdrant_local import AsyncQdrantLocal + + if self.async_client is None or isinstance( + self.async_client._client, AsyncQdrantLocal + ): + raise NotImplementedError( + "QdrantLocal cannot interoperate with sync and async clients" + ) + + from qdrant_client.http import models as rest + + result = await self.async_client.delete( + collection_name=self.collection_name, + points_selector=ids, + ) + + return result.status == rest.UpdateStatus.COMPLETED + @classmethod def from_texts( cls: Type[Qdrant],