llamaIndex - ✅(Solved) Fix [Bug]: QueryFusionRetriever ignores `retriever_weights` when `mode="reciprocal_rerank"` [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
run-llama/llama_index#21444Fetched 2026-04-23 07:23:15
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Timeline (top)
labeled ×2commented ×1cross-referenced ×1

Error Message

Expected output is ['node_A', 'node_B']

Relevant Logs/Tracebacks

Root Cause

When we set retriever_weights with mode="reciprocal_rerank", the weights are silently ignored and all retrievers are effectively weighted equally in the fused score. This happens because _reciprocal_rerank_fusion() iterates over results.values(), which discards the retriever_idx stored in each (query_str, retriever_idx) key, and always adds 1.0 / (rank + k) with no retriever-specific weight applied.

Fix Action

Fixed

PR fix notes

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

Description (problem / solution / changelog)

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

Changed files

  • llama-index-core/llama_index/core/retrievers/fusion_retriever.py (modified, +7/-4)
  • llama-index-core/tests/retrievers/test_fusion_retriever.py (modified, +54/-2)

Code Example

Expected output is ['node_A', 'node_B']

### Relevant Logs/Tracebacks
RAW_BUFFERClick to expand / collapse

Bug Description

When we set retriever_weights with mode="reciprocal_rerank", the weights are silently ignored and all retrievers are effectively weighted equally in the fused score. This happens because _reciprocal_rerank_fusion() iterates over results.values(), which discards the retriever_idx stored in each (query_str, retriever_idx) key, and always adds 1.0 / (rank + k) with no retriever-specific weight applied.

This appears to have been introduced in PR #11667, which added retriever_weights and _relative_score_fusion() together but did not update _reciprocal_rerank_fusion() to use the retriever index.

Version

0.14.21

Steps to Reproduce


from llama_index.core.base.base_retriever import BaseRetriever
from llama_index.core.retrievers import QueryFusionRetriever
from llama_index.core.retrievers.fusion_retriever import FUSION_MODES
from llama_index.core.schema import NodeWithScore, QueryBundle, TextNode


class MockRetriever(BaseRetriever):
      def __init__(self, nodes):
          self._nodes = nodes
          super().__init__()

      def _retrieve(self, query_bundle: QueryBundle):
          return self._nodes


retriever_0 = MockRetriever([
      NodeWithScore(node=TextNode(text="node_A"), score=0.9),
      NodeWithScore(node=TextNode(text="node_B"), score=0.8),
  ])
retriever_1 = MockRetriever([
      NodeWithScore(node=TextNode(text="node_C"), score=0.9),
      NodeWithScore(node=TextNode(text="node_D"), score=0.8),
  ])

retriever = QueryFusionRetriever(
      retrievers=[retriever_0, retriever_1],
      mode=FUSION_MODES.RECIPROCAL_RANK,
      retriever_weights=[1.0, 0.0],
      num_queries=1,
      use_async=False,
  )

results = retriever.retrieve("test query")
print([n.node.get_content() for n in results])

Expected output is ['node_A', 'node_B']

Relevant Logs/Tracebacks

['node_A', 'node_C']

extent analysis

TL;DR

Update the _reciprocal_rerank_fusion() function to use the retriever_idx stored in each (query_str, retriever_idx) key to apply retriever-specific weights.

Guidance

  • Review the changes introduced in PR #11667 to understand how _reciprocal_rerank_fusion() was affected.
  • Modify the _reciprocal_rerank_fusion() function to iterate over results.items() instead of results.values() to preserve the retriever_idx.
  • Apply the retriever_weights to the score calculation in _reciprocal_rerank_fusion() using the retriever_idx.
  • Verify the fix by running the provided example code and checking the output.

Example

def _reciprocal_rerank_fusion(self, results):
    # Iterate over items to preserve retriever_idx
    for (query_str, retriever_idx), nodes in results.items():
        # Apply retriever-specific weight
        weight = self.retriever_weights[retriever_idx]
        # Calculate score with weight
        score = weight * (1.0 / (rank + self.k))
        # ...

Notes

The provided example code and logs suggest that the issue is specific to the RECIPROCAL_RANK fusion mode. The fix may not apply to other fusion modes.

Recommendation

Apply the workaround by modifying the _reciprocal_rerank_fusion() function to use the retriever_idx and apply retriever-specific weights, as this is a targeted fix for the identified issue.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING