Zenaique

What does BM25 stand for and what does it score?

Flashcard·Easy·4.0 · 0·~30s·Asked atDifyLinkedinSambanova·Relevant atElasticHugging FaceNeo4jQdrant
Attempt it
TL;DR

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.

Memory aid
Sign in to see the mnemonic that makes this stick.
Easy to grasp

Picture an old-school librarian who scores every book by counting how often your search words appear inside it. The librarian downweights words that appear in almost every book (like the, and, of). The librarian also 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 still very 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.

Key concepts

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 an old algorithm that is still widely used. It was published in the 1990s and predates the deep-learning era of NLP. Yet it remains a core component of many production RAG systems. Understanding what it scores, why dense embeddings haven't replaced it, and how hybrid retrieval works is foundational to retrieval engineering.

BM25 applies a scoring formula over an inverted-index data structure. It covers the exact-match failure mode of dense embeddings, and Reciprocal Rank Fusion 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: BM25 is the variant numbered 25 in the Okapi BM family of probabilistic relevance ranking functions. Stephen Robertson, Karen Sparck Jones, and colleagues developed the family at City University London in the 1990s.

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. It has stayed 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. It assumes term independence and a binary relevance model. The BM25 formula is the practical form that performed best in the TREC evaluations of the 1990s, and it has stayed a strong baseline 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.

The scoring formula in detail
The inverted-index data structure
Where BM25 outperforms dense embeddings
Hybrid retrieval and Reciprocal Rank Fusion
Sign in to unlock the full deep dive.

Situations where this technique stops working.

Sign in to see when this approach fails.

2–4 min · Everything important, quickly.

Sign in to see the quick scan of the deep dive.

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.
Sign in to see more production examples.

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?
A

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.

2 more follow-ups an interviewer would ask next. Sign in to reveal them.

Red flags & common mistakes

The phrases that signal junior thinking. Click to expand.

Most common mistake

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.

Sign in to see all red flags and common mistakes.

60 second bullets to scan on the way to the call.

  • BM25 acronym expansion (Best Matching 25)

  • Three scoring factors (TF, IDF, length normalization)

Sign in to unlock the revision sheet.

Primary sources. Browse if you want the original framing.

Similar questions

Same topic, related formats. Practice these next.

4 curated
Next question
Why is cosine similarity preferred over Euclidean distance for text embeddings?
Flashcard·Easy