CodeQuest101Advanced RAGChapter Studio
Advanced RAG

8 chapters · Learn by building

RAG basics

Chapter 03 / 08

Match words. Match meaning.

Combine dense and lexical result lists while keeping their different scoring scales separate.

The idea, in plain words

Merge ranks with RRF

One search may find the X200 product code; another may find the opened-packaging rule. Hybrid retrieval gathers candidates from both paths.

Reciprocal rank fusion, or RRF, combines each passage's positions in those lists. A passage found by both can receive contributions from both, without adding incompatible raw scores.

1

Send the same question through dense retrieval and BM25.

2

Keep each path's ranked list and source passage identifiers.

3

Add reciprocal-rank contributions for passages present in either list.

4

Sort the fused scores and inspect why a passage changed position.

Decision inspector

Why did this move up?

D1Eligibility
Dense rank 1cosine 0.598
Sparse rank 2BM25 6.267

Opened packaging is allowed, provided the item has not been used.

Opened packaging and returns · D1-s2

Dense: 1/(60 + 1) = 0.01639 + Sparse: 1/(60 + 2) = 0.01613 → 0.03252

Rank fusion can retain useful signals from different retrievers even when their raw score scales are unrelated.

Math & code

RRF(d) = Σ 1 / (60 + rank(d)); ranks start at 1. Missing entries contribute 0.

for list in ranked_lists:
  for rank, passage in enumerate(list, start=1):
    fused[passage.id] += 1 / (60 + rank)
Developer’s reasoning

A passage missing from one list contributes nothing from that list. A high fused rank still does not prove that its text answers the question.

Sources & model provenance

sentence-transformers/all-MiniLM-L6-v2 · 384D · mean pooling + L2 normalization.

cross-encoder/ms-marco-MiniLM-L6-v2 · recorded raw logits.

Rewrites, subquestions, HyDE text, and answer claims are authored teaching examples.

Encoder revision onnx-sha256:4f148ba8ae9c2c7fbee4af2b132db8d06c6a6545b47fc83bbb98c3d22b8393e6

Reranker revision 233902d25c440f23af6f7d6e94d2946bac0bee0a

Corpus SHA256 d1c21da297e88785f9a6ac434e0a58f3e10975052a48419ba511145d461f704e

Current sources only; archived documents D9 are excluded before retrieval.

Hybrid search · Merge ranks with RRF