Repository navigation
Fix: fix(rag): query_documents ranks any keyword hit above every semantic match, and slows down at scale - #8737
Conversation
|
Verdict: Request changes The ranking fix is sound: keyword matches now compete with meaning-based matches instead of always winning, and both search tools get it. One side effect needs fixing before merge. The new scores are tiny (about 0.02 to 0.03), and they still go out as each passage's "relevance" score. The model now sees every passage scored near zero, and the Agent UI's sources panel shows
Real-world evidenceN/A: no evidence bundle was produced for this PR (internal ranking change, and inference is deferred to the strix-halo lane). The verdict rests on static review alone. I couldn't run the new tests here because pytest isn't installed on this runner. 🔍 Technical details🟡 Fused RRF score is reported as
Before this PR those fields held dense similarities (0.3–0.6) or keyword boosts (0.6–0.9). The smallest fix is to rescale inside Apply the same 🟡 Doc drift: 🟡 Eval coverage (LLM-affecting retrieval path) 🟢 Debug counts no longer list keyword chunks (rag_tools.py:1513-1521, :2023-2031) Sibling paths checked: both tools that had the boost ( Strengths
|
|
Addressed the review in 31b1bb3 (stacked on fce6ccf): fused scores are now rescaled by (k + 1) / 2 in both |
Signed-off-by: SIDDARTHA REDDY <[email protected]> Signed-off-by: Siddartha Reddy Chinthala <[email protected]>
…te spec (amd#4737) Fused RRF scores topped out at 2/61 (~0.03) but were reported unchanged as relevance_score, so the model and the Agent UI saw every passage scored near zero. Rescale by (k + 1) / 2 in both fusion helpers so a chunk ranked first by both lists scores 1.0 (ordering unchanged); update the spec, which still documented the old fixed keyword boost and hash dedupe; list keyword chunks in chunks_before_dedup_indices so the list matches total_chunks_before_dedup; add a test that relevance_score stays in 0-1. Signed-off-by: SIDDARTHA REDDY <[email protected]> Signed-off-by: Siddartha Reddy Chinthala <[email protected]>
31b1bb3 to
3a0c045
Compare
|
Rank fusion is such a clean fix for this, and that turnaround on review was impressive. Thank you @SIDDARTHAREDDY8! |
…8745) The release RAG retrieval benchmark has failed on every tag since v0.26.0-rc26 because a single stale evidence label aborted the whole run about eleven questions in, leaving most of the benchmark (technical docs, XQuAD, the scale tiers, the hard cases) unmeasured. Now a bad label is recorded against its own question while the run carries on, so one stale quote can no longer hide everything after it, and the job still fails at the end when any label error occurred. The two stale quotes themselves are fixed in #8755. <details> <summary>🔍 Technical details</summary> - A question with a label error is left out of the scores, listed in `results.json` (`label_errors` per dataset and in `meta`) and under **Label errors** in the report, and `gaia eval retrieval` exits 1. Any other exception still aborts the run. Scale tiers get the same handling; a tier where every label fails is reported instead of crashing on its summary line. - The report, the harness docstring and `docs/reference/eval.mdx` no longer describe the agent path as a "keyword boost"; it has used rank fusion since #8737. </details> ## Test plan - [x] `pytest tests/unit/rag/test_retrieval_bench_harness.py tests/unit/eval/test_retrieval_bench.py` (new: a bad label mid-dataset, every label bad, a label on a missing page, a non-label failure still aborting, scale tiers with some/all bad labels, report section, CLI exit code) - [ ] After merge (with #8755): dispatch `eval_retrieval.yml` on main and confirm it runs through every dataset
Summary
Fixed amd/gaia #4737 in both
query_documentsandquery_specific_file. The fixed 0.6-0.8 keyword boost (which outranked every dense score, typically 0.3-0.6) is replaced by reciprocal rank fusion (k=60) in shared helpers_fuse_dense_and_keyword/_fuse_extra_scores/_adaptive_max: each ranking contributes 1/(k+rank), so the top dense and top keyword matches compete on equal terms and a chunk both rankings like wins outright.Why
A keyword hit ranked above every semantic match, so retrieval returned lexically matching but semantically weaker chunks first, and the ranking slowed down at scale.
Linked issue
Fixes #4737
Changes
_fuse_dense_and_keyword/_fuse_extra_scores/_adaptive_max._adaptive_max, up to 25) instead of stopping at 5.rag.chunks.index()calls (debug-only paths) are replaced with a one-pass first-index dict; the O(n) regex scan was already gone via the KeywordIndex inverted index (fix(rag): document search re-reads every chunk on every query #6393), whoserank()scoring is unchanged.chunks_before_dedup_indicesnow lists the keyword chunks too so it matchestotal_chunks_before_dedup..takecomment (id 7067087685). Pushed to SIDDARTHAREDDY8/gaia branch oss-bhai-2026-11-21-p1, commit fce6ccf, base main bc3d152, verified on the fork. No PR opened (reviewer gates that).Test plan
tests/unit/rag/test_query_keyword_fusion.py: 10 passed (incl. a new test thatrelevance_scorestays in 0-1) (fusion order, keyword hit no longer outranks top dense match in both tools, chunk both rankings like wins, keyword pool covers all slots, debug indices).test_keyword_search.py,test_keyword_search_tools.py,test_query_balances_documents.py(incl. multi-document spread/budget),test_retrieval_bench_harness.py,test_lemonade_reranking.py(47 passed).tests/unit/rag/: 791 passed, 58 failed, 52 skipped; the 58 failures are all pre-existing in untouched epub/html/image extraction modules (verified: failure list with the fix was identical to pristine main before dep installs; remaining are env/library issues, e.g. pixel-value assertion in image extraction).rag_quality(this change alters which passages fill the context).gaia eval retrieval --suite fullcould NOT be run here: they need the Lemonade embedding server/models, unavailable in this VM. Closest runnable proxies passed: the retrieval bench harness (both pipelines find labelled evidence) and the new tests, which directly assert the reported failure mode (keyword hit above every semantic match) is gone.Evidence
gaia eval retrievalCLI could not run here (needs the Lemonade embedding server/models, unavailable in this VM).Checklist
Closes #N/Fixes #N/Refs #N).python util/lint.py --all,pytest tests/unit/).