BM25
BM25 is a ranking formula for keyword search. It scores each document by how often the query's words appear in it, giving more weight to rare words and less credit to long documents and repeated terms.
Also called: Okapi BM25, keyword search, lexical search
By Divya Sharma · Checked Nov 15, 2026 · How we review
BM25 is the standard keyword-ranking method in search engines such as Elasticsearch, OpenSearch and Lucene. It comes from the Okapi information-retrieval research and remains a strong baseline even against neural retrievers.
How it scores
For each query word, BM25 looks at three things. Term frequency: a word that appears more in a document counts for more, but with diminishing returns, so each extra mention adds less. Inverse document frequency: rare words such as "pgvector" count far more than common words such as "the". Document length: long documents are penalized a little, since they contain more words by chance. Two parameters, usually called k1 and b, control the first and third effects.
It is a bag-of-words method: word order and meaning are ignored.
Why it still matters for AI
BM25 needs no model, no GPU and no embedding step, and it handles product codes, names and error messages well. The BEIR benchmark found BM25 a robust baseline across many retrieval tasks. That is why most hybrid search setups pair BM25 with vector search.
Limits
BM25 cannot match synonyms or paraphrases: "car" will not find "automobile". Learned sparse retrieval models such as SPLADE keep the same index structure but add related terms, which addresses this gap.
Related terms
- Hybrid search
- Hybrid search runs a keyword search and a vector search on the same query and merges the two ranked lists, so results can match on exact words as well as on meaning.
- Sparse retrieval
- Sparse retrieval represents queries and documents as vectors over a vocabulary where most entries are zero and each non-zero entry is a word weight, so search can use fast inverted indexes like keyword search.
- Vector search
- Vector search finds items by comparing their embeddings to the embedding of a query and returning the closest ones, so results match on meaning rather than on shared keywords.
- Reranking
- Reranking is a second search step that takes a short list of candidate documents and reorders them by relevance to the query, using a more accurate but slower model than the first search.
- Retrieval metrics (recall@k, nDCG, MRR)
- Retrieval metrics score how well a search system returns relevant documents. Recall@k checks how many relevant items appear in the top k, nDCG rewards ranking them high, and MRR measures how early the first correct one appears.