What Is BM25?
BM25 is a ranking function that scores how well a document matches a keyword query. It reads three quantities and nothing else: how often each query term occurs in the document, how many documents in the collection contain that term, and how long the document is compared with the collection average. No meaning is involved at any point, and that is a design property rather than an omission.
The three quantities, and what the two parameters do to them
A BM25 score is a sum with one addend per query term, and each addend multiplies two factors together. The first is an inverse document frequency weight, which rises as fewer documents in the collection contain the term: a term present in almost every document contributes almost nothing, and a rare one carries most of the score. The second is a saturating function of how often the term occurs in this document, divided by a correction for the document's length. A query term the document does not contain adds zero, and a document is never penalised for containing something the query did not ask about.
Saturation is the property that separates BM25 from counting occurrences, and it is the part most often described wrongly. The frequency factor has the shape of a quantity divided by itself plus a constant: it climbs steeply over the first few occurrences and then flattens, approaching a ceiling however many more arrive. A document mentioning a term forty times scores above one mentioning it four times, but only slightly, and never ten times as high. The parameter written k1 sets how fast that flattening happens — a low value collapses towards a presence-or-absence test after the first occurrence, a high value keeps the response closer to a straight count.
Length normalisation is the second parameter and it settles a different question: whether a long document is relevant or merely large. The correction divides by the document's length relative to the average length across the collection, scaled by a parameter written b. At b = 0 length is ignored entirely and long documents accumulate score simply by containing more words; at b = 1 the correction applies in full, and a document twice the average length has to repeat a term proportionally more often to match what a shorter neighbour scores. Implementations commonly ship k1 near 1.2 and b near 0.75. Both are tuning values rather than constants of the method, and the pair that suits a collection is found by measuring on it.
| Input | Effect on the score |
|---|---|
| Term frequency | Raises the score with diminishing returns. Each additional occurrence adds less than the one before it. |
| Document frequency | Lowers the weight of a term found in many documents. A term in nearly every document is worth close to nothing. |
| Document length | Discounts a match in a document longer than the collection average, in the proportion set by b. |
| k1 | Sets how quickly the frequency contribution saturates. Lower saturates sooner. |
| b | Sets how far the length discount is applied. Zero ignores length; one applies it fully. |
Two things follow from that list, and both surprise readers who expect a score to be a property of a document. A BM25 score depends on the collection, because two of the quantities it reads are collection statistics rather than document ones — so the same document and the same query return a different number once unrelated documents are indexed, and a threshold tuned on one corpus means nothing on another. And the scores are not calibrated: they are unbounded above and dependable only for ordering within one query's results, never for comparison between queries.
What the function has no way of knowing
BM25 matches terms after an analysis step that it does not itself define. Whatever the indexing pipeline did — lowercasing, stripping punctuation, dropping stopwords, reducing words to stems — decides what counts as the same term, and two deployments that disagree about stemming disagree about what BM25 is scoring even with identical parameters. The arithmetic is exact and it is applied to whatever the analyser handed over.
Because the evidence is term overlap, a query and a passage that use different words for the same idea score nothing against one another, and no parameter setting repairs that. The complementary property is why the function has outlived every announcement of its retirement: an exact identifier, a part number, a rare surname or a quoted error string matches exactly, and its rarity makes it dominate the score. Those are the queries where ranking by distance in an embedding space is weakest, which is the practical argument for running both channels rather than choosing between them.
One arithmetic detail deserves stating because it produces a real defect rather than a theoretical one. The classical form of the inverse document frequency weight turns negative once a term appears in more than half the collection, so a document can lose score for containing a query term. Implementations generally avoid this by adding a constant inside the logarithm, flooring the weight at zero instead. That patch is a property of the particular library, not of BM25 as such, and it is one of the few places where two systems return different orderings from what is described as the same formula.
How the Registry classifies a keyword ranking task
Ranking a documentation corpus against a keyword query is filed as information retrieval in this registry's classification, and the reason is structural rather than editorial: a ranking function reorders a set that already existed and adds no member to it. Every document that could appear in the result was in the collection before the query was written, which is the property this class is defined by.
The Registry's canonical brief for this entry is filed as:
Rank a documentation corpus against a keyword query using term frequency and document length normalisation.
Submitted for assessment it is
classified as Information retrieval, and its wording is hashed once — to
8c3f7013a116e7c0…, the first sixteen of sixty-four hexadecimal
characters — with the wording itself never stored. The hash is what the derivation
reads.
That class's own page is /tasks/retrieval.
Classification is one of three inputs. The other two are the configuration submitted with the task, and the permanent chart derived from that configuration — fixed by the model name, the training cutoff and the temperature alone, and never reading the task at all. The same ascendant, ruling planet and harmony therefore appear on every assessment a given configuration receives, whatever it was asked to do. The derivation is published in full at /method.
What this page does not claim about bm25
No parameter pair is recommended here. k1 and b are tuned against a collection and a query mix and the canonical brief above fixes neither, nor does it fix the analysis chain that decides what will count as a matching term before any scoring happens. This registry has measured no ranking quality for any setting of them.
The Registry does not run this task, does not inspect any system's output for it, and validates no assessment it issues against what afterwards happens. What it does is compute — from a published method, for one submitted task and one submitted configuration — a verdict and a recommended execution window. It computes neither on this page.
Questions about bm25
- What is BM25?
- BM25 is a ranking function that scores a document against a keyword query from three quantities: how often each query term occurs in the document, how many documents in the collection contain that term, and the length of the document relative to the collection average. It is the default lexical ranking in several widely used search engines.
- What does the name Okapi BM25 mean?
- BM stands for best matching and 25 identifies the variant, one of a numbered series of weighting functions developed in the same line of work. Okapi was the retrieval system in which the function was first implemented, and the name stayed attached to it.
- What do the parameters k1 and b control?
- k1 controls how quickly the contribution of a term saturates as it occurs more often in one document. b controls how strongly a document longer than the collection average is discounted: at zero the length is ignored, at one the correction is applied in full.
- Why does the same document score differently after new documents are indexed?
- Because two of the quantities in the formula belong to the collection rather than to the document: how many documents contain each query term, and the average document length. Indexing more documents changes both, so scores drift even when neither the document nor the query has changed.
- Is BM25 obsolete now that vector retrieval exists?
- The two rank on different evidence. BM25 matches terms that are literally present, which is what an identifier, a code or a rare name requires; vector retrieval matches positions in an embedding space, which is what a paraphrase requires. Systems that need both commonly run both and fuse the results rather than replacing one with the other.
Related entries
Order an assessment for information retrieval tasks
The Registry issues a permanent, numbered task risk assessment for one submitted task and one submitted configuration. EUR 1.90 Standard, EUR 4.90 Extended, EUR 14.90 Full Chart, which adds the permanent chart. Assessments from EUR 1.90; machine-readable at /pricing.json.