fix(rag): decouple hybrid recall from top_k for stable merged ranking…#35498
Open
thomascolden585-svg wants to merge 1 commit into
Open
Conversation
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.
Summary
Fixes mixed (hybrid) RAG retrieval so changing only Top K no longer changes which segments participate in score fusion, which could reorder the head and make the first N results differ between a small Top K and a large Top K for the same query.
Problem
Hybrid search runs vector and full-text in parallel, deduplicates, then merges scores (weighted score or reranker). The final
top_kwas also used as the per-channel limit for each sub-retriever. A segment can sit belowkin both channels but still get a high combined score. With a smallkit never entered the candidate pool; with a largerkit did—so the merged top results were inconsistent with user expectations (reported in #35482).Solution
min(200, max(50, final_top_k)).embedding_searchandfull_text_index_searchin hybrid mode.top_kviaDataPostProcessor.invoke(..., top_n=top_k).Trade-offs
Slightly more work per hybrid query (larger per-channel fetch) in exchange for stable, correct fusion behavior.
Test plan
uv run pytest tests/unit_tests/core/rag/datasource/test_datasource_retrieval.py::test_hybrid_recall_top_k_for_merge_contract -quv run pytest tests/unit_tests/core/rag/retrieval/test_dataset_retrieval.py -k hybrid -qRelated