Skip to content

fix(retrievers): apply retriever_weights in reciprocal_rerank_fusion mode#21467

Closed
VANDRANKI wants to merge 1 commit into
run-llama:mainfrom
VANDRANKI:fix/fusion-retriever-rrf-weights
Closed

fix(retrievers): apply retriever_weights in reciprocal_rerank_fusion mode#21467
VANDRANKI wants to merge 1 commit into
run-llama:mainfrom
VANDRANKI:fix/fusion-retriever-rrf-weights

Conversation

@VANDRANKI

Copy link
Copy Markdown

Summary

Setting retriever_weights on a QueryFusionRetriever with mode="reciprocal_rerank" has no effect — all retrievers are weighted equally. The weights are silently ignored.

Root cause

_reciprocal_rerank_fusion iterates over results.values(), discarding the (query_str, retriever_idx) key. Each node always gets 1.0 / (rank + k) regardless of its retriever's weight:

# Before (broken)
for nodes_with_scores in results.values():  # key discarded
    ...
    fused_scores[hash] += 1.0 / (rank + k)  # no weight applied

_relative_score_fusion already does this correctly with retriever_idx = query_tuple[1] and self._retriever_weights[retriever_idx].

Fix

Switch to results.items(), extract retriever_idx from the key, and scale the RRF contribution by self._retriever_weights[retriever_idx]:

for query_tuple, nodes_with_scores in results.items():
    retriever_idx = query_tuple[1]
    weight = self._retriever_weights[retriever_idx]
    ...
    fused_scores[hash] += weight / (rank + k)

This mirrors the weight application in _relative_score_fusion and was introduced in PR #11667 but not carried through to the RRF path.

Fixes #21444

…mode

_reciprocal_rerank_fusion iterated over results.values(), discarding the
(query_str, retriever_idx) key.  As a result, every retriever contributed
1.0 / (rank + k) regardless of its configured weight; retriever_weights was
silently ignored when mode="reciprocal_rerank".

_relative_score_fusion already extracts retriever_idx = query_tuple[1] and
multiplies by self._retriever_weights[retriever_idx].  Apply the same
pattern in _reciprocal_rerank_fusion: iterate over results.items(), extract
the retriever index from the key, and scale the RRF score by the weight:
    fused_scores[hash] += weight / (rank + k)

Fixes run-llama#21444
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Apr 24, 2026
@gautamvarmadatla

Copy link
Copy Markdown
Contributor

hi @VANDRANKI there is already a PR i created along with the issue #21445. Please review existing work before mass opening AI PRs :)

Infact, you even commented on my PR saying LGTM lol

@VANDRANKI

Copy link
Copy Markdown
Author

Closes as duplicate of #21445 by @gautamvarmadatla, which was already open before this PR was created. Apologies for the noise - I should have checked for existing open PRs before opening this. To make it worse, I had already reviewed #21445 and left LGTM on it, then opened this competing PR. That was a serious oversight. Please disregard this PR and consider #21445 instead.

@VANDRANKI VANDRANKI closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS This PR changes 0-9 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