The "empty" and "not empty" filtering conditions are not working in the knowledge retrieval metadata filtering operation. #16320

Closed
opened 2026-02-21 19:25:38 -05:00 by yindo · 1 comment
Owner

Originally created by @rouxiaomin on GitHub (Aug 21, 2025).

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.7.2

Cloud or Self Hosted

Cloud

Steps to reproduce

Reproduce Step:
1.Set metadata

Image 2.Set workflow Image

✔️ Expected Behavior

Expected no results

Actual Behavior

Still retrieved one

Image
Originally created by @rouxiaomin on GitHub (Aug 21, 2025). ### 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.7.2 ### Cloud or Self Hosted Cloud ### Steps to reproduce Reproduce Step: 1.Set metadata <img width="1312" height="506" alt="Image" src="https://github.com/user-attachments/assets/783d7225-f267-4b70-99b5-bdd77b7b7845" /> 2.Set workflow <img width="1718" height="442" alt="Image" src="https://github.com/user-attachments/assets/0bfdac61-2da7-40f4-b379-b126ae2b2a9a" /> ### ✔️ Expected Behavior Expected no results ### ❌ Actual Behavior Still retrieved one <img width="818" height="396" alt="Image" src="https://github.com/user-attachments/assets/ad584dcf-9895-4872-92cd-49efe8e9bc76" />
yindo added the 🐞 bug label 2026-02-21 19:25:38 -05:00
yindo closed this issue 2026-02-21 19:25:38 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Aug 21, 2025):

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

This is a known limitation in Dify 1.7.2: the 'empty' and 'not empty' metadata filtering conditions only check if a metadata field is null or not null in the database. They do not treat empty strings (""), empty lists ([]), or empty objects ({}) as 'empty'—only missing or explicitly null fields match the 'empty' condition. So, if your metadata field exists but is set to an empty string or similar, it will not be filtered out as 'empty' and will still be retrieved. This matches the current code logic for these filters source.

If you want a field to be considered 'empty', make sure it is actually missing from the metadata or set to null. As a workaround, you can preprocess your data to remove keys with empty string/list/object values or set them to null before uploading.

If you need 'empty' to include empty strings/lists/objects, the filtering logic would need to be extended in the codebase to explicitly check for those cases. There have been no recent changes to this logic, so this behavior is consistent across recent versions source.

Let me know if you need guidance on preprocessing your metadata or want details on how to extend the filter logic!

To reply, just mention @dosu.


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

@dosubot[bot] commented on GitHub (Aug 21, 2025): <!-- Greeting --> Hi @rouxiaomin! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the dify team. <!-- Answer --> This is a known limitation in Dify 1.7.2: the 'empty' and 'not empty' metadata filtering conditions only check if a metadata field is null or not null in the database. They do not treat empty strings (`""`), empty lists (`[]`), or empty objects (`{}`) as 'empty'—only missing or explicitly null fields match the 'empty' condition. So, if your metadata field exists but is set to an empty string or similar, it will not be filtered out as 'empty' and will still be retrieved. This matches the current code logic for these filters [source](https://github.com/langgenius/dify/blob/ea066f891f51614b1794a1a079f1e03d53342ed7/api/core/rag/retrieval/dataset_retrieval.py). If you want a field to be considered 'empty', make sure it is actually missing from the metadata or set to null. As a workaround, you can preprocess your data to remove keys with empty string/list/object values or set them to null before uploading. If you need 'empty' to include empty strings/lists/objects, the filtering logic would need to be extended in the codebase to explicitly check for those cases. There have been no recent changes to this logic, so this behavior is consistent across recent versions [source](https://github.com/langgenius/dify/pull/23111). Let me know if you need guidance on preprocessing your metadata or want details on how to extend the filter logic! <!-- 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/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/d7cfdee7-60b7-4329-9935-f3bfc43bb41f?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/6088a4f4-073a-43f3-b3d4-4f06fb0c05a0/ask?utm_source=github)&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/24275)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#16320