Knowledge retrieve metadata filtering is not working for the comparison_operator of in #21297

Closed
opened 2026-02-21 20:11:49 -05:00 by yindo · 1 comment
Owner

Originally created by @jingsam on GitHub (Dec 25, 2025).

Originally assigned to: @fatelei on GitHub.

Self Checks

  • I have read the Contributing Guide and Language Policy.
  • 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, otherwise it will be closed.
  • 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
  • Please do not modify this template :) and fill in all the required fields.

Dify version

1.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

I tried the Knowledge retireve API (https://api.dify.ai/v1/datasets/{dataset_id}/retrieve) to do metadata filtering with custom metadata. Here's the query body:

{
    "query": "三维",
    "retrieval_model": {
        "search_method": "hybrid_search",
        "top_k": 10,
        "reranking_enable": true,
        "score_threshold_enabled": true,
        "score_threshold": 0.5,
        "metadata_filtering_conditions": {
            "logical_operator": "and",
            "conditions": [{
                "name": "zllx_dm",
                "comparison_operator": "in",
                "value": "11,12"
            }]
        }
    }
}

The response shows that the metadata filtering is not working, while still return zllx_dm other than 11 and 12.

✔️ Expected Behavior

metadata filtering with in operator should work.

Actual Behavior

not working

Originally created by @jingsam on GitHub (Dec 25, 2025). Originally assigned to: @fatelei on GitHub. ### Self Checks - [x] I have read the [Contributing Guide](https://github.com/langgenius/dify/blob/main/CONTRIBUTING.md) and [Language Policy](https://github.com/langgenius/dify/issues/1542). - [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, otherwise it will be closed. - [x] 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :) - [x] Please do not modify this template :) and fill in all the required fields. ### Dify version 1.11.1 ### Cloud or Self Hosted Self Hosted (Docker) ### Steps to reproduce I tried the Knowledge retireve API (https://api.dify.ai/v1/datasets/{dataset_id}/retrieve) to do metadata filtering with custom metadata. Here's the query body: ``` { "query": "三维", "retrieval_model": { "search_method": "hybrid_search", "top_k": 10, "reranking_enable": true, "score_threshold_enabled": true, "score_threshold": 0.5, "metadata_filtering_conditions": { "logical_operator": "and", "conditions": [{ "name": "zllx_dm", "comparison_operator": "in", "value": "11,12" }] } } } ``` The response shows that the metadata filtering is not working, while still return `zllx_dm` other than `11` and `12`. ### ✔️ Expected Behavior metadata filtering with `in` operator should work. ### ❌ Actual Behavior not working
yindo added the 🐞 bug label 2026-02-21 20:11:49 -05:00
yindo closed this issue 2026-02-21 20:11:49 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Dec 25, 2025):

This is a known issue: the in operator for metadata filtering in the Knowledge retrieve API is not actually implemented in the backend logic, so any filter using in is ignored and does not restrict results—even if you use the correct value format (which should be a list, e.g., ["11", "12"], not a comma-separated string) [code reference]. This limitation is tracked in multiple issues and has been acknowledged by maintainers [issue 17624].

Until the backend adds support for the in operator, you can only use other supported operators like is or contains as a workaround, or restructure your queries. There’s no direct fix without a code change. Keep an eye on future releases for updates on this feature.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

@dosubot[bot] commented on GitHub (Dec 25, 2025): <!-- Answer --> This is a known issue: the `in` operator for metadata filtering in the Knowledge retrieve API is not actually implemented in the backend logic, so any filter using `in` is ignored and does not restrict results—even if you use the correct value format (which should be a list, e.g., `["11", "12"]`, not a comma-separated string) [[code reference](https://github.com/langgenius/dify/blob/f0d02b4b91edd2e014ecfe1cec8c37da3023bbe7/api/core/rag/retrieval/dataset_retrieval.py#L1011-L1224)]. This limitation is tracked in multiple issues and has been acknowledged by maintainers [[issue 17624](https://github.com/langgenius/dify/issues/17624)]. Until the backend adds support for the `in` operator, you can only use other supported operators like `is` or `contains` as a workaround, or restructure your queries. There’s no direct fix without a code change. Keep an eye on future releases for updates on this feature. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/1b7ed06f-3c8a-4fb8-8f75-60550d8d2b13?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=This%20is%20a%20known%20issue%3A%20the%20%60in%60%20operator%20for%20metadata%20filtering%20in%20the%20Knowledge%20retrieve%20API%20is%20not%20actually%20implemented%20in%20the%20backend%20logic%2C%20so%20any%20filter%20using%20%60in%60%20is%20ignored%20and%20does%20not%20restrict%20results%E2%80%94even%20if%20you%20use%20the%20correct%20value%20format%20%28which%20should%20be%20a%20list%2C%20e.g.%2C%20%60%5B%2211%22%2C%20%2212%22%5D%60%2C%20not%20a%20comma-separated%20string%29%20%5B%5Bcode%20reference%5D%28https%3A//github.com/langgenius/dify/blob/f0d02b4b91edd2e014ecfe1cec8c37da3023bbe7/api/core/rag/retrieval/dataset_retrieval.py%23L1011-L1224%29%5D.%20This%20limitation%20is%20tracked%20in%20multiple%20issues%20and%20has%20been%20acknowledged%20by%20maintainers%20%5B%5Bissue%2017624%5D%28https%3A//github.com/langgenius/dify/issues/17624%29%5D.%0A%0AUntil%20the%20backend%20adds%20support%20for%20the%20%60in%60%20operator%2C%20you%20can%20only%20use%20other%20supported%20operators%20like%20%60is%60%20or%20%60contains%60%20as%20a%20workaround%2C%20or%20restructure%20your%20queries.%20There%E2%80%99s%20no%20direct%20fix%20without%20a%20code%20change.%20Keep%20an%20eye%20on%20future%20releases%20for%20updates%20on%20this%20feature.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/langgenius/dify/issues/30188)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#21297