« Back

BM25 keyword ranking

brain/notes/bm25.md - updated 2026-11-18
Tags: concept, search, keyword-search, ranking - Similar notes

BM25 (Okapi BM25) is a classic ranking function that scores documents by how well their words match a query.

  • "BM" stands for "best matching." It treats documents as bags of words and ignores word order.
  • It comes from the probabilistic retrieval framework developed in the 1970s and 1980s by Stephen E. Robertson, Karen Spärck Jones and others. "Okapi" was the system at City University, London, that first used it.
  • Three ideas: term frequency (more matches score higher, with diminishing returns), inverse document frequency (rare words count more) and length normalization (long documents don't win just by being long).
  • Free parameters: k1 (typically 1.2 to 2.0) and b (typically 0.75).
  • It is fast and good at exact terms like names and codes, but it does not know synonyms. Pair it with embeddings in hybrid search.

Sources