LESSON 27 / 215·2 min readFoundation

Keyword search and BM25

Must knowConcept lesson
01 Understand02 Recall03 Prepare

Words made simple

A few useful meanings before you read the explanation.

BM25
A method for ranking documents using query-word matches and document statistics. It is useful when exact terms matter.
Semantic search
Searching by meaning rather than only matching exact words. A search for damaged car may also find vehicle accident documents.

Overview

  • Keyword search matches words or indexed terms rather than learned meaning.
  • BM25 is a common relevance formula that rewards useful matching terms, accounts for document length, and avoids letting repeated words dominate indefinitely.
  • It is usually implemented over an inverted index: a map from terms to documents.

Why this matters

Exact names, clause codes, policy numbers, and rare terms are often retrieved better lexically.

An everyday example

Searching a book index for “Clause 7.2” is more precise than describing what the clause might mean.

A technical example

Searching POL-2026-42 should prioritize documents containing that actual identifier.

How it works

  1. Analyze text into terms
  2. Build term/document index
  3. Analyze query
  4. Score matching documents
  5. Sort and filter.

Architecture and flow

Query terms → inverted index/BM25 → ranked matches.

The insurance assistant example

Find the exact exclusion code mentioned in a letter before explaining its wording.

When to use it

Exact identifiers, product terminology, and search requiring transparent lexical matching.

When to avoid it

Pure keyword search may fail “vehicle collision” versus “car accident” when no shared terms exist.

Interview answer

“BM25 is strong for exact terminology and identifiers. Semantic search handles paraphrases, so I often combine them.”

Benefits, trade-offs, and production considerations

  • Tokenization, stemming, stopwords, language analyzers, and synonyms affect results.
  • Preserve identifier fields separately; stripping punctuation may damage an exact policy-code search.
PAUSE & RECALL

Can you explain it without the notes?

Keyword search and BM25

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Keyword search matches words or indexed terms rather than learned meaning. BM25 is a common relevance formula that rewards useful matching terms, accounts for document length, and avoids letting repeated words dominate indefinitely. It is usually implemented…

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Hybrid search and metadata filtering

Adapted from 13_AI.MD · “Keyword search and BM25”. Examples are study fragments; framework behavior can depend on your version.