From 2d387fa6de698a72cc6c7ea6ee3a474b2261844f Mon Sep 17 00:00:00 2001 From: yangdx Date: Sat, 1 Feb 2025 22:54:23 +0800 Subject: [PATCH] Save keywords to cache only when it's no empty --- lightrag/operate.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lightrag/operate.py b/lightrag/operate.py index 37ea24dc..49f6bf39 100644 --- a/lightrag/operate.py +++ b/lightrag/operate.py @@ -760,7 +760,7 @@ async def extract_keywords_only( # 6. Parse out JSON from the LLM response match = re.search(r"\{.*\}", result, re.DOTALL) if not match: - logger.error("No JSON-like structure found in the result.") + logger.error("No JSON-like structure found in the LLM respond.") return [], [] try: keywords_data = json.loads(match.group(0)) @@ -772,20 +772,21 @@ async def extract_keywords_only( ll_keywords = keywords_data.get("low_level_keywords", []) # 7. Cache only the processed keywords with cache type - cache_data = {"high_level_keywords": hl_keywords, "low_level_keywords": ll_keywords} - await save_to_cache( - hashing_kv, - CacheData( - args_hash=args_hash, - content=json.dumps(cache_data), - prompt=text, - quantized=quantized, - min_val=min_val, - max_val=max_val, - mode=param.mode, - cache_type="keywords", - ), - ) + if hl_keywords or ll_keywords: + cache_data = {"high_level_keywords": hl_keywords, "low_level_keywords": ll_keywords} + await save_to_cache( + hashing_kv, + CacheData( + args_hash=args_hash, + content=json.dumps(cache_data), + prompt=text, + quantized=quantized, + min_val=min_val, + max_val=max_val, + mode=param.mode, + cache_type="keywords", + ), + ) return hl_keywords, ll_keywords