Lab / ranking
Reciprocal Rank Fusion
Two search systems disagree about which document is best. RRF merges them using only positions, so it never has to compare scores that were measured on different scales.
RRF(d) = Σᵢ 1 / (k + rankᵢ(d)) — ranks start at 1; a document missing from a ranking adds nothing.
Fixture query: “What handles a scanned PDF?”
Larger k flattens the difference between ranks. The usual default is 60.
Fused order: D1, D3, D2, D4
| Fused | Document | Lexical: rank → 1/(k+rank) | Semantic: rank → 1/(k+rank) | RRF score |
|---|---|---|---|---|
| 1 | D1 | 2 → 1/62 = 0.016129 | 1 → 1/61 = 0.016393 | 0.032522 |
| 2 | D3 | 3 → 1/63 = 0.015873 | 2 → 1/62 = 0.016129 | 0.032002 |
| 3 | D2 | 1 → 1/61 = 0.016393 | absent → 0 | 0.016393 |
| 4 | D4 | absent → 0 | 3 → 1/63 = 0.015873 | 0.015873 |
Ties are broken by document id, so the order never depends on input order.
Reading the result
With the example rankings, D1 is near the top of both lists — second lexically, first semantically — so it wins. D2 is first lexically but missing from the semantic list, so it falls below D3, which sits in the middle of both lists. RRF rewards agreement between systems more than a single top position.
The constant k decides how much rank position matters. With a small k the first place is worth much more than the second; with a large k positions count almost equally and documents found by more systems win. 60 is the value from the original paper and a common default.
Rules this implementation follows
- Ranks start at 1; a document missing from a ranking contributes 0.
- k must be a finite number greater than 0; anything else is rejected, not clamped.
- A repeated id inside one ranking keeps its first (best) position and produces a warning.
- Equal scores are ordered by document id, so the result never depends on input order.
How NexusRAG differs
NexusRAG's deployed gateway does not call a pure RRF function. It blends rank contributions with a dense weight α and adds a small bonus for lexical term coverage. Tick “Compare” above to see where the two orders agree and where they part.
Evidence for the NexusRAG comparison2 sources
- Repository documentedInspected source code
Gateway retrieval blends rank-based contributions from dense (Qdrant) and lexical term-coverage lists: α·dense + (1−α)·(lexical + 0.02·coverage), α = 0.6 by default.
const rankingScore = (item) => (semanticWeight * item.dense_rrf) + ((1 - semanticWeight) * (item.lexical_rrf + (0.02 * (item.lexical_score || 0))));
- Lexical scoring in the gateway is term coverage, not BM25.
- A pure RRF library exists in packages/retrieval/src/fusion.ts but the gateway does not call it.
- Retrieval quality of this blend is not established by implementation alone.
apps/gateway/src/worker-lifecycle.js (opens in a new tab) @ 85b14f1 · reviewed 2026-10-25 · In the ledger
- Repository documentedRepository documentation
The Python research path includes BM25 + vector hybrid retrieval with RRF, cross-encoder reranking, semantic and hierarchical chunking, contextual enrichment, semantic cache, multi-query expansion, adaptive K and OCR with a circuit breaker.
The following features describe optional Python implementations, not production acceptance or the bounded gateway's capabilities.
- Not enabled in the bounded gateway.
- Optional contextual enrichment does not by itself establish improved answer quality (README line 15).
README.md; backend/src/retrieval/reranker.py (opens in a new tab) @ 85b14f1 · reviewed 2026-10-25 · In the ledger