Keyword search and BM25
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
- Analyze text into terms
- Build term/document index
- Analyze query
- Score matching documents
- 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.
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…
Turn this concept into a clear answer.
Practice this conceptAdapted from 13_AI.MD · “Keyword search and BM25”. Examples are study fragments; framework behavior can depend on your version.