Repository navigation
Description
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.17.1 (also reproducible on current main)
Cloud or Self Hosted
Self Hosted (Docker)
Steps to reproduce
-
Create a knowledge base with two metadata fields:
writer(string) andyear(number). -
Add three documents:
document metadata alicewriter = "Alice",year = 2023bobwriter = "Bob",year = 2025missingno metadata values set -
Filter with each condition below.
| condition | value | current result |
|---|---|---|
writer is not |
Alice |
{bob} |
year ≠ |
2023 |
{bob} |
writer not contains |
Ali |
{bob} |
writer not in |
Alice |
{bob} |
writer is |
Alice |
{alice} |
writer in |
Alice |
{alice} |
year > |
2024 |
{bob} |
missing is returned by none of the negative operators.
Cause. writer is not "Alice" is compiled to:
WHERE (documents.doc_metadata ->> 'writer') != 'Alice'For missing, ->> 'writer' is NULL, so the predicate is NULL != 'Alice', which evaluates to unknown rather than TRUE. WHERE keeps only TRUE rows, so the document is excluded. NOT LIKE and NOT IN behave the same way.
✔️ Expected Behavior
This is a question about intended semantics rather than a clear bug. There are two readings:
- A (current): "is not Alice" means the writer is known and is not Alice. A missing value is unknown, so the document is excluded.
- B: "is not Alice" means there is no indication that the writer is Alice. A missing value is not Alice, so the document is included, and the four negative operators would return
{bob, missing}.
Reasons I think B fits better:
emptyalready treats a missing key as an empty value.missingmatcheswriter empty. An empty value is clearly not"Alice", yetmissingfailswriter is not "Alice".isandis notshould be complementary. Users expectis Xandis not Xto split the documents into two groups, butmissingcurrently matches neither. Filtering out Alice's documents also silently drops every document whose metadata hasn't been filled in.- Other systems behave like B. In MongoDB,
$neand$ninmatch documents that do not contain the field. In Elasticsearch,bool.must_notwith atermquery returns documents that lack the field.
❌ Actual Behavior
Documents without the metadata key are excluded by is not / ≠ / not contains / not in, as shown above.
Question: Is reading A intended? If B is preferred, I've opened #44753 which adds OR <field> IS NULL to these four operators only; >/< and the positive operators are unchanged. Happy to close it if the current behavior is intended.
This affects knowledge retrieval in chat apps, the Knowledge Retrieval node in workflows, and hit testing, since they share process_metadata_filter_func.
Related: #43346 changes empty / not empty in the same function; this is independent of it.
Activity
asukaminato0721 commentedon Oct 25, 2026
@dosu what do you think
dosubot commentedon Oct 25, 2026
I’d favor B as the product semantics, but treat it as an intentional behavior change rather than an unquestionable bug fix.
For a user-facing exclusion filter, I think “exclude Alice” should leave documents with no writer value eligible. Making positive and negative filters complementary for non-null comparison values gives a clearer rule than exposing SQL’s three-valued logic. There is already a precedent in this function:
not in []explicitly evaluates toTRUE, even for missing metadata. [1]I’d define the contract explicitly:
nullmatch the four negative operators.emptyalso matches them is a separate decision.The compatibility caveat matters: the existing predicates exclude SQL NULL values, so adopting B would broaden the eligible document set for existing negative filters. I’d document that change in the release notes and pin down missing-key, JSON-null, blank-string, and populated-value behavior in regression tests before shipping it. [2]
To reply, just mention @dosu.
Docs are dead. Just use Dosu.