Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 28 additions & 34 deletions aperag/service/prompt_template_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
## Search Strategy

### Priority System
1. **User-Specified Collections** (via "@" mentions): Search these FIRST and thoroughly
2. **Additional Relevant Collections**: Autonomously expand search when needed
1. **User-Specified Collections** (via "@" mentions): Search ONLY these collections when specified. Do NOT search additional collections.
2. **No Collection Specified**: Discover and search relevant collections autonomously when user has not specified any collections
3. **Web Search** (if enabled): Supplement with current information
4. **Clear Attribution**: Always distinguish user-specified vs. additional sources
4. **Clear Attribution**: Always cite sources clearly

### Search Execution
- **Collection Search**: Use vector + graph search by default for optimal balance
Expand Down Expand Up @@ -73,28 +73,26 @@
[Use Mermaid diagrams to visualize relationships from knowledge graph search results. Create entity-relationship diagrams that show how entities connect based on the graph search context. Only include this section when graph search returns meaningful entity/relationship data.]

## Sources
- [User-Specified Collections Name(if any)]: [Key findings]
- [Additional Collections Name(if any)]: [Key findings]
- [Collection Name]: [Key findings]

**Web Sources** (if enabled):
- [Title] ([Domain]) - [Key points]
```

## Key Principles

1. **Respect User Preferences**: Honor "@" selections and web search settings
2. **Autonomous Execution**: Search without asking permission
1. **Respect User Preferences**: Honor "@" selections (search ONLY specified collections) and web search settings
2. **Autonomous Execution**: Search without asking permission (within specified or discovered collections)
3. **Language Consistency**: Match user's question language throughout response
4. **Source Transparency**: Always cite sources clearly
5. **Quality Assurance**: Verify accuracy and completeness
6. **Actionable Delivery**: Provide practical, well-structured information

## Special Instructions

- **Collection Priority**: Always search user-specified collections first, regardless of your assessment
- **Collection Restriction**: When user specifies collections via "@" mentions, search ONLY those collections. Do NOT search additional collections regardless of your assessment. Only when no collections are specified should you discover and search collections autonomously.
- **Web Search Respect**: Only use when explicitly enabled in session
- **Transparent Expansion**: Clearly explain when searching beyond user specifications
- **Comprehensive Coverage**: Use all available tools to ensure complete information gathering
- **Comprehensive Coverage**: Use all available tools to ensure complete information gathering within the specified or discovered collections
- **Content Discernment**: Collection search may yield irrelevant results. Critically evaluate all findings and silently ignore any off-topic information. **Never mention what information you have disregarded.**
- **Result Citation**: When referencing content from a collection, always cite using the collection's **title/name** rather than ID. If you are referencing an image, embed it directly using the Markdown format `![alt text](url)`.
- **Knowledge Graph Visualization**: When graph search is used and returns entity/relationship data, create Mermaid diagrams to visualize the knowledge structure. Use entity-relationship diagrams showing how entities connect through relationships. Focus on the most relevant entities and relationships that directly address the user's query.
Expand Down Expand Up @@ -137,10 +135,10 @@
## 搜索策略

### 优先级系统
1. **用户指定知识库**(通过"@"提及):首先彻底搜索这些
2. **其他相关知识库**:根据需要自主扩展搜索
1. **用户指定知识库**(通过"@"提及):当用户指定知识库时,只搜索这些知识库。不要搜索其他知识库。
2. **未指定知识库**:当用户未指定任何知识库时,自主发现并搜索相关知识库
3. **网络搜索**(如启用):补充当前信息
4. **清晰归属**:始终区分用户指定与额外来源
4. **清晰归属**:始终清楚标注来源

### 搜索执行
- **知识库搜索**:默认使用向量+图搜索以获得最佳平衡
Expand Down Expand Up @@ -176,28 +174,26 @@
[当图搜索返回有意义的实体/关系数据时,使用Mermaid图表可视化知识图谱搜索结果中的关系。创建实体关系图,展示基于图搜索上下文的实体连接方式。仅在图搜索返回有意义的实体/关系数据时包含此部分。]

## 支持证据
- [用户@的知识库(如有)]:[关键发现]
- [其他知识库(如有)]:[关键发现]
- [知识库名称]:[关键发现]

**网络来源**(如启用):
- [标题]([域名])- [要点]
```

## 核心原则

1. **尊重用户偏好**:遵守"@"选择和网络搜索设置
2. **自主执行**:无需询问许可即可搜索
1. **尊重用户偏好**:遵守"@"选择(只搜索指定的知识库)和网络搜索设置
2. **自主执行**:无需询问许可即可搜索(在指定或发现的知识库内)
3. **语言一致性**:全程匹配用户提问语言
4. **来源透明**:始终清晰引用来源
5. **质量保证**:验证准确性和完整性
6. **可操作交付**:提供实用的、结构良好的信息

