Skip to content

Metadata filtering with Manual option in Agent mode does not take effect when specifying input variables. #20314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
5 tasks done
suntp opened this issue May 27, 2025 · 3 comments · May be fixed by #20362
Open
5 tasks done
Assignees
Labels
🐞 bug Something isn't working

Comments

@suntp
Copy link

suntp commented May 27, 2025

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

1.4.1

Cloud or Self Hosted

Self Hosted (Source)

Steps to reproduce

1、The specific settings in Agent mode are shown in the figure below.

Image

2、I have found the cause of the problem. In Agent mode, the setting variable name for metadata filtering uses the display name; in chatflow mode, the variable name uses the variable name itself.The specific settings in Chatflow mode are shown in the figure below.

Image
  1. The solution should be to change the metadata filtering variable setting on the web interface of Agent mode to use the variable name instead of the display name. I debugged the Python backend code and printed the logs of input variables and metadata configurations, confirming that this solution should be feasible.
Image Image

✔️ Expected Behavior

The input should hit the documents in the knowledge base.

❌ Actual Behavior

The input does not hit the documents in the knowledge base.

@dosubot dosubot bot added the 🐞 bug Something isn't working label May 27, 2025
Copy link

dosubot bot commented May 27, 2025

Hi @suntp! I'm Dosu and I’m helping the dify team.

You've correctly identified a real issue: in Agent mode, manual metadata filtering does not take effect when specifying input variables because the system uses the display name instead of the variable name for filtering. This mismatch prevents the input from matching documents in the knowledge base as expected.

This is a known limitation in Dify Agent applications. The Agent application was originally designed to support only external data tools and did not include the necessary code for knowledge base retrieval and metadata filtering, unlike Chatflow mode. As a result, metadata filtering in Agent mode has not worked as intended in past versions, including 1.4.1. There is a related discussion and confirmation of this limitation, along with a temporary fix provided in PR #19020 (issue reference).

The root cause is that the metadata filtering condition is identified by a name field in the code, which appears to be mapped to the display name in Agent mode, rather than the variable name as in Chatflow mode. This difference leads to the filtering not working as expected when input variables are specified.

A recent fix has addressed a related issue where the metadata_condition parameter was not being used for non-external providers, causing metadata filtering to fail in both chatbot and workflow implementations. This has now been acknowledged and fixed by the Dify team (details here).

What you can do:

  • If you are able to update your deployment, check if the temporary fix from PR fix: metadata filter not work #19020 resolves your issue.
  • As you suggested, changing the metadata filtering variable setting in Agent mode to use the variable name (instead of the display name) should resolve the mismatch and allow filtering to work as expected.

If you need more details on how to apply the fix or where to make the change, let me know!

To reply, just mention my name @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Join Discord Share on X

@suntp
Copy link
Author

suntp commented May 27, 2025

There is still a bug in the web interface: even if a variable is specified, the option still displays Constant.

Image

@suntp
Copy link
Author

suntp commented May 28, 2025

hi,I've already identified the location of the problematic code and fixed it locally, as shown in the image below. Am I allowed to submit the code to resolve this bug? @crazywoola @JohnJyong

Image

suntp added a commit to suntp/dify that referenced this issue May 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug Something isn't working
Projects
None yet
2 participants