yangdx commited on
Commit
6cce1ca
·
1 Parent(s): b6c0e2f

feat: Remove immediate persistence in delete operation

Browse files

- Enhance delete implementation in JsonKVStorage by removing immediate persistence in delete operation
- Update documentation for drop method to clarify persistence behavior
- Add abstract delete method to BaseKVStorage

Files changed (2) hide show
  1. lightrag/base.py +17 -0
  2. lightrag/kg/json_kv_impl.py +14 -1
lightrag/base.py CHANGED
@@ -123,6 +123,7 @@ class StorageNameSpace(ABC):
123
  3. Reset the storage to its initial state
124
  4. Handle cleanup of any resources
125
  5. Notify other processes if necessary
 
126
 
127
  Returns:
128
  dict[str, str]: Operation status and message with the following format:
@@ -207,6 +208,22 @@ class BaseKVStorage(StorageNameSpace, ABC):
207
  async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
208
  """Upsert data"""
209
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
210
 
211
  @dataclass
212
  class BaseGraphStorage(StorageNameSpace, ABC):
 
123
  3. Reset the storage to its initial state
124
  4. Handle cleanup of any resources
125
  5. Notify other processes if necessary
126
+ 6. This action should persistent the data to disk immediately.
127
 
128
  Returns:
129
  dict[str, str]: Operation status and message with the following format:
 
208
  async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
209
  """Upsert data"""
210
 
211
+ @abstractmethod
212
+ async def delete(self, ids: list[str]) -> None:
213
+ """Delete specific records from storage by their IDs
214
+
215
+ This method will:
216
+ 1. Remove the specified records from in-memory storage
217
+ 2. For in-memory DB, update flags to notify other processes that data persistence is needed
218
+ 3. For in-memory DB, changes will be persisted to disk during the next index_done_callback
219
+
220
+ Args:
221
+ ids (list[str]): List of document IDs to be deleted from storage
222
+
223
+ Returns:
224
+ None
225
+ """
226
+
227
 
228
  @dataclass
229
  class BaseGraphStorage(StorageNameSpace, ABC):
lightrag/kg/json_kv_impl.py CHANGED
@@ -122,14 +122,27 @@ class JsonKVStorage(BaseKVStorage):
122
  await set_all_update_flags(self.namespace)
123
 
124
  async def delete(self, ids: list[str]) -> None:
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  async with self._storage_lock:
126
  for doc_id in ids:
127
  self._data.pop(doc_id, None)
128
  await set_all_update_flags(self.namespace)
129
- await self.index_done_callback()
130
 
131
  async def drop(self) -> dict[str, str]:
132
  """Drop all data from storage and clean up resources
 
133
 
134
  This method will:
135
  1. Clear all data from memory
 
122
  await set_all_update_flags(self.namespace)
123
 
124
  async def delete(self, ids: list[str]) -> None:
125
+ """Delete specific records from storage by their IDs
126
+
127
+ This method will:
128
+ 1. Remove the specified records from in-memory storage
129
+ 2. Update flags to notify other processes that data persistence is needed
130
+ 3. The changes will be persisted to disk during the next index_done_callback
131
+
132
+ Args:
133
+ ids (list[str]): List of document IDs to be deleted from storage
134
+
135
+ Returns:
136
+ None
137
+ """
138
  async with self._storage_lock:
139
  for doc_id in ids:
140
  self._data.pop(doc_id, None)
141
  await set_all_update_flags(self.namespace)
 
142
 
143
  async def drop(self) -> dict[str, str]:
144
  """Drop all data from storage and clean up resources
145
+ This action will persistent the data to disk immediately.
146
 
147
  This method will:
148
  1. Clear all data from memory