BM25
Type three words into a search box and something has to decide which of a million documents answers them. The ranking function that has been hardest to beat at that job for decades is BM25.
Three ideas in one formula
A document's score for a query is the sum, over the query's terms, of a weight built from three observations:
- Term frequency saturates. The fifth occurrence of a word adds far less than the second, with the parameter k1 setting how quickly the curve flattens. Raw counts never saturate, which is why keyword stuffing beats them.
- Rare terms matter more, supplied by an IDF factor — matching pericardium is worth more than matching the.
- Long documents are discounted, since length alone makes a match likelier; b controls how hard document length is normalised against the collection average.
Where you meet it
BM25 is Lucene's default similarity, so it is what Elasticsearch and OpenSearch score with out of the box. It is the standard first-stage retriever feeding a reranker, and the baseline every dense retriever is measured against on MS MARCO and BEIR. Hybrid search blends its scores with embedding scores precisely because the two fail differently: BM25 nails a part number or a rare proper noun, dense retrieval handles paraphrase.
What it costs
It knows nothing about meaning. A document that answers the query in entirely different words scores zero — the vocabulary mismatch problem that dense retrieval was built to fix. And k1 and b are corpus-dependent knobs that are left at their defaults far more often than they are tuned.
BM25 ranks documents against a query by summing, per query term, a weight combining IDF, a saturating term frequency so repetition stops paying off, and a length normalisation that discounts long documents. Two parameters, k1 and b, set the saturation and the normalisation. It is Lucene's default scoring and the reference baseline for keyword retrieval, yet shares bag-of-words blindness: a document matching the query's meaning without its words scores zero.
Picture a librarian ranking books for your question. A book using your exact words is promising — but the tenth mention of a word tells her little more than the third, an unusual word like pericardium counts for far more than the, and a thousand-page book will contain your words by sheer accident, so she discounts it for bulk.
BM25 is that judgement written down as a formula. It powers the keyword side of most search boxes you have ever used, and it is remarkably good for something that never understands a word of what it ranks. Its limit is simple: if a document says exactly what you wanted in completely different words, BM25 will never find it.