yangdx
commited on
Commit
·
8133923
1
Parent(s):
b8799cc
Save keywords to cache only when it's no empty
Browse files- lightrag/operate.py +16 -15
lightrag/operate.py
CHANGED
@@ -760,7 +760,7 @@ async def extract_keywords_only(
|
|
760 |
# 6. Parse out JSON from the LLM response
|
761 |
match = re.search(r"\{.*\}", result, re.DOTALL)
|
762 |
if not match:
|
763 |
-
logger.error("No JSON-like structure found in the
|
764 |
return [], []
|
765 |
try:
|
766 |
keywords_data = json.loads(match.group(0))
|
@@ -772,20 +772,21 @@ async def extract_keywords_only(
|
|
772 |
ll_keywords = keywords_data.get("low_level_keywords", [])
|
773 |
|
774 |
# 7. Cache only the processed keywords with cache type
|
775 |
-
|
776 |
-
|
777 |
-
|
778 |
-
|
779 |
-
|
780 |
-
|
781 |
-
|
782 |
-
|
783 |
-
|
784 |
-
|
785 |
-
|
786 |
-
|
787 |
-
|
788 |
-
|
|
|
789 |
return hl_keywords, ll_keywords
|
790 |
|
791 |
|
|
|
760 |
# 6. Parse out JSON from the LLM response
|
761 |
match = re.search(r"\{.*\}", result, re.DOTALL)
|
762 |
if not match:
|
763 |
+
logger.error("No JSON-like structure found in the LLM respond.")
|
764 |
return [], []
|
765 |
try:
|
766 |
keywords_data = json.loads(match.group(0))
|
|
|
772 |
ll_keywords = keywords_data.get("low_level_keywords", [])
|
773 |
|
774 |
# 7. Cache only the processed keywords with cache type
|
775 |
+
if hl_keywords or ll_keywords:
|
776 |
+
cache_data = {"high_level_keywords": hl_keywords, "low_level_keywords": ll_keywords}
|
777 |
+
await save_to_cache(
|
778 |
+
hashing_kv,
|
779 |
+
CacheData(
|
780 |
+
args_hash=args_hash,
|
781 |
+
content=json.dumps(cache_data),
|
782 |
+
prompt=text,
|
783 |
+
quantized=quantized,
|
784 |
+
min_val=min_val,
|
785 |
+
max_val=max_val,
|
786 |
+
mode=param.mode,
|
787 |
+
cache_type="keywords",
|
788 |
+
),
|
789 |
+
)
|
790 |
return hl_keywords, ll_keywords
|
791 |
|
792 |
|