Repository navigation
fix(metadata): Elasticsearch date filtering — exact-match returns 0 and ASCII operators dropped - #16833
fix(metadata): Elasticsearch date filtering — exact-match returns 0 and ASCII operators dropped#16833Xavierando wants to merge 1133 commits into
Conversation
### Summary Go development guide --------- Signed-off-by: Jin Hai <[email protected]>
As title --------- Signed-off-by: Jin Hai <[email protected]>
### Summary --migrate will trigger database migration ``` ./ragflow_main --api --migrate ``` Signed-off-by: Jin Hai <[email protected]>
### Summary Remove ragflow-cli building dependency Signed-off-by: Jin Hai <[email protected]>
### Summary Fix Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
…ow#16736) Bumps [golang.org/x/crypto](https://github.com/golang/crypto) from 0.51.0 to 0.52.0.
…17010) ## Summary - Preserve request-scoped system variables such as files and user IDs during Canvas execution. - Persist conversation history, turn counts, and tool memory in the session DSL across turns. - Parse agent uploads into `sys.files` and align system variable rendering with Python. ## Testing - `bash build.sh --test ./internal/agent/...` - `bash build.sh --test ./internal/service/...` <img width="1896" height="1232" alt="image" src="https://github.com/user-attachments/assets/b420cd97-53c3-470f-a3e1-d39cea26a213" />
…#17034) ## Summary - Filter the `[DONE]` transport sentinel from Eino model streams - Add regression coverage for stream messages and callbacks ## Testing - `bash build.sh --test ./internal/entity/models` - `bash build.sh --test ./internal/agent/component` - `bash build.sh --test -run 'Test(AgentChatCompletions_Stream|RunAgent_Stream)' ./internal/handler`
### Summary As title <img width="3116" height="1949" alt="image" src="https://github.com/user-attachments/assets/13692cb2-06d6-470b-b13e-182773c8225a" />
### Summary As title <img width="3718" height="2029" alt="image" src="https://github.com/user-attachments/assets/227bcd8b-e5b8-465e-983c-c0c0650a4ea5" /> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
### Summary CI: modify longtime testcase to p3
### Summary ``` RAGFlow(api/default)> CHAT WITH 'glm-4-flash@new_test@zhipu-ai' MESSAGE '30 words describes LLM'; Answer: Hello! I'm ChatGLM, an AI assistant. Feel free to ask me any questions or request help with any tasks. Input tokens: 5 Output tokens: 28 Time: 12.748241 ``` Signed-off-by: Jin Hai <[email protected]>
# Conflicts: # test/unit_test/common/test_metadata_filter_operators.py
… fallback the recogniser can't serve (infiniflow#16958)
…nd tests Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Rebased on latest The only conflict was a tail-append collision in Recap for reviewers — this fixes three bugs in ES metadata date filtering (#16832):
Cross-PR note for @chuenchen309 / maintainers — there's a load-bearing ordering dependency with the open #16943 (Infinity push-down rejecting multi-valued-unsafe negative ops). That guard keys on the Unicode Beyond these three point-fixes, @zeweihan's framing on #16832 and #16967 (backend-specific schema/semantics drift — "same query, different backend, materially different answer, zero error signal") points at a durable follow-up: a backend-parity test asserting ES/Infinity/in-memory return identical filter sets, plus a One note for maintainers: the |
…ative ops (≠, not in) (#16943) ### What problem does this PR solve? The Elasticsearch and Infinity metadata push-down translators are meant to be interchangeable pre-filters that both mirror the in-memory `meta_filter` fallback — the shared test section is even titled *"is_pushdown_supported pre-check (same logic for both backends)"*. But the two `is_pushdown_supported` implementations diverge: - `common/metadata_es_filter.py` defines `MULTIVALUE_UNSAFE_NEGATIVE_OPS = frozenset({"≠", "not in"})` and refuses push-down for those operators. - `common/metadata_infinity_filter.py` has **no such guard** and pushes them down. **Why the guard exists:** `meta_fields.<key>` can hold a JSON array, and the in-memory `meta_filter` matches a document when **any** of its values satisfies the predicate (per-value-bucket semantics). A document whose `tag` is `[a, b]` therefore still matches `tag ≠ a` — bucket `b` satisfies it. The Infinity push-down emits `NOT JSON_CONTAINS(meta_fields, '$.tag', '"a"')`, which means *"the array contains no `a` at all"*, so it **silently drops** that document. Same divergence for `not in`. The result: `tag ≠ a` / `tag not in (...)` under-counts results for any document that has the excluded value alongside others, but only on the Infinity backend. This is on a live production path: `DocMetadataService._filter_doc_ids_by_metadata_infinity` (`api/db/services/doc_metadata_service.py:948`) calls this exact `is_pushdown_supported` as the sole gate before building the Infinity SQL, mirroring the ES branch at line 880 which uses the guarded ES version. Reproduction (both real modules, no services needed): ```python >>> from common import metadata_es_filter as es, metadata_infinity_filter as inf >>> f = [{"op": "≠", "key": "tag", "value": "a"}] >>> es.is_pushdown_supported(f), inf.is_pushdown_supported(f) (False, True) # ES falls back to in-memory (correct); Infinity pushes down (wrong) ``` ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) ### Fix Add the same `MULTIVALUE_UNSAFE_NEGATIVE_OPS` set to `metadata_infinity_filter` and reject those operators in `is_pushdown_supported`, so a single such filter forces the whole request to the in-memory path — the only place the per-bucket semantics are reproduced. `not contains` is intentionally still allowed, matching the ES backend (`all(not contains)` == `not any(contains)`, which the push-down expresses correctly on multi-valued fields). The `≠` / `not in` translators themselves are unchanged — they remain correct for the in-memory-fallback path; only the push-down eligibility gate is fixed. ### Testing - Confirmed `is_pushdown_supported([{op}])` now returns `False` for `≠` and `not in` on **both** backends (previously ES=False, Infinity=True). - Added `test_pushdown_check_rejects_multivalue_unsafe_negative_ops`, which asserts both backends reject these ops. Confirmed red→green: it fails against the pre-fix Infinity module, passes after. - `ruff check` / `ruff format --check` clean. ### Note on overlap Open PR #16833 also edits `test/unit_test/common/test_metadata_filter.py`, but only **appends** at the end of the file (line 640+) and changes `metadata_es_filter.py` / `metadata_utils.py`, not the Infinity module — no overlap with this change. ### Disclosure AI-assisted (Claude Code): the divergence was surfaced by an AI-assisted review pass, but I independently reproduced it against the real modules, confirmed the production call path, and verified the fix and test before submitting. Signed-off-by: Andrew Chen <[email protected]> Signed-off-by: chuenchen309 <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]>
|
@sxxtony Would you please help review this PR? |
qinling0210
left a comment
There was a problem hiding this comment.
@Xavierando Please rebase your code change to latest code.
And make sure you have verified your code change.
|
We have released RAGFlow v1.0.0-rc1 today, and we only have go code on main branch. Python code is only on 0.27.x branch. Could you please apply your code change to the 2 branches separately? We are mainly developing in Go, so please make modifications in Go first. Thanks. |
|
Hi, thanks for the info. I belive i will update my project to the go codebase and adapt my fix. It will probably take a couple of days |
|
Thanks @qinling0210. The Go fix is in #20532. On Since |
Summary
Fixes three bugs that break document-metadata date filtering on Elasticsearch (issue #16832). They surface as "date filter returns nothing / returns everything" in chat
auto/semi_autofiltering and in/api/v1/retrieval.1. Exact-match
=on adate-typed field returned 0.ES dynamic date detection types a
YYYY-MM-DDmeta field asdate, which has no.keywordsub-field;_term_or_matchbuilt a.keyword-only term for string values, so=on a date field silently matched nothing. ISO-date values now match both the parent field and.keywordvia ashould; non-date strings are unchanged (multi-word phrase equality preserved).2. ASCII comparison operators were silently dropped.
gen_meta_filterand user conditions may emit>=/<=/!=/==, but the push-down (SUPPORTED_OPERATORS) and the in-memory path only accept the Unicode set (≥/≤/≠/=); an un-normalised operator dropped the whole filter. Addednormalize_condition_operators()(mirroringconvert_conditions) and applied it at the top of_run_metadata_filter, so every backend benefits.3. A filter that matches nothing fell back to unrestricted retrieval (latent; exposed by 1 and 2).
apply_meta_data_filterreturnedNonefrom theauto/semi_autobranches when the generated conditions matched zero documents.Nonemeans "no metadata filter", so retrieval ran unrestricted and returned arbitrary documents instead of "no results". Themanualbranch already returns the["-999"]no-results sentinel here;auto/semi_autonow do the same, while still returningNonewhen no conditions were generated (genuinely no filter). This bug is pre-existing, but only once=/range filtering works (fixes 1 and 2) can a date query legitimately match zero documents and reach this fallback — e.g. "what happened yesterday" on a date with no documents previously surfaced unrelated docs with a hallucinated date.All three fixes have unit tests (
test/unit_test/common/test_metadata_filter.py,test/unit_test/common/test_metadata_filter_operators.py,test/unit_test/common/test_apply_semi_auto_meta_data_filter.py) and fixes 1–2 were verified against a live Elasticsearch index (bug 1:0 → 12docs; bug 2:dropped → 18docs).Closes #16832