fix: apply retriever weights in reciprocal rank fusion#22171
Closed
fengjikui wants to merge 1 commit into
Closed
Conversation
Contributor
|
Hi @fengjikui, please check existing open PRs before mass opening new ones. Most of your PRs are duplicating existing work, and I’ve already left comments on multiple other PRs of yours. Even for this PR there is #21445 :) |
Author
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
retriever_weightswhenmode="reciprocal_rerank"#21444.retriever_weightswhenQueryFusionRetrieveruses reciprocal rank fusion.retriever_weights=[1.0, 0.0]withmode=FUSION_MODES.RECIPROCAL_RANK.Root cause
_reciprocal_rerank_fusion()iterated overresults.values(), which discarded the(query, retriever_idx)key. Withoutretriever_idx, the reciprocal rank score always used an implicit equal weight.Fix
The method now iterates over
results.items(), reads the retriever index from the key, and scales each reciprocal-rank contribution byself._retriever_weights[retriever_idx].Validation
uv run --frozen --project llama-index-core pytest llama-index-core/tests/retrievers/test_fusion_retriever.py -quv run --frozen --project llama-index-core ruff format --check llama-index-core/llama_index/core/retrievers/fusion_retriever.py llama-index-core/tests/retrievers/test_fusion_retriever.pyuv run --frozen --project llama-index-core ruff check llama-index-core/llama_index/core/retrievers/fusion_retriever.py llama-index-core/tests/retrievers/test_fusion_retriever.pyAI assistance
I used AI assistance to help trace the narrow code path and draft this small patch, then manually reviewed the diff and validated it with the commands above.