Repository navigation
fix(rag): treat null and blank metadata values as empty in metadata filters - #43346
Open
msdianprince-7 wants to merge 1 commit into
Open
msdianprince-7 wants to merge 1 commit into
msdianprince-7 wants to merge 1 commit into
Conversation
…ilters The "empty" / "not empty" conditions checked the JSON element for SQL NULL, so a field attached to a document without a value (stored as JSON null) was treated as not empty. Compare the extracted text value instead, which maps JSON null to NULL on PostgreSQL and MySQL, and count "" as empty. Fixes langgenius#43345 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-10-02 06:53:41.395329849 +0000
+++ /tmp/pyrefly_pr.txt 2026-10-02 06:53:33.171171874 +0000
@@ -4251,7 +4251,7 @@
ERROR Argument `SimpleNamespace` is not assignable to parameter `orig` with type `BaseException` in function `sqlalchemy.exc.DBAPIError.__init__` [bad-argument-type]
--> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.py:5594:13
ERROR Argument `str` is not assignable to parameter `metadata_filtering_mode` with type `Literal['automatic', 'disabled', 'manual']` in function `core.workflow.nodes.knowledge_retrieval.retrieval.KnowledgeRetrievalRequest.__init__` [bad-argument-type]
- --> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval_methods.py:145:33
+ --> tests/unit_tests/core/rag/retrieval/test_dataset_retrieval_methods.py:147:33
ERROR Argument `Iterator[SimpleNamespace]` is not assignable to parameter `invoke_result` with type `Generator[Unknown]` in function `core.rag.retrieval.router.multi_dataset_react_route.ReactMultiDatasetRouter._handle_invoke_result` [bad-argument-type]
--> tests/unit_tests/core/rag/retrieval/test_multi_dataset_react_route.py:194:52
ERROR Argument `None` is not assignable to parameter `text` with type `str` in function `core.rag.splitter.text_splitter.RecursiveCharacterTextSplitter.split_text` [bad-argument-type]
|
Contributor
Pyrefly Type Coverage
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #43346 +/- ##
==========================================
- Coverage 88.59% 88.59% -0.01%
==========================================
Files 5182 5182
Lines 326050 326050
Branches 65397 65397
==========================================
- Hits 288874 288866 -8
- Misses 31928 31937 +9
+ Partials 5248 5247 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
Author
|
@JohnJyong friendly ping on this one, it still merges cleanly with main and CI is green. Happy to adjust anything if needed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
Fixes #<issue number>.Summary
Fixes #43345
The metadata filter conditions
empty/not emptycheckeddoc_metadata -> '<field>' IS NULL. When a field is attached to a document without a value, the UI stores it as JSONnull, and on PostgreSQL->returns the JSONB valuenull, not SQLNULL. So those documents were skipped byemptyand matched bynot empty.This change compares the extracted text value (
as_string(), already used by the other conditions) instead. SQLAlchemy maps a JSONnullto SQLNULLthere on both PostgreSQL (->>) and MySQL. A blank string""now also counts as empty.Added a SQLite-backed test that stores documents with the key missing,
null,""and a real value, and checks which ones each condition returns. It fails onmainand passes with this change.Screenshots
emptymisses documents whose value isnullemptymatches missing,nulland""valuesChecklist
make lint && make type-check(backend) andvp staged(frontend) to appease the lint gods🤖 Generated with Claude Code
From Claude Code