RAG & Retrieval·Question 12 of 100Basic

What does BM25 actually compute? Walk me through the formula's moving parts.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

BM25 scores a document by summing, over each query term, three factors: an IDF weight, a saturating term-frequency contribution, and a length normalization.

Full worked answer

BM25 scores a document by summing, over each query term, three factors: an IDF weight, a saturating term-frequency contribution, and a length normalization.

IDF weights rare terms higher. A term appearing in 5 of 10 million documents carries far more signal than 'the'. This is what makes BM25 good at error codes, SKUs and surnames.

Term frequency with saturation is the key improvement over naive TF-IDF. Raw TF is linear: 20 occurrences look 20 times better than one. BM25 pushes TF through tf / (tf + k1 * (...)), which saturates, so the jump from 1 to 2 occurrences matters a lot and 20 to 21 barely registers. k1 (typically ~1.2 to 2.0) controls how fast it saturates. This is exactly right for relevance: a document mentioning your term once is very different from never, a document mentioning it 50 times is probably not 50 times better.

Length normalization divides by document length relative to the corpus average, controlled by b (typically ~0.75). Without it, long documents win everything by accident. b=0 disables it, b=1 normalizes fully.

So: rare terms count more, repetition has diminishing returns, and long documents get discounted.

What candidates miss is that BM25 is purely lexical. It has no idea 'car' and 'automobile' are related, which is precisely why you pair it with dense retrieval. It also depends heavily on the analyzer: tokenization, stemming, stopwords and case folding. Getting the analyzer wrong on a jargon-heavy corpus quietly destroys BM25 quality, and people blame the algorithm.

What a good answer covers

  • BM25 scores a document by summing, over each query term, three factors
  • A term appearing in 5 of 10 million documents carries far more signal than 'the'
  • This is what makes BM25 good at error codes, SKUs and surnames
  • Term frequency with saturation is the key improvement over naive TF-IDF
  • Raw TF is linear: 20 occurrences look 20 times better than one

Key terms: IDF · Term frequency with saturation · Length normalization

Interviewer follow-ups to expect

  1. How would you tune k1 and b for a corpus of very short documents like support ticket titles?

  2. Why does BM25 need no training while a dense retriever does?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep