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.
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
- What Fuzzy Matching Is, and Where It Fits in SEO MLforSEO
- How modern search actually works: the five-stage retrieval funnel MLforSEO
- The Probabilistic Relevance Framework: BM25 and Beyond (Robertson and Zaragoza, 2009)
- Practical BM25, Part 2: The BM25 Algorithm and its Variables (Elastic)
- Similarity module (Elasticsearch reference)
Other terms from ML Models & Algorithms
- BERT (Bidirectional Encoder Representations from Transformers)Google's 2018 transformer language model that reads text in both directions to produce context-aware embedding…
- BERTopicA modular topic modelling technique that clusters transformer embeddings and labels each cluster with class-ba…
- BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies)BIRCH (Balanced Iterative Reducing and Clustering using Hierarchies) clusters very large numeric datasets by s…
- Boyer-MooreA fast exact string-search algorithm that compares a pattern from right to left and skips ahead after mismatch…
- c-TF-IDFClass-based TF-IDF: treats each cluster as one document to find the words that best describe it, used by BERTo…
- Centroid-based ClusteringA clustering family that groups data around central points (centroids), each the average of its cluster's memb…
- Convolutional Neural Network (CNN)A deep learning architecture that scans data with small learned filters to detect local patterns; the classic…
- DBSCANDensity-based clustering that groups closely packed points, finds the number of clusters itself and labels iso…
- Decision TreeA supervised model that predicts by asking a series of yes/no questions about the data, branching like a flowc…
