The Agent context is bound to the knowledge base, but no retrieval is performed after sending the question. #7027

Closed
opened 2026-02-21 18:18:30 -05:00 by yindo · 2 comments
Owner

Originally created by @yunfeng13 on GitHub (Dec 3, 2024).

Self Checks

  • This is only for bug report, if you would like to ask a question, please head to Discussions.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

0.11.2

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

image
t the beginning, the prompt word was not written like this, and I never did a knowledge base search. It was not until I added the requirements to the prompt word that I started to search the contextual knowledge base. Why is this? Is there an official explanation? Is there a better one? Writing method, I hope that every question will be contextualized for knowledge retrieval

✔️ Expected Behavior

t the beginning, the prompt word was not written like this, and I never did a knowledge base search. It was not until I added the requirements to the prompt word that I started to search the contextual knowledge base. Why is this? Is there an official explanation? Is there a better one? Writing method, I hope that every question will be contextualized for knowledge retrieval

Actual Behavior

If the knowledge retrieval is not written in the Agent prompt word, the retrieval will not be performed.

Originally created by @yunfeng13 on GitHub (Dec 3, 2024). ### Self Checks - [X] This is only for bug report, if you would like to ask a question, please head to [Discussions](https://github.com/langgenius/dify/discussions/categories/general). - [X] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [X] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [X] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [X] Please do not modify this template :) and fill in all the required fields. ### Dify version 0.11.2 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce ![image](https://github.com/user-attachments/assets/a63d1c9c-346f-49a7-8cab-ddeba9e0764e) t the beginning, the prompt word was not written like this, and I never did a knowledge base search. It was not until I added the requirements to the prompt word that I started to search the contextual knowledge base. Why is this? Is there an official explanation? Is there a better one? Writing method, I hope that every question will be contextualized for knowledge retrieval ### ✔️ Expected Behavior t the beginning, the prompt word was not written like this, and I never did a knowledge base search. It was not until I added the requirements to the prompt word that I started to search the contextual knowledge base. Why is this? Is there an official explanation? Is there a better one? Writing method, I hope that every question will be contextualized for knowledge retrieval ### ❌ Actual Behavior If the knowledge retrieval is not written in the Agent prompt word, the retrieval will not be performed.
yindo added the 🐞 bug label 2026-02-21 18:18:30 -05:00
yindo closed this issue 2026-02-21 18:18:30 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 3, 2024):

I found a similar unsolved discussion that might be relevant to your issue: Bot always response "I know nothing" even I have connected it with knowledge base about my company [1].

Regarding your issue, it seems that the knowledge retrieval in Dify is triggered by specific configurations in the prompt. The prompt word is configured using the "sys.query" variable, which is pre-set in the "Start" node of conversational applications to represent the user's input question. This variable is used to query the knowledge base for text chunks most closely related to the user's question [2].

To ensure that every question is contextualized for knowledge retrieval, you might need to adjust the prompt configuration to include the necessary retrieval instructions. Dify provides examples and best practices for writing prompts to ensure knowledge retrieval, which involves structuring prompts with components like Context, Pre-prompt, Query, and History to guide the model's responses [3].

If the retrieval is not performed unless specified in the prompt, it might be due to the default settings or the way the prompt is structured. You can modify these settings by configuring the Knowledge Base Retrieval Node, selecting the query variable, choosing the knowledge base, and configuring the retrieval strategy [4][2].

To continue talking to Dosu, mention @dosu.

@dosubot[bot] commented on GitHub (Dec 3, 2024): <!-- Answer --> I found a similar unsolved discussion that might be relevant to your issue: [Bot always response "I know nothing" even I have connected it with knowledge base about my company](https://github.com/langgenius/dify/discussions/10246) <sup>[[1]](https://github.com/langgenius/dify/discussions/10246)</sup>. Regarding your issue, it seems that the knowledge retrieval in Dify is triggered by specific configurations in the prompt. The prompt word is configured using the "sys.query" variable, which is pre-set in the "Start" node of conversational applications to represent the user's input question. This variable is used to query the knowledge base for text chunks most closely related to the user's question <sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/knowledge-retrieval.md)</sup>. To ensure that every question is contextualized for knowledge retrieval, you might need to adjust the prompt configuration to include the necessary retrieval instructions. Dify provides examples and best practices for writing prompts to ensure knowledge retrieval, which involves structuring prompts with components like `Context`, `Pre-prompt`, `Query`, and `History` to guide the model's responses <sup>[[3]](https://github.com/langgenius/dify-docs/blob/main/en/guides/application-orchestrate/prompt-engineering/prompt-template.md)</sup>. If the retrieval is not performed unless specified in the prompt, it might be due to the default settings or the way the prompt is structured. You can modify these settings by configuring the Knowledge Base Retrieval Node, selecting the query variable, choosing the knowledge base, and configuring the retrieval strategy <sup>[[4]](https://github.com/langgenius/dify-docs/blob/main/en/guides/knowledge-base/create-knowledge-and-upload-documents.md)</sup><sup>[[2]](https://github.com/langgenius/dify-docs/blob/main/en/guides/workflow/node/knowledge-retrieval.md)</sup>. <!-- Dosu Comment Footer --> *To continue talking to [Dosu](https://dosu.dev), mention @dosu.*
Author
Owner

@crazywoola commented on GitHub (Dec 3, 2024):

See https://docs.dify.ai/guides/application-orchestrate/agent for more details.
Agent will do actions based on instructions, the prompt is a instruction list, so if you do want the agent to search the knowledge base, tell it to do it.

And you can not use variable to store things in agent it, this should leave to the end user to fill it.

If you don't know how to write a proper prompt, try the button 'AI generate' on top of the prompt input area.

@crazywoola commented on GitHub (Dec 3, 2024): See https://docs.dify.ai/guides/application-orchestrate/agent for more details. Agent will do actions based on instructions, the prompt is a instruction list, so if you do want the agent to search the knowledge base, tell it to do it. And you can not use variable to store things in agent it, this should leave to the end user to fill it. If you don't know how to write a proper prompt, try the button 'AI generate' on top of the prompt input area.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#7027