← Back to concept explainers

Concept Fable

BM25

Conclusion first:BM25 is a classic keyword retrieval ranking algorithm, commonly used in search engines and sparse retrieval for RAG. It judges document-query relevance based on term frequency, inverse document frequency, and document length normalization. BM25 excels at literal matching problems such as proper nouns, IDs, precise terminology, and regulatory clauses. Even after vector retrieval became popular, BM25 is still often combined with semantic retrieval to form hybrid search, compensating for vector retrieval's instability with exact and rare terms.

BM25 · Retrieval

Read the story first. There is no rush to give a definition here; let the question grow on its own first.

Fable

The old indexer weighed the words

The city archive first searched for files by looking only for the same word. When a reader asked about "bridge tax," the copyist brought every file containing "bridge" or "tax." The table was soon piled with paper, much of which merely mentioned it in passing.

The curator realized that a word appearing does not mean it is important. A volume on the East Bridge tax system that repeatedly mentions the bridge tax is of course relevant; a travelogue that only says 'passed by the bridge and paid the tax' should not be ranked at the top.

The old indexer began weighing words. He first counted how many times a word appeared in a certain file. Appearing more often meant the file might be more relevant. But he soon discovered that overly long files naturally tended to contain more words, so he could not reward by count alone.

So he also looked at how rare the word was in the entire archive. Words like "of" and "in the city" are everywhere and have almost no discriminating power; rare words like "bridge tax reduction decree" are very valuable once they appear.

There was another problem: a word appearing one hundred times is not necessarily ten times better than appearing ten times. The old indexer set a cap on repeated occurrences, to prevent a document from pushing itself to the front by piling up words.

Later, when a reader asked about 'East Bridge tax relief,' the indexer no longer just fetched all files containing those words, but considered comprehensively: whether these words appear often enough in the text, whether they are rare enough across the whole library, whether this file's length is reasonable, and whether repeated occurrences have already saturated.

The young man asked him: Isn't this a very old method? The old indexer said: Old doesn't mean useless. As long as the question contains a clear name, number, term, or clause, use the literal clues first—it's often more reliable than guessing at meaning.

Later the archive got a new map for finding books by meaning, but the old indexer still didn't retire. He worked alongside the new map: one caught exact words, the other caught similar meanings. Only then did the curator understand: in complex retrieval, literal matching isn't backward—it's a stable nail. Without it, many proper names and clauses would drift away. When encountering obscure place names, draft bank names or statute names, the new map often took a long detour, while the old indexer could grab them in one go. The archive later used it first to pin down the explicit clues, then let other methods fill in the meaning.

Reveal

This story is about: BM25

BM25 is a classic keyword retrieval ranking algorithm, commonly used in search engines and sparse retrieval for RAG. It judges document-query relevance based on term frequency, inverse document frequency, and document length normalization. BM25 excels at literal matching problems such as proper nouns, IDs, precise terminology, and regulatory clauses. Even after vector retrieval became popular, BM25 is still often combined with semantic retrieval to form hybrid search, compensating for vector retrieval's instability with exact and rare terms.

What matters is that it is not just a term, but a structural problem that repeatedly appears in real AI / Agent systems. Understanding it lets you judge when to add a model, when to change a process, and when to add governance.

Metaphor mapping

  • Only checking whether the same word appears: the most basic keyword matching
  • A word appearing does not mean it is important: retrieval needs ranking, not just filtering
  • How many times a word appears in a file: term frequency TF
  • How rare this word is across the whole library: inverse document frequency, IDF, rare words are more discriminative
  • Long dossiers naturally have more words: document length normalization
  • Set a cap on repeated occurrences: the term-frequency saturation idea behind BM25
  • Clear names, numbers, terminology, clauses: BM25's strong scenarios
  • Working with the new map: BM25 is often combined with vector retrieval into hybrid search

Andy Ren Xu's judgment

The practical value of this concept is that it helps you break "AI features that look smart" into deliverable, verifiable, and governable units of work.

sparse retrievallexical search

Related distinctions

This concept is easily confused with adjacent concepts; it is recommended to continue to the comparison page.

京ICP备2026014272号