What is BM25?
BM25 ranks documents by how often query words appear, how rare they are and how long the document is. Elasticsearch uses it by default.
In short. BM25 is a ranking function for keyword search that scores how well a document matches the words of a query. The score rises when a query word appears often in the document and rarely in the collection, with limits for repetition and document length. Elasticsearch uses it by default. Retrieval-augmented systems such as Anthropic's Contextual Retrieval combine it with embeddings to find exact terms.
On this page 7 sections
The evidence
BM25 comes from the probabilistic relevance framework, a model of document retrieval grounded in research from the 1970s and 1980s.1
1Foundations and Trends in Information RetrievalFoundations and Trends in Information Retrieval, 2009.Elasticsearch uses BM25 as its default similarity, with the parameter k1 set to 1.2 and b set to 0.75.3
3Elasticsearch referenceElasticsearch reference. Checked Nov 20, 2026.Azure AI Search uses BM25 on every search service created after July 2020. BM25 scores full-text search only, and filters, autocomplete, wildcard and fuzzy queries are not scored.4
4Microsoft LearnMicrosoft Learn. Checked Nov 20, 2026.BM25 sets the order of keyword search results in engines such as Elasticsearch, and AI retrieval systems still run it to catch exact product names and technical terms. In Anthropic's tests, contextual BM25 combined with contextual embeddings cut the top-20 retrieval failure rate by 49%.
The formula gives each document that matches a query a score from the query words it contains. The highest-scoring documents appear first.
#How BM25 scores a document
Introduction to Information Retrieval, a Cambridge University Press textbook, builds the BM25 score from three parts for each query word:2
- A word that appears in few documents of the collection gets a higher weight. This part is the inverse document frequency.
- Each extra occurrence of the word in a document raises the score, which is the term frequency part. The parameter k1 sets how fast this gain levels off.
- The score is adjusted for a document that is longer or shorter than average. The parameter b sets how much.
The textbook says a k1 of 0 ignores term frequency, and a large k1 uses the raw count. A b of 1 fully scales the score by document length, and a b of 0 does no length scaling. For a system without tuning, it says experiments have shown that a k1 between 1.2 and 2 and a b of 0.75 are reasonable.2
Anthropic's post on Contextual Retrieval describes BM25 as a refinement of TF-IDF. It considers document length and applies a saturation function to term frequency, which helps prevent common words from dominating the results.6
#Origin
BM25 grew out of decades of information retrieval research. The Probabilistic Relevance Framework: BM25 and Beyond, a 2009 monograph on the framework, says the framework is grounded in work from the 1970s and 1980s. It calls BM25 one of the most successful text retrieval algorithms. BM25F, a later extension, also takes document structure and link information into account.1
The textbook says BM25 is often called Okapi weighting, after the system in which it was first implemented. Its strong results in the TREC evaluations led to wide adoption.2
#BM25 in search engines
Elasticsearch and Azure AI Search use BM25 as their standard ranking for text. The Elasticsearch similarity settings list BM25 as the default similarity, with k1 set to 1.2 and b set to 0.75.3
Microsoft's page on BM25 scoring in Azure AI Search says BM25 is the fixed algorithm on all search services created after July 2020. Microsoft says it favors documents that contain many instances of the search term, and that it scores higher when the term is rare across the index. BM25 applies to full-text search only.4
A keyword search engine stores an inverted index, a list of the documents that contain each word, and BM25 scores the matches. Because BM25 matches words, it cannot find a document that uses other words for the same meaning. What is semantic search? compares keyword search with search by embeddings.
#BM25 in AI search and RAG
Retrieval systems for AI answers often run BM25 next to vector search. Anthropic says embedding models can miss exact matches, and that BM25 is particularly effective for queries with unique identifiers or technical terms. In its tests, combining contextual BM25 with contextual embeddings cut the top-20 retrieval failure rate by 49%, from 5.7% to 2.9%.6
Microsoft's documentation of hybrid search describes the same pattern. One request runs full-text search, ranked with BM25, and vector search in parallel. Reciprocal Rank Fusion merges the two result lists into one.5 A reranker can then reorder the top results.
BM25 remains a strong baseline in research. The BEIR benchmark tested 10 retrieval systems on 18 datasets and found that BM25 held up well across them. Dense retrieval models were more efficient than reranking models but often performed worse on data they were not trained for.7
A page reaches a BM25 result list only through the words it contains. Writing exact product names, codes and technical terms into the text gives keyword retrieval something to match directly. What is retrieval-augmented generation (RAG)? covers where keyword retrieval fits in an AI answer.
Read next
AI search
What is semantic search and how does it differ from keyword search?
Semantic search matches the meaning of a query, often with vector embeddings. Keyword search matches its words. Hybrid search runs both and merges the results.
AI search
What is retrieval-augmented generation (RAG)?
RAG retrieves documents at query time and gives them to a language model to write a cited answer. How ChatGPT, Claude, Google, Bing and Perplexity use it.
LLMs
What are vector embeddings?
A vector embedding is a list of numbers that represents the meaning of text. OpenAI's text-embedding-3-large returns 3,072 of them by default.
AI search
How does AI search choose which sources to cite?
AI search retrieves pages from an index, reads passages and cites what it used. What OpenAI, Anthropic, Google, Microsoft and Perplexity document.
Questions
What does BM25 stand for?
BM stands for best match. Anthropic's post on Contextual Retrieval writes it as Best Matching 25. The function is often called Okapi BM25, after the Okapi retrieval system in which it was first implemented.
How is BM25 different from TF-IDF?
Both weight a word by how often it appears in a document and how rare it is in the collection. BM25 also accounts for document length and applies a saturation function to term frequency, which Anthropic says helps prevent common words from dominating the results.
Is BM25 still used with vector search?
Yes. Hybrid search runs a BM25 keyword query and a vector query together and merges the results. Azure AI Search does this with Reciprocal Rank Fusion, and Anthropic's Contextual Retrieval method combines BM25 with embeddings.
Notes
- 1
- 2
- 3
- 4
- 5
- 6
- 7
About this page
Researched and reviewed by Promptly Found. Reviewed Nov 20, 2026. Next review due Feb 2027.
Cite this page
Promptly Found. (2026, November 20). What is BM25? https://promptlyfound.com/glossary/bm25
Revisions 1
- First published.