AI Wisdom

BM25

A keyword-based ranking function scoring documents by term frequency weighted by inverse document frequency.

In this article

BM25 (Best Match 25) is the gold standard for keyword search, used by Elasticsearch, OpenSearch, Solr, and Lucene. It ranks documents by how often query terms appear (Term Frequency โ€” TF), weighted by how rare each term is across the corpus (Inverse Document Frequency โ€” IDF), with saturation to prevent high TF from dominating. Despite being decades old, BM25 remains highly competitive for exact-match retrieval and is indispensable in hybrid search pipelines alongside vector search. It requires no GPU and runs at millisecond latency.

What it means in practice

BM25 is not just vocabulary; it is a design handle. In AI engineering, this term usually appears when engineers are designing, reviewing, or troubleshooting real production flows rather than only naming the concept. It is most useful when search quality, context selection, recall, latency, and answer grounding need to be measured together.

Why engineers care

  • It gives teams a shared name for the behaviour, risk, or architecture choice being discussed.
  • It helps separate the goal from the implementation detail, so you can compare alternatives instead of copying a tool pattern blindly.
  • It creates a useful checklist for reviews: inputs, outputs, failure modes, ownership, cost, latency, and measurement.

Production watch-outs

Do not judge it by demo relevance alone. Track recall, precision, source freshness, chunk quality, failure cases, and the cost of retrieval plus generation.

Related context

Useful neighbouring concepts: Hybrid Search, Semantic Search, RAG, RRF.

Discussion

Sign in to share your feedback and join the discussion.