Promptwatch Logo

BM25

BM25 is a keyword ranking function that scores documents by term frequency, term rarity and length. It remains the lexical half of most hybrid AI retrieval.
Updated October 15, 2026
AI

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.

Terms related to BM25

Hybrid Search

Hybrid search runs keyword and vector retrieval together and merges the results, so a system matches exact terms and meaning at once. AI search engines use it.

AI

Vector Search

Vector search finds content by comparing embedding vectors, returning items closest in meaning to a query. It is the semantic half of AI search retrieval.

AI

Reranking

Reranking is the second retrieval stage, where a precise model rescores candidate passages so only the most relevant few reach the LLM that writes the answer.

AI

Semantic Search

Semantic search returns results that match the meaning and intent of a query, not just its words, using language models, embeddings and entity understanding.

SEO

Embeddings

Embeddings are numeric vectors that represent the meaning of text, images or other data, so AI systems can compare content by meaning. They power vector search.

AI

Grounding Queries

Grounding queries are the search queries an AI model writes and runs to find sources for an answer. They decide which pages it reads and can cite.

AI

Retrieval Evaluation

Retrieval evaluation measures whether a search or AI system finds the right documents and passages for a query, before judging the answer written from them.

Analytics

Passage Ranking

Passage ranking is Google's system for ranking a page on the strength of one relevant passage, live since 2021, and the passage-level scoring used by AI search.

SEO

Retrieval-Augmented Generation (RAG)

Retrieval-augmented generation is a technique that pairs a language model with a retriever, so each answer is written from documents fetched for that query.

AI

Frequently Asked Questions about BM25

Learn about AI visibility monitoring and how Promptwatch helps your brand succeed in AI search.

BM25 estimates how relevant a document is to a keyword query. It rewards documents that contain the query terms, with diminishing returns for repeated terms, gives more weight to rare terms than common ones, and adjusts for document length so long pages are not favored simply for being long. Two parameters, k1 and b, tune the saturation and length effects.

Be the brand AI recommends

Monitor your brand's visibility across ChatGPT, Claude, Perplexity, and Gemini. Get actionable insights and create content that gets cited by AI search engines.

Promptwatch Dashboard