diff --git a/lightrag/base.py b/lightrag/base.py index bff92b34..f35440c1 100644 --- a/lightrag/base.py +++ b/lightrag/base.py @@ -123,6 +123,7 @@ class StorageNameSpace(ABC): 3. Reset the storage to its initial state 4. Handle cleanup of any resources 5. Notify other processes if necessary + 6. This action should persistent the data to disk immediately. Returns: dict[str, str]: Operation status and message with the following format: @@ -207,6 +208,22 @@ class BaseKVStorage(StorageNameSpace, ABC): async def upsert(self, data: dict[str, dict[str, Any]]) -> None: """Upsert data""" + @abstractmethod + async def delete(self, ids: list[str]) -> None: + """Delete specific records from storage by their IDs + + This method will: + 1. Remove the specified records from in-memory storage + 2. For in-memory DB, update flags to notify other processes that data persistence is needed + 3. For in-memory DB, changes will be persisted to disk during the next index_done_callback + + Args: + ids (list[str]): List of document IDs to be deleted from storage + + Returns: + None + """ + @dataclass class BaseGraphStorage(StorageNameSpace, ABC): diff --git a/lightrag/kg/json_kv_impl.py b/lightrag/kg/json_kv_impl.py index 2ca9c03e..ea4fb51b 100644 --- a/lightrag/kg/json_kv_impl.py +++ b/lightrag/kg/json_kv_impl.py @@ -122,14 +122,27 @@ class JsonKVStorage(BaseKVStorage): await set_all_update_flags(self.namespace) async def delete(self, ids: list[str]) -> None: + """Delete specific records from storage by their IDs + + This method will: + 1. Remove the specified records from in-memory storage + 2. Update flags to notify other processes that data persistence is needed + 3. The changes will be persisted to disk during the next index_done_callback + + Args: + ids (list[str]): List of document IDs to be deleted from storage + + Returns: + None + """ async with self._storage_lock: for doc_id in ids: self._data.pop(doc_id, None) await set_all_update_flags(self.namespace) - await self.index_done_callback() async def drop(self) -> dict[str, str]: """Drop all data from storage and clean up resources + This action will persistent the data to disk immediately. This method will: 1. Clear all data from memory