ML Models & Algorithms

BM25

In shortA classic ranking function that scores documents by how often query words appear, adjusted for word rarity and document length.

Updated 24 Oct 2026· 2 min read

BM25 (Best Matching 25, also called Okapi BM25) is a ranking function used in search engines to estimate how relevant a document is to a query based on the words they share. It refines TF-IDF and has been the standard lexical baseline in Information Retrieval for decades. It is the default similarity in Elasticsearch, OpenSearch and Lucene-based search engines.

How it works

For each query word, BM25 combines three ideas and adds the results together:

  • Term frequency with saturation: more occurrences raise the score, but with diminishing returns. The tenth mention adds far less than the second. A parameter called k1 controls how quickly it saturates.
  • Inverse document frequency: rare words (“pgvector”) count more than common ones (“guide”).
  • Length normalisation: long documents naturally contain more words, so scores are adjusted against the average document length. A parameter called b controls how strongly.

Elasticsearch’s defaults are k1 = 1.2 and b = 0.75. Because BM25 treats text as a bag of words, it knows nothing about meaning: “car” and “automobile” are unrelated to it.

How it’s used in SEO and marketing

  • Understanding the lexical layer of modern retrieval. MLforSEO describes AI search as two layers at once: fuzzy and lexical matching (edit distance, n-grams, BM25) repairs messy input, while embeddings capture paraphrases and intent.
  • Hybrid search: many RAG systems combine BM25 with Vector Search and then re-rank, because BM25 excels at exact names, product codes and rare terms that embeddings blur.
  • Building site search or internal-link tools that need precise keyword matches.
  • As a quick baseline when testing a semantic matching approach.

Example

A user searches “XR-200 battery replacement”. A product support page that mentions “XR-200” several times scores highly with BM25, because the model code is rare across the site. A pure embedding search might rank a general battery guide higher. A hybrid system keeps both candidates and lets a re-ranker decide.

Limitations and things to watch

  • No understanding of synonyms, paraphrases or intent without extra steps such as query expansion.
  • Sensitive to tokenisation and language: stemming and stop-word choices change results.
  • It is a relevance estimate, not a full ranking system. Search engines combine it, or something like it, with many other signals.
  • Writing for BM25 by repeating keywords hits saturation quickly and reads badly.

Learn it on MLforSEO

Sources and further reading

Other terms from ML Models & Algorithms

See all 50 ML Models & Algorithms terms →