# 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.

Canonical: https://promptlyfound.com/glossary/bm25
Updated: 2026-11-20

## Short answer

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.

## Key findings

- BM25 comes from the probabilistic relevance framework, a model of document retrieval grounded in research from the 1970s and 1980s. [1]
- Elasticsearch uses BM25 as its default similarity, with the parameter k1 set to 1.2 and b set to 0.75. [3]
- 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]
- Across 18 datasets, the BEIR benchmark found that BM25 held up well as a baseline. Reranking and late-interaction models scored best on average, at high computational cost. [7]
- In Anthropic's tests, contextual embeddings cut the top-20 retrieval failure rate by 35%. Adding contextual BM25 cut it by 49%, from 5.7% to 2.9%. [6]

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](https://nlp.stanford.edu/IR-book/html/htmledition/okapi-bm25-a-non-binary-model-1.html), 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](https://www.anthropic.com/news/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](https://www.emerald.com/ftinr/article/4/1-2/1/1326508/The-Probabilistic-Relevance-Framework-BM25-and), 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](https://www.elastic.co/docs/reference/elasticsearch/index-settings/similarity) 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](https://learn.microsoft.com/en-us/azure/search/index-similarity-and-scoring) 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?](https://promptlyfound.com/ai-search/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](https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview) 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](https://promptlyfound.com/glossary/reranking) can then reorder the top results.

BM25 remains a strong baseline in research. The [BEIR benchmark](https://arxiv.org/abs/2104.08663) 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)?](https://promptlyfound.com/ai-search/rag) covers where keyword retrieval fits in an AI answer.

## Sources

1. The Probabilistic Relevance Framework: BM25 and Beyond. Foundations and Trends in Information Retrieval, 2009-09-17. https://www.emerald.com/ftinr/article/4/1-2/1/1326508/The-Probabilistic-Relevance-Framework-BM25-and
2. Okapi BM25: a non-binary model. Introduction to Information Retrieval, Cambridge University Press. https://nlp.stanford.edu/IR-book/html/htmledition/okapi-bm25-a-non-binary-model-1.html
3. Similarity settings. Elasticsearch reference. https://www.elastic.co/docs/reference/elasticsearch/index-settings/similarity
4. BM25 relevance scoring in Azure AI Search. Microsoft Learn. https://learn.microsoft.com/en-us/azure/search/index-similarity-and-scoring
5. Hybrid search using vectors and full-text search in Azure AI Search. Microsoft Learn. https://learn.microsoft.com/en-us/azure/search/hybrid-search-overview
6. Introducing Contextual Retrieval. Anthropic, 2024-09-19. https://www.anthropic.com/news/contextual-retrieval
7. BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models. arXiv, 2021-04-17. https://arxiv.org/abs/2104.08663

---

This is a plain-text copy of https://promptlyfound.com/glossary/bm25 from Promptly Found. The web page is the canonical version and includes the charts.
