QueryFusionRetriever Score Fusion#
QueryFusionRetriever fans out a single query into multiple LLM-generated variants, runs each against one or more backing retrievers, then merges the ranked results using a configurable fusion mode. Score fusion is the last step: it combines per-retriever, per-query result lists into a single ranked list.
Fusion Modes#
Four modes are defined in FUSION_MODES:
| Mode | Value | Scoring logic |
|---|---|---|
RECIPROCAL_RANK | "reciprocal_rerank" | 1 / (rank + 60) summed across all result lists (RRF formula) |
RELATIVE_SCORE | "relative_score" | Min-max normalization per result list → weighted sum |
DIST_BASED_SCORE | "dist_based_score" | Same as above, but min/max derived from mean ± 3 σ |
SIMPLE | "simple" | De-duplicate by node hash, keep max score |
The default mode is SIMPLE . Retriever weights default to equal shares (1/N) and are normalized to sum to 1 .
Implementation Entry Points#
| Symbol | Lines | Notes |
|---|---|---|
_reciprocal_rerank_fusion | 100–135 | Sorts by descending score, assigns RRF weight; cites original paper at L106–107 |
_relative_score_fusion | 137–198 | Handles both relative_score and dist_based_score via dist_based flag |
_simple_fusion | 200–217 | Max-score de-duplication |
_retrieve / _aretrieve | 263–304 | Dispatches to the appropriate fusion method |
Score Normalization Details (Relative / Dist-Based)#
_relative_score_fusion works in two passes:
- Compute per-list min/max using
node.score or 0.0coercion . Fordist_based, the effective min/max are mean ± 3 σ instead of the actual min/max. - Rescale each score to
[0, 1], then multiply byretriever_weights[retriever_idx]and divide bynum_queries. Nodes appearing in multiple result lists accumulate their weighted scores .
Known Issues#
None scores crash relative/dist-based fusion#
NodeWithScore.score is Optional[float]. The normalization step at L173–175 performs arithmetic directly on node_with_score.score without a None guard, raising a TypeError when a retriever (e.g., SummaryIndexRetriever, KeywordTableRetriever) emits unscored nodes. Both PR #22386 and PR #22717 fix this by applying or 0.0 at the normalization line; neither PR has been merged as of the latest update.
retriever_weights ignored in reciprocal-rank mode#
The current _reciprocal_rerank_fusion accumulates unweighted RRF scores — configured retriever_weights have no effect. PR #21445 fixes this by multiplying each contribution by the retriever's weight; also open/unmerged .
In-place mutation of NodeWithScore corrupts shared/cached results#
All three score-altering modes write the fused score directly back onto the original NodeWithScore objects returned by the backing retrievers — no copy is made . If a caching layer reuses the same Python objects across calls, the scores accumulate across invocations, corrupting rankings: nodes that should rank highly may fall below the similarity_top_k cutoff on the next call.
SIMPLEmode also mutates.scoreon duplicates L213, but the effect is benign (retains the max value).- Mitigation: Shallow-copy
NodeWithScorewrappers before passing them into fusion, or avoid caching layers that reuse wrapper objects acrossQueryFusionRetrievercalls.