The Search Odyssey
In progress
Module 4Turn matching into ordering Ranker

Ranking with TF-IDF and BM25

Move from binary matching to probabilistic ranking. Understand why TF-IDF fails on term repetition and long documents, and how Okapi BM25 uses saturation (k1) and length normalization (b) to produce sensible orderings.

Term frequencyInverse document frequencySaturationLength normalizationBM25k1bField boosting

The stumper

A long, keyword-stuffed document outranks the perfect short answer. How does BM25 prevent this?

Boolean retrieval tells you if a document matches, but not what to read first. Users care about ordering - position 1 gets most clicks. Ranking is essential.

TF counts how often a term appears: more occurrences seems better. But a 10,000-word document will have more occurrences than a 200-word answer purely by length, and repeating terms gives unbounded benefit. TF-IDF helps by downweighting common terms (high document frequency) and upweighting rare terms.

Still, TF-IDF is linear in term frequency and handles length poorly. Okapi BM25 adds non-linear saturation so additional occurrences have diminishing returns, and length normalization so a short document where query terms are concentrated can outrank a long document.

The parameters give the engine its personality: k1 controls saturation speed, b controls how aggressively we normalize for length.

Try it before you read on

Open the Lab tab. Change a parameter, break something, and form a hypothesis before reading the explanation.

Checkpoint

3 questions. Explanations appear after submission.

1. What does IDF do?

2. What does the b parameter control in BM25?

3. Why is saturation useful?