fix: inject KB document listing on fallback for broad queries (#959)

When users ask broad queries like "请整理知识库中的数据" in RAG mode,
vector/keyword search returns nothing because the query has no specific
content to match. The user needs to see what documents exist, not search
results.

- Add buildKBDocumentListing() to fetch document titles/filenames from
  the knowledge base and inject them into the fallback prompt via
  {{kb_documents}} placeholder
- Update fallback prompt templates (model_fallback, default_fallback_prompt)
  to include document listing context so the LLM can guide users
- Improve rewrite prompt: tighten summarize vs kb_search classification,
  expand kb_search to cover browse/organize/list operations, add examples

Closes #959
This commit is contained in:
wizardchen
2026-04-28 23:25:02 +08:00
committed by lyingbug
parent d5f6c7ba21
commit d812770806
3 changed files with 99 additions and 10 deletions
+14 -6
View File
@@ -90,12 +90,15 @@ templates:
description: "일반 지식을 바탕으로 모델이 답변하도록 안내하는 프롬프트"
mode: "model"
content: |
No content directly related to the user's question was found in the knowledge base. Please use your general knowledge to help the user answer the question as best as possible.
No content directly matched the user's query via search. However, the knowledge base contains the following documents:
{{kb_documents}}
Important Notes:
1. Clearly inform the user that this answer is based on general knowledge, not knowledge base content
2. If the question involves specific domains or requires the latest information, suggest the user consult official resources
3. Maintain accuracy and objectivity in the response
1. If the document listing above is available, use it to help answer the user's question (e.g., list relevant documents, suggest which documents may contain the information they need)
2. If the document listing is empty, use your general knowledge and clearly inform the user that the answer is not from the knowledge base
3. If the question involves specific domains or requires the latest information, suggest the user consult official resources
4. Maintain accuracy and objectivity in the response
## CRITICAL: Language Rule
- ALWAYS respond in {{language}}
@@ -117,10 +120,15 @@ templates:
description: "KB에 관련 결과가 없을 때 모델에 위임하는 기본 프롬프트"
mode: "model"
content: |
You are WeKnora, a professional and friendly AI assistant developed by Tencent. Please answer the user's question based on your knowledge.
You are WeKnora, a professional and friendly AI assistant developed by Tencent.
No content directly matched the user's query via search. However, the knowledge base contains the following documents:
{{kb_documents}}
## Response Requirements
- Answer the user's question directly
- If the document listing above is available, use it to help answer the user's question (e.g., list relevant documents, suggest which documents may contain the information they need, or summarize what is available in the knowledge base)
- If the document listing is empty or not relevant, answer the user's question based on your general knowledge and clearly inform the user that the answer is not from the knowledge base
- Be concise, clear, and substantive
- If real-time data or personal privacy information is involved, honestly state that it cannot be obtained
- Use a polite and professional tone