RAG & Retrieval · Ground answers in evidence

How does BM25 scoring work?

Mediumbm25lexical searchrankingUpdated Oct 2026
Quiz this track

Short answer

BM25 scores documents by query-term frequency, adjusted for term rarity and document length. It rewards exact matches and is strong for names, codes and rare words.

BM25 is a bag-of-words ranking function. A document scores higher when it contains the query terms often, when those terms are rare across the corpus, and when the document is not excessively long. It does not understand synonyms or intent, which is exactly why it complements embeddings.

  • Term frequency saturates, so repeating a word has diminishing returns.
  • Inverse document frequency gives rare terms more weight.
  • Length normalisation prevents long documents from winning by volume.
  • Tokenisation and stemming choices materially change results.
BM25 needs the same analyser for indexing and querying. A mismatch in stemming or tokenisation quietly breaks exact matching.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Why does BM25 still matter when embeddings exist?
  2. 2How would you tune BM25 for code search?
  3. 3What happens with typos in a BM25 query?

Say it in the interview

BM25 ranks documents by how often query terms appear, weighted by how rare those terms are and normalised for document length. It is excellent for exact names, codes and rare vocabulary, which are exactly the cases embeddings can miss. It has no notion of synonyms, so I combine it with vector search. Tokenisation and stemming have to match between index and query, or the exact match silently fails.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live RAG & Retrieval mock interview and get scored feedback on depth, clarity and confidence.