AI GLOSSARY · AI CONCEPTS

BM25

Markdown version

Definition

BM25 (Best Matching 25) is a ranking function that scores documents against a query by lexical matching, meaning it looks for the query's actual words. It builds on TF-IDF and adjusts for document length and repeated terms.

Also called: BM25 algorithm, Okapi BM25, BM25 search, BM25 ranking, BM25 scoring.

In plain language

BM25 is the scoring rule behind classic keyword search. Given a search, it gives every document a score based on how many of your words it contains. Rare words count for more than common ones, a word that appears again and again stops adding much, and a short page is not unfairly beaten by a long one. Searching a help centre for the error code TS-999 is a good fit, because the exact string matters. The limit is that it matches words, not meaning. A search for car will not find a page that only says automobile. Many AI document-search systems therefore run it alongside a meaning-based search and merge the two result lists.

Technical definition

For each query term it multiplies an inverse document frequency weight, which rewards terms that are rare across the collection, by a saturating term-frequency component. Elastic's explainer describes the factors as term frequency, inverse document frequency and document length, with parameter k1 limiting how much one term can affect a document's score and parameter b scaling the effect of document length. Elastic gives default values of b = 0.75 and k1 = 1.2. Anthropic's contextual retrieval post describes BM25 as building on TF-IDF and presents it as complementary to embeddings, combining the two with rank fusion. It also prepends chunk-specific context before building the BM25 index.

Worked examples in this catalogue

Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.

  1. Guide · Illustrative, not executed

    What Is RAG? Retrieval-Augmented Generation Explained

    What you see
    A walkthrough of indexing and querying for RAG, including how chunk boundaries affect what retrieval finds and a technique of adding a short context line to each chunk, which the guide credits to Anthropic's contextual retrieval write-up.
    Why it exercises the concept
    BM25 is one of the retrieval methods such pipelines use. The guide shows the chunking step that decides what any retriever, keyword or meaning-based, can find.
  2. Skill by Skill Almanac · Illustrative, not executed

    rag-chunking-planner 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    Your documents split by three chunking strategies, with defects and offline recall reported for each, so chunk settings are chosen with numbers.
    Why it exercises the concept
    BM25 scores the chunks you give it, so chunk size and boundaries change what it can match. This skill measures that step before you pick settings.
  3. Skill by Skill Almanac · Illustrative, not executed

    keyword-density-count 41/100 · Provisional, not yet measuredScored · Method v0.2 · How we score

    What you see
    Case-insensitive, whole-word counts of each keyword or phrase in plain page text, with density figures reported.
    Why it exercises the concept
    It shows raw term counts, the simplest ingredient of lexical scoring. It does not rank documents, weight rare words or adjust for length, which is what BM25 adds.

How it shows up when you use agents

If you build or use a document-search setup for an agent, BM25 is often the keyword half of it. An embedding search finds passages with similar meaning, and BM25 finds passages that contain the exact words, such as an error code, a function name or a product identifier. Anthropic's contextual retrieval post describes using both and merging the results. That combined approach is often called hybrid search, and it sits inside many retrieval-augmented generation pipelines, often followed by reranking.

Coding agents also search by exact text when they look through your repository, which is closer to keyword matching than to meaning-based search. That works well for names and strings and less well for questions phrased in different words from the code.

What breaks when BM25 is misunderstood: people expect it to understand synonyms and are surprised when a paraphrased question finds nothing, or they test only with exact-word queries and miss the failure. The next action is to test your retriever with questions that use different words from the documents, and to look at how chunking splits the text, since BM25 scores each chunk separately.

Common confusions

  • BM25 versus semantic search. BM25 matches the words in the query. Semantic search compares meaning using embeddings. Each can find things the other misses.
  • BM25 versus TF-IDF. BM25 builds on TF-IDF. According to Anthropic's post, it also accounts for document length and saturates term frequency so common words do not dominate.
  • BM25 versus a vector database. A vector database stores embeddings for similarity search. BM25 is a scoring formula over words and works without one.
  • Myth. Keyword search is obsolete once you have embeddings. Anthropic's post presents BM25 as complementary, because embeddings can miss exact matches.

Terms that mention BM25

5 terms mention this one

Guides that mention BM25

More in AI concepts

Next steps

  1. What Is RAG? Retrieval-Augmented Generation Explained The long-form guide.
  2. rag-chunking-planner A skill that exercises it.
  3. Retrieval-augmented generation (RAG) Related term.
  4. Reranking Related term.
  5. All glossary terms A to Z and by family.

Sources

Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-24. Wikipedia is never the only source.

Review record

Last verified

Drafted by claude-sonnet-5-5; sources and example targets checked by claude-haiku-5-5 source check; claude-sonnet-5-5 editor pass on 2026-11-24. Last verified .

This entry is still in review, so it is not listed in search engines yet.

Change log (2)
  • : First version.
  • : Verifier pass: dropped bag-of-words sentence.