Search & IR · core
BM25
The standard lexical ranking function: TF saturation + IDF + length normalization.
Mental model
BM25 fixes TF-IDF's two flaws: term frequency saturates (the 10th occurrence adds little via the k1 parameter) and document length is normalized (the b parameter). It is still the strongest single keyword ranker and the lexical half of hybrid search.
How to study BM25
Begin by restating the mental model in your own words, then connect it to a concrete system you have built or operated. Name the mechanism, the constraint it addresses, and the trade-off it introduces. Use Okapi BM25 (Wikipedia), Elastic — Practical BM25 Part 2: The BM25 Algorithm and its Variables to check details, but close the source before writing your explanation. Retrieval is the learning step; rereading is only preparation.
Next, compare BM25 with Hybrid Search, Search Evals, Reranking. Ask what changes in correctness, latency, resource use, operability, and failure recovery. Complete Calculate a BM25 score by hand, Implement a BM25 ranker and preserve the command, input, output, and one failed attempt as evidence. Finish by explaining the idea without jargon to someone who has not studied the track.
Proof of understanding
- Explain the mechanism from first principles and identify the state it reads or changes.
- Give one situation where the concept is the right choice and one where it is not.
- Predict a realistic failure mode before running the drill, then compare the prediction with evidence.
- Connect the result to a roadmap or build artifact instead of treating the concept as isolated trivia.
Where it matters
Default scorer in Elasticsearch, OpenSearch, Lucene, Tantivy; lexical leg of hybrid retrieval.
Common mistakes
- Believing embeddings make BM25 obsolete — they are complementary
- Leaving k1/b at defaults without tuning on your corpus
- Skipping document length normalization
- Not building search evals to compare against vector retrieval
Learn from primary sources
Practice and explain it back
Calculate a BM25 score by hand
Given tf, df, N, document length, average document length, k1=1.2 and b=0.75, compute the BM25 score of a query term for a document.
Expected evidence: A numeric score; verify TF saturation by checking the 10th occurrence adds little.
Open the interactive drill →Implement a BM25 ranker
On top of your inverted index, implement BM25 scoring and return the top-k documents for a multi-term query.
Expected evidence: Ranked top-k results for a query, scored by summed per-term BM25.
Open the interactive drill →Review prompts
- Why does BM25 normalize by document length?
- How is BM25 different from TF-IDF?
- When can BM25 outperform embedding-based retrieval?
- How would you combine BM25 and vector search?
Build evidence
Implement BM25 search in HighSignal
Index a corpus of articles and serve ranked keyword search using BM25.
- Index at least 100 documents
- Support keyword search with a tokenizer shared by index and query
- Return top-k ranked results scored by BM25
- Add a small set of eval queries with expected results
Hybrid search v0 in HighSignal
Combine BM25 and vector retrieval with reciprocal rank fusion.
- Run BM25 and vector retrieval over the same corpus
- Fuse results with reciprocal rank fusion
- Beat both single retrievers on the search eval set