MLGuerrillaStart M1 →
Embeddings and retrieval·16 min read·Updated 24 September 2026

BM25 and sparse retrieval

BM25 counts how many of your query's rare words a document contains and adjusts for length. It has no idea what any of them mean, and on the corpus behind this article it answered a question the embedding model got wrong.

BM25 is a scoring function. It takes a query and a document as input and returns a number for how well they match, computed from nothing but word counts. It came out of the Okapi retrieval work in the 1990s, and it is the ranking Elasticsearch still uses by default today.

The scoring rests on three observations about words. A word that appears in few documents tells you more than a word that appears in most of them. A document that uses a query word several times is a better match than one that uses it once, though the second use counts for less than the first. And a long document containing a word is less impressive than a short one containing it, so length gets divided out. The formula is those three ideas multiplied together and summed over the query's words.

What it is

It scores the words, and it never learned what they mean

Working through one real query makes the whole thing concrete. This is the same question and the same 287 passages the text embeddings article searches, with BM25 in place of the embedding model.

A figure titled "BM25 scores the words, and it has never heard of meaning", from one question run against 287 passages from this site. The question is "how do I train a classifier on my own labelled examples", and a note says stopwords are dropped and the eight words left are scored one at a time. The passage that won is from /models/bert, 43 words long, scoring 10.72, and reads "The second step is fine-tuning. You take the pretrained model, put one small output layer on top of it, and train it again on your own labeled examples. The BERT paper makes the point that this is ...". The runner-up, from /models/jev, scored 10.22. A table then shows where the score came from, word by word, with how many of the 287 passages contain it, its rarity, how many times it appears in this passage, and what it adds. The word how is in 40 passages, rarity 1.96, appears 0 times, adds 0.00. The word do is in 10 passages, rarity 3.31, appears once, adds 3.28. The word train is in 17 passages, rarity 2.80, appears once, adds 2.77. The word classifier is in 9 passages, rarity 3.41, appears 0 times, adds 0.00. The word my is in 8 passages, rarity 3.52, appears 0 times, adds 0.00. The word own is in 42 passages, rarity 1.91, appears once, adds 1.89. The word labelled, shown in terracotta, is in 0 passages, rarity 0.00, appears 0 times, adds 0.00. The word examples is in 17 passages, rarity 2.80, appears once, adds 2.77. Added up, the total is 10.72, and a note says three of the eight words scored nothing and the passage still won. A final panel headed "the word that mattered most scored zero" explains that labelled appears in 0 of the 287 passages because this site spells it labeled, that BM25 compares strings so the two are unrelated words, that classifier is in 9 passages and in none of this one so it added nothing either, and that the score came from do, train, own and examples. It closes by noting that an embedding model got this same question wrong, and it knows perfectly well that labelled and labeled are the same word. The caption reads: exact matching is the strength and the failure, and they are the same property.
The rarity column is the inverse document frequency, and it is why do at 3.31 outscores own at 1.91 even though both appear once here.

Two things in that run are worth sitting with.

The first is that BM25 got this question right. The embedding model put a YOLO passage about fine-tuning on labelled images first, because both passages are about training on your own labels and one vector has no room to keep them apart. BM25 had no such problem, because "fine-tuning" and "layer" are just different strings from "images" and "boxes".

The second is how it got there. Three of the eight scored words contributed nothing at all, and one of those was "labelled", the word carrying most of the question's meaning. This site spells it "labeled", and with the plain tokenizer this run used, those are two unrelated tokens. The right answer came back anyway, on the strength of four ordinary words. The analyzer section further down shows how a stemmer would have joined the two spellings.

Keep reading

The rest of this article is free with an account

Create a free account to read the remaining 6 sections. It takes about twenty seconds and there's nothing to pay. The same account opens the slide decks and CV reviews.

  1. 02Where BM25 shows up
  2. 03The formula, learned sparse retrieval, and how to merge two rankings
  3. 04What to run, as of September 2026
  4. 05Choosing, which usually means running two things
  5. 06How to try it
  6. and 1 more