Skip to content

fix(core): retriever_weights not applied in QueryFusionRetriever reciprocal_rerank mode#21445

Open
gautamvarmadatla wants to merge 5 commits into
run-llama:mainfrom
gautamvarmadatla:fix/rrf-retriever-weights
Open

fix(core): retriever_weights not applied in QueryFusionRetriever reciprocal_rerank mode#21445
gautamvarmadatla wants to merge 5 commits into
run-llama:mainfrom
gautamvarmadatla:fix/rrf-retriever-weights

Conversation

@gautamvarmadatla

Copy link
Copy Markdown
Contributor

Description

Fixed _reciprocal_rerank_fusion to iterate results.items() instead of results.values() and apply self._retriever_weights[retriever_idx] to each score, so user-specified weights are now honored in reciprocal rank mode the same way they already are in relative score fusion.

Fixes #21444

New Package?

Did I fill in the tool.llamahub section in the pyproject.toml and provide a detailed README.md for my new integration or package?

  • Yes
  • No

Version Bump?

Did I bump the version in the pyproject.toml file of the package I am updating? (Except for the llama-index-core package)

  • Yes
  • No

Type of Change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Your pull-request will likely not be merged unless it is covered by some form of impactful unit testing.

  • I added new unit tests to cover this change
  • I believe this change is already covered by existing unit tests

Suggested Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added Google Colab support for the newly added notebooks.
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I ran uv run make format; uv run make lint to appease the lint gods

@dosubot dosubot Bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 22, 2026

@VANDRANKI VANDRANKI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix is correct and addresses two separate issues in _reciprocal_rerank_fusion.

Bug 1 (weights ignored): for nodes_with_scores in results.values() threw away the retriever index, making self._retriever_weights unreachable. Switching to results.items() and multiplying by self._retriever_weights[retriever_idx] is the right fix. Note that _retriever_weights is already normalized to sum to 1.0 by QueryFusionRetriever.__init__, so the multiplication is safe.

Bug 2 (node mutation): reranked_nodes[-1].score = score was mutating the original NodeWithScore objects in hash_to_node. Creating a new NodeWithScore(node=..., score=score) is the right approach - it avoids side effects on any caller that retains references to the original nodes.

Tests are the best part of this PR. test_rrf_zero_weight_retriever_does_not_influence_results with [1.0, 0.0] and [0.0, 1.0] weights is a definitive regression test - it would have failed before this fix because the old code used 1.0 / (rank + k) for every retriever regardless of weight. The parametrize pattern keeps both cases together. test_rrf_higher_weight_retriever_scores_higher verifies the relative ordering.

LGTM.

@gautamvarmadatla

Copy link
Copy Markdown
Contributor Author

I checked the PR diff, and this looks unrelated to the changes here. This PR only touches llama-index-core’s QueryFusionRetriever logic and its tests.

The failing CI errors are from integration dependency resolution issues and a separate rankllm-rerank import failure:

ImportError: cannot import name 'PromptMode' from 'rank_llm.rerank.reranker'

Since this PR doesn’t touch those packages or dependency pins, I believe the failures are unrelated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: QueryFusionRetriever ignores retriever_weights when mode="reciprocal_rerank"

2 participants