Retrieval

Hybrid Retrieval Visualised

One query, two searches, one result list. See BM25 and cosine search feed their rankings into reciprocal rank fusion.

There is a narrated film on this topic.Watch Vector search: HNSW, cosine similarity and BM25

Ready · 1 / 7

Query: NB-204

QueryBM25CosineRRFResults
BM25 Cosine RRF

One query. Two searches.

See exact-word retrieval and topic similarity work together, then combine their ranks.

BM25

Exact words

Cosine

Topic similarity

RRF joins the two ranked lists into one result.

Eight fictional UK business documents. BM25 uses their text; cosine uses hand-authored topic vectors. Each branch returns up to three candidates. RRF uses c = 60. Playback illustrates the steps, not measured timing.

Choose an example and press Play. BM25 looks for matching words. Cosine compares topic vectors. Both searches receive the same query, then reciprocal rank fusion (RRF) combines their rankings into one list.

The exact-identifier example shows why the searches complement each other: BM25 finds the right contract, while the topic vector also retrieves documents about related incidents. Different wording shows the opposite case: no exact words match, but the vector search still returns candidates. Combining lists can help, but does not guarantee relevance.

The demonstration uses eight fictional UK business documents. BM25 is computed from their text with k1 = 1.2 and b = 0.75, preserving identifiers such as NB-204 without stemming or stop-word removal. Cosine uses four hand-authored coordinates: incidents, billing, privacy and staff. These are teaching vectors, not model-generated embeddings. The 3D lanes separate the searches; their positions do not measure relevance. Playback illustrates the sequence, not service latency.

The maths

Reciprocal rank fusion
RRF(d)=L:dL1c+rankL(d)\operatorname{RRF}(d)=\sum_{L:d\in L}\frac{1}{c+\operatorname{rank}_L(d)}

This example keeps up to three candidates per search and fixes c at 60. A document receives 1 / (60 + rank) from each list containing it. Missing from a list means zero from that branch. Add these contributions, then sort by the total. Raw BM25 and cosine scores are not added.

Sources and model assumptions

Follow the original mechanism behind this explainer. The interactive examples identify their toy data and simplifying assumptions above.

Put it to work

Related terms

More visualisations

Building with language models?

These explainers come out of the work. If you want the same thinking applied to your own system, that is what I do.

See how I can help