Fix cache persistence bugs
This commit is contained in:
@@ -859,6 +859,7 @@ async def kg_query(
|
|||||||
.strip()
|
.strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if hashing_kv.global_config.get("enable_llm_cache"):
|
||||||
# Save to cache
|
# Save to cache
|
||||||
await save_to_cache(
|
await save_to_cache(
|
||||||
hashing_kv,
|
hashing_kv,
|
||||||
@@ -873,6 +874,7 @@ async def kg_query(
|
|||||||
cache_type="query",
|
cache_type="query",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
@@ -989,6 +991,7 @@ async def extract_keywords_only(
|
|||||||
"high_level_keywords": hl_keywords,
|
"high_level_keywords": hl_keywords,
|
||||||
"low_level_keywords": ll_keywords,
|
"low_level_keywords": ll_keywords,
|
||||||
}
|
}
|
||||||
|
if hashing_kv.global_config.get("enable_llm_cache"):
|
||||||
await save_to_cache(
|
await save_to_cache(
|
||||||
hashing_kv,
|
hashing_kv,
|
||||||
CacheData(
|
CacheData(
|
||||||
@@ -1002,6 +1005,7 @@ async def extract_keywords_only(
|
|||||||
cache_type="keywords",
|
cache_type="keywords",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return hl_keywords, ll_keywords
|
return hl_keywords, ll_keywords
|
||||||
|
|
||||||
|
|
||||||
@@ -1205,6 +1209,7 @@ async def mix_kg_vector_query(
|
|||||||
.strip()
|
.strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if hashing_kv.global_config.get("enable_llm_cache"):
|
||||||
# 7. Save cache - Only cache after collecting complete response
|
# 7. Save cache - Only cache after collecting complete response
|
||||||
await save_to_cache(
|
await save_to_cache(
|
||||||
hashing_kv,
|
hashing_kv,
|
||||||
@@ -1973,6 +1978,7 @@ async def naive_query(
|
|||||||
.strip()
|
.strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if hashing_kv.global_config.get("enable_llm_cache"):
|
||||||
# Save to cache
|
# Save to cache
|
||||||
await save_to_cache(
|
await save_to_cache(
|
||||||
hashing_kv,
|
hashing_kv,
|
||||||
@@ -2121,6 +2127,7 @@ async def kg_query_with_keywords(
|
|||||||
.strip()
|
.strip()
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if hashing_kv.global_config.get("enable_llm_cache"):
|
||||||
# 7. Save cache - 只有在收集完整响应后才缓存
|
# 7. Save cache - 只有在收集完整响应后才缓存
|
||||||
await save_to_cache(
|
await save_to_cache(
|
||||||
hashing_kv,
|
hashing_kv,
|
||||||
|
@@ -731,9 +731,6 @@ async def save_to_cache(hashing_kv, cache_data: CacheData):
|
|||||||
hashing_kv: The key-value storage for caching
|
hashing_kv: The key-value storage for caching
|
||||||
cache_data: The cache data to save
|
cache_data: The cache data to save
|
||||||
"""
|
"""
|
||||||
if not hashing_kv.global_config.get("enable_llm_cache"):
|
|
||||||
return
|
|
||||||
|
|
||||||
# Skip if storage is None or content is a streaming response
|
# Skip if storage is None or content is a streaming response
|
||||||
if hashing_kv is None or not cache_data.content:
|
if hashing_kv is None or not cache_data.content:
|
||||||
return
|
return
|
||||||
@@ -776,6 +773,8 @@ async def save_to_cache(hashing_kv, cache_data: CacheData):
|
|||||||
"original_prompt": cache_data.prompt,
|
"original_prompt": cache_data.prompt,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logger.info(f" == LLM cache == saving {cache_data.mode}: {cache_data.args_hash}")
|
||||||
|
|
||||||
# Only upsert if there's actual new content
|
# Only upsert if there's actual new content
|
||||||
await hashing_kv.upsert({cache_data.mode: mode_cache})
|
await hashing_kv.upsert({cache_data.mode: mode_cache})
|
||||||
|
|
||||||
@@ -1314,8 +1313,7 @@ async def use_llm_func_with_cache(
|
|||||||
|
|
||||||
res: str = await use_llm_func(input_text, **kwargs)
|
res: str = await use_llm_func(input_text, **kwargs)
|
||||||
|
|
||||||
# Save to cache
|
if llm_response_cache.global_config.get("enable_llm_cache_for_entity_extract"):
|
||||||
logger.info(f" == LLM cache == saving {arg_hash}")
|
|
||||||
await save_to_cache(
|
await save_to_cache(
|
||||||
llm_response_cache,
|
llm_response_cache,
|
||||||
CacheData(
|
CacheData(
|
||||||
@@ -1325,6 +1323,7 @@ async def use_llm_func_with_cache(
|
|||||||
cache_type=cache_type,
|
cache_type=cache_type,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
return res
|
return res
|
||||||
|
|
||||||
# When cache is disabled, directly call LLM
|
# When cache is disabled, directly call LLM
|
||||||
|
Reference in New Issue
Block a user