DataOkapi BM25TF-IDFkeyword ranking

BM25

Definition

BM25 ranks documents for a query by summing, over the query terms, the inverse document frequency of each term multiplied by a saturating function of how often it appears in the document, normalised by document length.

In practice

It improves on raw TF-IDF in two ways: extra occurrences of a term count less and less (controlled by k1, often around 1.2), and long documents are penalised so they do not win just by containing more words (controlled by b, often 0.75). It is the default similarity in Lucene, Elasticsearch and OpenSearch and a cheap first ranking stage on every shard.

BM25 only knows exact terms after analysis, so it misses synonyms and paraphrases, which vector search handles better. In 2026 it remains a strong baseline and is commonly combined with embeddings in hybrid search, then refined by a re-ranker on the top few hundred candidates.

Example

For "postgres vacuum", a short page mentioning vacuum 5 times outscores a 10,000-word page mentioning it 8 times, and matches on the rarer vacuum count more than matches on postgres.