mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-11-30 17:06:14 +00:00
Fix: Improve keyword extraction prompt for robust JSON output.
* Emphasize strict JSON output in key extration prompt * Clean up prompt examples in key extration prompt * Log raw LLM response on JSON error
This commit is contained in:
parent
3f5ade47cd
commit
f2d051eea5
@ -1852,6 +1852,7 @@ async def extract_keywords_only(
|
||||
keywords_data = json.loads(match.group(0))
|
||||
except json.JSONDecodeError as e:
|
||||
logger.error(f"JSON parsing error: {e}")
|
||||
logger.error(f"LLM respond: {result}")
|
||||
return [], []
|
||||
|
||||
hl_keywords = keywords_data.get("high_level_keywords", [])
|
||||
|
||||
@ -251,7 +251,7 @@ Given the query and conversation history, list both high-level and low-level key
|
||||
######################
|
||||
{examples}
|
||||
|
||||
#############################
|
||||
######################
|
||||
---Real Data---
|
||||
######################
|
||||
Conversation History:
|
||||
@ -259,42 +259,45 @@ Conversation History:
|
||||
|
||||
Current Query: {query}
|
||||
######################
|
||||
The `Output` should be human text, not unicode characters. Keep the same language as `Query`.
|
||||
Output:
|
||||
The `Output` should be in JSON format, with no other text before and after the JSON. Use the same language as `Current Query`.
|
||||
|
||||
Output:
|
||||
"""
|
||||
|
||||
PROMPTS["keywords_extraction_examples"] = [
|
||||
"""Example 1:
|
||||
|
||||
Query: "How does international trade influence global economic stability?"
|
||||
################
|
||||
|
||||
Output:
|
||||
{
|
||||
"high_level_keywords": ["International trade", "Global economic stability", "Economic impact"],
|
||||
"low_level_keywords": ["Trade agreements", "Tariffs", "Currency exchange", "Imports", "Exports"]
|
||||
}
|
||||
#############################""",
|
||||
|
||||
""",
|
||||
"""Example 2:
|
||||
|
||||
Query: "What are the environmental consequences of deforestation on biodiversity?"
|
||||
################
|
||||
|
||||
Output:
|
||||
{
|
||||
"high_level_keywords": ["Environmental consequences", "Deforestation", "Biodiversity loss"],
|
||||
"low_level_keywords": ["Species extinction", "Habitat destruction", "Carbon emissions", "Rainforest", "Ecosystem"]
|
||||
}
|
||||
#############################""",
|
||||
|
||||
""",
|
||||
"""Example 3:
|
||||
|
||||
Query: "What is the role of education in reducing poverty?"
|
||||
################
|
||||
|
||||
Output:
|
||||
{
|
||||
"high_level_keywords": ["Education", "Poverty reduction", "Socioeconomic development"],
|
||||
"low_level_keywords": ["School access", "Literacy rates", "Job training", "Income inequality"]
|
||||
}
|
||||
#############################""",
|
||||
|
||||
""",
|
||||
]
|
||||
|
||||
PROMPTS["naive_rag_response"] = """---Role---
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user