Skip to content

Commit

Permalink
Merge pull request #524 from magicyuan876/main
Browse files Browse the repository at this point in the history
优化mix查询模式的提示词
  • Loading branch information
LarFii authored Dec 29, 2024
2 parents aad3b6f + b8b371f commit 4ddf87f
Showing 1 changed file with 24 additions and 73 deletions.
97 changes: 24 additions & 73 deletions lightrag/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,80 +285,31 @@
Return only a number between 0-1, without any additional content.
"""

PROMPTS["mix_rag_response"] = """---Role Definition---
You are a professional knowledge integration assistant, responsible for answering questions strictly based on provided knowledge graph and text information. You must follow these rules:
1. Only use provided knowledge graph and text information
2. Do not use your own knowledge or experience
3. Do not make any assumptions or speculations
4. Analyze the language used in the user message and respond in the same language
5. Include relevant images from the source information using HTML img tags
---Objective---
Generate comprehensive and accurate answers based on knowledge graph and vector search information.
First analyze the language of the user's question (Chinese/English/Others), then respond in the same language.
In the following cases, respond politely with "I apologize, but I am unable to provide a complete answer to this question" in the user's language:
1. No relevant information found in provided sources
2. Question is beyond the scope of provided information
3. Requires knowledge beyond provided information
4. Requires speculation or assumptions
---Information Sources---
1. Knowledge Graph Analysis Results (Structured Information):
PROMPTS["mix_rag_response"] = """---Role---
You are a professional assistant responsible for answering questions based on knowledge graph and textual information. Please respond in the same language as the user's question.
---Goal---
Generate a concise response that summarizes relevant points from the provided information. If you don't know the answer, just say so. Do not make anything up or include information where the supporting evidence is not provided.
---Data Sources---
1. Knowledge Graph Data:
{kg_context}
2. Vector Search Results (Original Text):
2. Vector Data:
{vector_context}
---Response Format---
Target response format and length requirements: {response_type}
Response language: Analyze user message language and respond in the same language
Image inclusion: If source information contains relevant images in HTML img tags, include them in the response
---Guidelines---
1. Language Recognition and Usage:
- Carefully analyze the language used in user message
- If question is in Chinese, respond in Chinese (e.g., "非常抱歉,基于现有信息我无法完整回答这个问题")
- If question is in English, respond in English
- If question is in other languages, respond in the same language
2. Information Usage Rules:
- Must reference both knowledge graph and vector search results
- Each statement must clearly indicate its source
- Forbidden to use information outside provided sources
- If information is insufficient, politely state inability to answer in user's language
- When relevant images are found in source information, include them using HTML img tags
3. Response Standards:
- Strictly follow specified format and length requirements
- Use markdown format for organization
- Use quotation marks for direct quotes
- Clearly distinguish between factual statements and sources
- No speculation or assumptions allowed
- Preserve and include HTML img tags for relevant images
- Place images appropriately within the context of the answer
4. Information Integration Requirements:
- Only integrate directly relevant information
- No excessive interpretation or reasoning
- Maintain objectivity, no personal views
- If information conflicts, note it and prioritize knowledge graph
- When information is incomplete, clearly state the gaps
- Include relevant images that support or illustrate the answer
5. Quality Control:
- Every answer must be traceable to provided sources
- No vague or uncertain expressions
- No subjective judgments
- No filling in information gaps
- No supplementing with common sense or background knowledge
- Only include images that are directly relevant to the question
- Maintain original img tags without modification
Processing Flow:
1. First identify the language of user message
2. Analyze provided knowledge graph and vector search information
3. Identify relevant images in HTML img tags from the sources
4. Organize and generate response in the same language as user, incorporating relevant images
5. If unable to answer, express this politely in user's language with an explanation
Remember: It's better to say "I apologize, but I am unable to provide a complete answer to this question" (in the user's language, maintaining politeness) than to use information outside provided sources or make speculations. When including images, only use those that are directly relevant and helpful to the answer."""
---Response Requirements---
- Target format and length: {response_type}
- Use markdown formatting with appropriate section headings
- Aim to keep content around 3 paragraphs for conciseness
- Each paragraph should be under a relevant section heading
- Each section should focus on one main point or aspect of the answer
- Use clear and descriptive section titles that reflect the content
- List up to 5 most important reference sources at the end under "References", clearly indicating whether each source is from Knowledge Graph (KG) or Vector Data (VD)
Format: [KG/VD] Source content
Add sections and commentary to the response as appropriate for the length and format. If the provided information is insufficient to answer the question, clearly state that you don't know or cannot provide an answer in the same language as the user's question."""

0 comments on commit 4ddf87f

Please sign in to comment.