mirror of
https://github.com/HKUDS/LightRAG.git
synced 2025-12-01 01:16: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))
|
keywords_data = json.loads(match.group(0))
|
||||||
except json.JSONDecodeError as e:
|
except json.JSONDecodeError as e:
|
||||||
logger.error(f"JSON parsing error: {e}")
|
logger.error(f"JSON parsing error: {e}")
|
||||||
|
logger.error(f"LLM respond: {result}")
|
||||||
return [], []
|
return [], []
|
||||||
|
|
||||||
hl_keywords = keywords_data.get("high_level_keywords", [])
|
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}
|
{examples}
|
||||||
|
|
||||||
#############################
|
######################
|
||||||
---Real Data---
|
---Real Data---
|
||||||
######################
|
######################
|
||||||
Conversation History:
|
Conversation History:
|
||||||
@ -259,42 +259,45 @@ Conversation History:
|
|||||||
|
|
||||||
Current Query: {query}
|
Current Query: {query}
|
||||||
######################
|
######################
|
||||||
The `Output` should be human text, not unicode characters. Keep the same language as `Query`.
|
The `Output` should be in JSON format, with no other text before and after the JSON. Use the same language as `Current Query`.
|
||||||
Output:
|
|
||||||
|
|
||||||
|
Output:
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PROMPTS["keywords_extraction_examples"] = [
|
PROMPTS["keywords_extraction_examples"] = [
|
||||||
"""Example 1:
|
"""Example 1:
|
||||||
|
|
||||||
Query: "How does international trade influence global economic stability?"
|
Query: "How does international trade influence global economic stability?"
|
||||||
################
|
|
||||||
Output:
|
Output:
|
||||||
{
|
{
|
||||||
"high_level_keywords": ["International trade", "Global economic stability", "Economic impact"],
|
"high_level_keywords": ["International trade", "Global economic stability", "Economic impact"],
|
||||||
"low_level_keywords": ["Trade agreements", "Tariffs", "Currency exchange", "Imports", "Exports"]
|
"low_level_keywords": ["Trade agreements", "Tariffs", "Currency exchange", "Imports", "Exports"]
|
||||||
}
|
}
|
||||||
#############################""",
|
|
||||||
|
""",
|
||||||
"""Example 2:
|
"""Example 2:
|
||||||
|
|
||||||
Query: "What are the environmental consequences of deforestation on biodiversity?"
|
Query: "What are the environmental consequences of deforestation on biodiversity?"
|
||||||
################
|
|
||||||
Output:
|
Output:
|
||||||
{
|
{
|
||||||
"high_level_keywords": ["Environmental consequences", "Deforestation", "Biodiversity loss"],
|
"high_level_keywords": ["Environmental consequences", "Deforestation", "Biodiversity loss"],
|
||||||
"low_level_keywords": ["Species extinction", "Habitat destruction", "Carbon emissions", "Rainforest", "Ecosystem"]
|
"low_level_keywords": ["Species extinction", "Habitat destruction", "Carbon emissions", "Rainforest", "Ecosystem"]
|
||||||
}
|
}
|
||||||
#############################""",
|
|
||||||
|
""",
|
||||||
"""Example 3:
|
"""Example 3:
|
||||||
|
|
||||||
Query: "What is the role of education in reducing poverty?"
|
Query: "What is the role of education in reducing poverty?"
|
||||||
################
|
|
||||||
Output:
|
Output:
|
||||||
{
|
{
|
||||||
"high_level_keywords": ["Education", "Poverty reduction", "Socioeconomic development"],
|
"high_level_keywords": ["Education", "Poverty reduction", "Socioeconomic development"],
|
||||||
"low_level_keywords": ["School access", "Literacy rates", "Job training", "Income inequality"]
|
"low_level_keywords": ["School access", "Literacy rates", "Job training", "Income inequality"]
|
||||||
}
|
}
|
||||||
#############################""",
|
|
||||||
|
""",
|
||||||
]
|
]
|
||||||
|
|
||||||
PROMPTS["naive_rag_response"] = """---Role---
|
PROMPTS["naive_rag_response"] = """---Role---
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user