BM25, the formula everything is measured against
- : how often term occurs in document .
- : the document length, and the average length.
- : the saturation parameter, usually 1.2 to 2.0.
- : the length normalisation, usually 0.75.
Every part of that expression is a correction to counting words, and each one earns its place.
A term appearing in almost every document tells you nothing, so its weight falls towards zero.
The two corrections that make it work
Term frequency saturates. The fifth occurrence of a word adds far less than the second, which stops a document from winning by repetition alone.
Longer documents contain more of everything, so the count is divided by length relative to the average, with controlling how aggressively.
Set too high and short documents dominate. Too low and a long document wins every query by accident of size.
Why it is fast
A term maps to the list of documents containing it, so a query touches only the documents that share a word with it rather than the whole corpus.
Rare terms have short lists, and rare terms are the ones with high IDF, so the expensive part of the query is also the least useful part.
Skipping and early termination exploit exactly that, which is how a keyword index answers over a billion documents in milliseconds.
One query, in order
- Tokenise the query with the same analyser used at indexing time.
- Look up the posting list for each term.
- Accumulate the BM25 contribution of each term into each candidate document.
- Keep the top by total score.
- Return them, with the matched terms available for highlighting.
Learned sparse retrieval
SPLADE and similar models predict a weight for every vocabulary term rather than counting occurrences, so a document can be given weight on a word it never contains.
That adds the synonym matching dense retrieval has, while keeping the inverted index and its exact-match behaviour.
An L1 penalty keeps the output sparse, because a dense vector over 30,000 terms would destroy the whole reason for using an inverted index.
The result sits between the two families: better than BM25 on paraphrase, worse than a good bi-encoder on meaning, and far cheaper to serve than either at scale.