
BM25
BM25 is a mathematical formula that search engines use to decide which texts best match a search query. It evaluates how often the searched words appear in a text, how rare they are overall, and how long the text is.
Anyone who types a few words into a search box gets back a sorted list of results. Something has to decide which text ends up at the top and which lands on page three. BM25 is one of the best-known formulas for exactly this decision. It gives every text a score, and the highest score wins. The formula dates back to the 1990s and is still used in almost every piece of search software today. The name is an abbreviation for “Best Match 25” and reveals nothing about how it works — it was simply the 25th attempt by a group of researchers.
It’s important to note: BM25 does not understand language. The formula has no idea what “interest rates” means. It merely counts how words are distributed across texts. It is precisely this simplicity that is its strength.
Why an old formula refuses to disappear
BM25 is extremely fast and requires almost no computing power. A search across millions of documents runs in milliseconds on an ordinary server. Modern language models — that is, AI programs that understand text — require significantly more hardware for the same task. For many applications, that would simply be a waste.
There is also a practical advantage: BM25 doesn’t need to learn anything. The formula can be applied to a completely new set of data without first feeding it any examples. For specialized texts with rare terms, it is often even better than AI-based methods. BM25 finds part numbers, drug names, or legal statute references exactly, because they are simply character strings.
Its weakness is the flip side of this. Anyone searching for “car” will not find texts that only contain “automobile” or “vehicle.” The formula is blind to semantic similarity. That’s why it is nowadays often combined with AI-based search rather than being replaced by it.
The three signals behind the score
The first signal is word frequency. If a search term appears ten times in a text, that’s a stronger signal than appearing just once. However, the score doesn’t simply grow in proportion. There’s a big difference between one occurrence and three, but almost none between fifty and sixty. The formula deliberately flattens out so that text spam with endless word repetitions doesn’t win.
The second signal is how rare a word is across the entire dataset. In the query “the history of inflation,” the word “the” is worthless because it appears everywhere. “Inflation” carries almost all the information. BM25 therefore weights rare words heavily and common words lightly. This principle is called inverse document frequency.
The third signal is text length. A 300-page book inevitably contains any given search term more often than a short note does. That would be an unfair advantage. BM25 therefore compares the length of a text to the average length and scales down long texts accordingly. Two tuning parameters, known in technical terms as k1 and b, control how strongly these corrections take effect.
BM25 in search fields and AI systems
The formula is built into search software such as Elasticsearch, OpenSearch, and Lucene. These programs power the search fields of many online shops, news archives, and corporate wikis. If full-text search works on a company’s intranet, BM25 is often the default setting behind it.
In AI news, the term is usually encountered in connection with RAG. This stands for “Retrieval-Augmented Generation” and means: a chatbot first retrieves matching documents and then writes its answer based on them. For the retrieval step, many systems use BM25 together with an AI-based method. This combination is called hybrid search.
BM25 also serves as a benchmark in research. Anyone presenting a new search method must show that it beats BM25. Remarkably often, this only succeeds by a narrow margin or only on certain datasets. A formula from before the internet boom is thus still a serious contender.