Data & Retrieval

BM25

also: keyword search · lexical search

The classic keyword-ranking function — still the baseline every fancy retriever must beat.

BM25 scores documents by term frequency (saturating, so the 10th occurrence adds little), inverse document frequency (rare terms count more), and length normalization. Decades old, no training, and still embarrassingly competitive — exact identifiers, names and codes that embeddings blur, BM25 nails. That is why production retrieval is usually hybrid: BM25 + vectors, fused.

Worked example: for the query ‘python asyncio TimeoutError’, BM25 scores documents by how often those exact terms appear, weighting the rare term (TimeoutError) far above the common one (python) and dampening very long documents. Gotcha: it is unbeatable for exact identifiers and codes but blind to paraphrase — it will not match ‘coroutine timed out’ to ‘TimeoutError’, which is why hybrid search pairs it with embeddings.