Fix llm cache save problem in json_kv storage

This commit is contained in:
yangdx
2025-03-09 23:33:03 +08:00
parent bc42afe7b6
commit c938989920
3 changed files with 5 additions and 7 deletions

View File

@@ -96,12 +96,12 @@ class JsonDocStatusStorage(DocStatusStorage):
write_json(data_dict, self._file_name)
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
logger.info(f"Inserting {len(data)} to {self.namespace}")
if not data:
return
logger.info(f"Inserting {len(data)} to {self.namespace}")
async with self._storage_lock:
self._data.update(data)
await self.index_done_callback()
async def get_by_id(self, id: str) -> Union[dict[str, Any], None]:

View File

@@ -98,11 +98,9 @@ class JsonKVStorage(BaseKVStorage):
async def upsert(self, data: dict[str, dict[str, Any]]) -> None:
if not data:
return
logger.info(f"Inserting {len(data)} to {self.namespace}")
async with self._storage_lock:
left_data = {k: v for k, v in data.items() if k not in self._data}
if left_data:
logger.info(f"Process {os.getpid()} KV inserting {len(left_data)} to {self.namespace}")
self._data.update(left_data)
self._data.update(data)
async def delete(self, ids: list[str]) -> None:
async with self._storage_lock:

View File

@@ -403,6 +403,7 @@ async def extract_entities(
else:
_prompt = input_text
# TODO add cache_type="extract"
arg_hash = compute_args_hash(_prompt)
cached_return, _1, _2, _3 = await handle_cache(
llm_response_cache,
@@ -431,7 +432,6 @@ async def extract_entities(
cache_type="extract",
),
)
logger.info(f"Extract: saved cache for {arg_hash}")
return res
if history_messages: