BM25 (Best Matching 25) is a sparse term-frequency retrieval function that scores documents by TF, IDF, and length normalization; it pairs with dense embeddings in hybrid retrieval.
Picture an old-school librarian who scores every book by counting how often your search words appear inside it, downweights words that appear in almost every book (like the, and, of), and accounts for how long each book is so a giant encyclopedia doesn't beat a short article by sheer volume. That counting system is BM25. It's been around since the 1990s and is shockingly hard to beat for exact-match cases like rare names, product codes, and error strings. Modern systems usually run BM25 and a smart semantic search side by side and combine their answers.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Concept explanation~2 min read
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
BM25 is the algorithm that refuses to retire. It was published in the 1990s, predates the deep-learning era of NLP entirely, and yet remains a core component of every serious production RAG system in 2026. Understanding what it scores, why dense embeddings haven't replaced it, and how hybrid retrieval works is foundational to retrieval engineering.
This deep dive walks through the BM25 scoring formula, the inverted-index data structure, the exact-match failure mode of dense embeddings that BM25 covers, and the Reciprocal Rank Fusion pattern that combines the two into the modern hybrid-retrieval architecture.
The acronym and the family
BM25 stands for Best Matching 25. The 25 is a version number; it's the 25th formula in the Okapi BM family of probabilistic relevance ranking functions developed at City University London in the 1990s by Stephen Robertson, Karen Sparck Jones, and colleagues.
The earlier members of the family (BM1, BM11, BM15) experimented with different normalizations and combinations of term frequency and document length. BM25 is the formulation that combined all the lessons into a single ranking function and has held the throne as the strongest pure-sparse baseline for thirty years.
The theoretical foundation is the probabilistic relevance framework: rank documents by the probability of relevance given the query, using assumptions about term independence and a binary relevance model. The BM25 formula is the practical instantiation that performed best across the TREC evaluations of the 1990s and has held up across every retrieval benchmark since.
The family is still alive. Robertson and others have published BM25F (field-weighted BM25 for documents with structured fields like title, body, tags), BM25+ (with a floor on term-frequency contributions), and BM25L (alternative length normalization). BM25 itself remains the default.
Situations where this technique stops working.
2–4 min · Everything important, quickly.
Real products, models, and research that use this idea.
- Elasticsearch and OpenSearch implement BM25 as the default scoring function for full-text search queries.
- Anthropic's contextual retrieval architecture for Claude pairs BM25 with dense embeddings and a contextual chunk prefix to boost both retrievers.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhat's the difference between BM25 and TF-IDF, and why does it matter?
TF-IDF scores a document by raw TF times IDF, which gives unbounded score for very high frequency terms and ignores document length. BM25 adds term-frequency saturation (controlled by k_1) so the marginal value of additional occurrences drops off, and length normalization (controlled by b) so longer documents don't beat shorter ones by sheer mass. Both changes materially improve quality on real corpora.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Red flags & common mistakes
The phrases that signal junior thinking. Click to expand.
Treating BM25 as obsolete because dense embeddings exist. It's still strong at exact-token matching and the workhorse of hybrid retrieval, where BM25 + dense + RRF beats either alone.
60 second bullets to scan on the way to the call.
Primary sources. Browse if you want the original framing.
Same topic, related formats. Practice these next.