Definition
BM25 (Best Matching 25, often called Okapi BM25) is a ranking function that scores how relevant a document is to a keyword query, based on which query terms the document contains, how often, how rare those terms are across the collection, and how long the document is. It is the default relevance formula in widely used search engines such as Elasticsearch and remains the standard lexical component of modern AI retrieval pipelines.
BM25 came out of the Okapi search system at City University London. Stephen Robertson and Stephen Walker developed it for the TREC-3 evaluation in 1994, combining two earlier formulas (BM11 and BM15) into one, and published it in 1995. Robertson and Hugo Zaragoza later set out its theory in 'The Probabilistic Relevance Framework: BM25 and Beyond' (2009), which also describes BM25F, a variant that weights fields such as title and body differently.
The score combines three ideas:
- Term frequency with saturation. A term appearing more often raises the score, but each extra occurrence adds less; a parameter called k1 controls how quickly that happens.
- Inverse document frequency. Rare terms count more than common ones, so a match on 'TS-999' matters more than a match on 'error'.
- Length normalization. Long documents are not rewarded just for containing more words; a parameter called b controls how strongly length is corrected.
Elasticsearch uses BM25 as its default similarity with k1 = 1.2 and b = 0.75 (Elastic). Microsoft has described BM25 as the default ranker in Azure AI Search, with its Bing-derived semantic ranker applied on top of the BM25 results.
BM25 has lasted because it is fast, needs no training, and is hard to beat on exact matches. When the BEIR benchmark tested ten retrieval approaches on 18 datasets in 2021, BM25 proved a strong zero-shot baseline that many neural retrievers failed to beat outside their training domain (Thakur et al.). Its weakness is meaning: it does not know that 'car' and 'automobile' are related, which is why it is now usually paired with vector search in a hybrid search setup. Anthropic's 2024 Contextual Retrieval work went further and added chunk-level context before building the BM25 index, calling the result Contextual BM25. Reranker vendors still use BM25 as a reference first stage: Voyage AI reported in September 2026 that its rerank-3 model improved nDCG@10 by 20.33% over BM25 results alone.
The major AI search engines do not publish their retrieval formulas, so claims that a particular assistant 'uses BM25' should be treated as unverified. What is documented is the general pattern: lexical matching on an inverted index, alongside semantic retrieval, followed by reranking.
For GEO, BM25's persistence means exact wording still counts. A page that never uses the precise product name, plan name, model number or category term a model puts into its grounding queries gives lexical retrieval nothing to match. Use the terms buyers and models actually search for, consistently, in headings and body text, alongside the clear explanations that semantic retrieval rewards. Keyword stuffing does not help: saturation caps the benefit of repetition, and the later reranking stages judge whether the passage answers the question.
Examples of BM25
- A support search uses BM25 to surface the one article containing the exact error code 'TS-999', which an embedding-only search ranked below general troubleshooting pages.
- An Elasticsearch index for a legal archive keeps BM25 as its first-stage ranker and adds a semantic reranker on the top 100 results, instead of replacing keyword search entirely.
- A RAG system's evaluation shows BM25 alone finds the right passage for part-number queries 90% of the time, while vector search wins on natural-language questions, so the team fuses both.
- A SaaS company notices AI answers rarely cite its 'workflow automation' page because the page only says 'smart flows'; adding the category term buyers use brings the page into AI citations for those queries.