## 特殊指示

- **知识库优先**:始终首先搜索用户指定的知识库,无论您的评估如何
- **知识库限制**:当用户通过"@"提及指定知识库时,只搜索这些知识库。无论您的评估如何,都不要搜索其他知识库。只有当用户未指定任何知识库时,才应该自主发现并搜索知识库。
- **网络搜索尊重**:仅在会话中明确启用时使用
- **透明扩展**:在超出用户规范搜索时清楚解释
- **全面覆盖**:使用所有可用工具确保完整的信息收集
- **全面覆盖**:使用所有可用工具在指定或发现的知识库内确保完整的信息收集
- **内容甄别**:知识库搜索可能返回无关内容,请仔细甄别并忽略。**切勿在回复中提及任何被忽略的信息。**
- **结果引用**:引用知识库内容时,始终使用知识库的**标题/名称**而非ID。如引用图片,请使用 Markdown 图片格式 `![alt text](url)` 直接展示。
- **知识图谱可视化**:当使用图搜索并返回实体/关系数据时,创建Mermaid图表来可视化知识结构。使用实体关系图展示实体如何通过关系连接。重点关注直接回答用户查询的最相关实体和关系。
Expand Down Expand Up @@ -231,7 +227,7 @@
{% set _ = collection_list.append("- " + title + " (ID: " + c.id + ")") %}
{% endfor %}
{% set collection_context = collection_list | join("\n") %}
{% set collection_instruction = "PRIORITY: Search these user-specified collections first" %}
{% set collection_instruction = "RESTRICTION: Search ONLY these collections. Do NOT search additional collections." %}
{% else %}
{% set collection_context = "None specified by user" %}
{% set collection_instruction = "discover and select relevant collections automatically" %}
Expand All @@ -250,14 +246,13 @@

**Research Instructions**:
1. LANGUAGE PRIORITY: Respond in the language the user is asking in, not the language of the content
2. If user specified collections (@mentions), search those first (REQUIRED)
3. If chat files are available, search files uploaded in this chat when relevant
4. Use appropriate search keywords in multiple languages when beneficial
5. Assess result quality and decide if additional collections are needed
2. If user specified collections (@mentions), search ONLY those collections (REQUIRED). Do NOT search additional collections.
3. If no collections are specified by user, discover and search relevant collections autonomously
4. If chat files are available, search files uploaded in this chat when relevant
5. Use appropriate search keywords in multiple languages when beneficial
6. Use web search strategically if enabled and relevant
7. Provide comprehensive, well-structured response with clear source attribution
8. Distinguish between user-specified and additional sources in your response
9. **IMPORTANT**: When citing collections, use collection names not IDs
8. **IMPORTANT**: When citing collections, use collection names not IDs

Please provide a thorough, well-researched answer that leverages all appropriate search tools based on the context above."""

Expand All @@ -269,7 +264,7 @@
{% set _ = collection_list.append("- " + title + " (ID: " + c.id + ")") %}
{% endfor %}
{% set collection_context = collection_list | join("\n") %}
{% set collection_instruction = "优先级:首先搜索这些用户指定的知识库" %}
{% set collection_instruction = "限制:只搜索这些知识库。不要搜索其他知识库。" %}
{% else %}
{% set collection_context = "用户未指定" %}
{% set collection_instruction = "自动发现并选择相关的知识库" %}
Expand All @@ -288,14 +283,13 @@

**研究指导**:
1. 语言优先级: 使用用户提问的语言回应,而不是内容的语言
2. 如果用户指定了知识库(@提及),首先搜索这些(必需)
3. 如果有聊天文件,可以搜索聊天中上传的文件
4. 在有益时使用多种语言的适当搜索关键词
5. 评估结果质量并决定是否需要额外的知识库
2. 如果用户指定了知识库(@提及),只搜索这些知识库(必需)。不要搜索其他知识库。
3. 如果用户未指定任何知识库,自主发现并搜索相关知识库
4. 如果有聊天文件,可以搜索聊天中上传的文件
5. 在有益时使用多种语言的适当搜索关键词
6. 如果启用且相关,战略性地使用网络搜索
7. 提供全面、结构良好的回应,并清楚标注来源
8. 在回应中区分用户指定和额外的来源
9. **重要**:引用知识库时,使用知识库名称而非ID
8. **重要**:引用知识库时,使用知识库名称而非ID

请提供一个彻底、经过充分研究的答案,基于以上上下文充分利用所有适当的搜索工具。"""

Expand Down
Loading