From 5b7cd500058e50d41614c9b4b38c3039f465905b Mon Sep 17 00:00:00 2001 From: yangdx Date: Mon, 31 Mar 2025 02:14:16 +0800 Subject: [PATCH] Add delete support for MongoKVStorage --- lightrag/kg/mongo_impl.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lightrag/kg/mongo_impl.py b/lightrag/kg/mongo_impl.py index 8a9f1f3a..d5832af0 100644 --- a/lightrag/kg/mongo_impl.py +++ b/lightrag/kg/mongo_impl.py @@ -150,6 +150,21 @@ class MongoKVStorage(BaseKVStorage): # Mongo handles persistence automatically pass + async def delete(self, ids: list[str]) -> None: + """Delete documents with specified IDs + + Args: + ids: List of document IDs to be deleted + """ + if not ids: + return + + try: + result = await self._data.delete_many({"_id": {"$in": ids}}) + logger.info(f"Deleted {result.deleted_count} documents from {self.namespace}") + except PyMongoError as e: + logger.error(f"Error deleting documents from {self.namespace}: {e}") + async def drop(self) -> dict[str, str]: """Drop the storage by removing all documents in the collection.