core practice · implementation task
Implement a BM25 ranker
On top of your inverted index, implement BM25 scoring and return the top-k documents for a multi-term query.
The mechanism
BM25 fixes TF-IDF's two flaws: term frequency saturates (the 10th occurrence adds little via the k1 parameter) and document length is normalized (the b parameter). It is still the strongest single keyword ranker and the lexical half of hybrid search.
Expected evidence
Ranked top-k results for a query, scored by summed per-term BM25.
Try this drill in the practice workspace →
Hints when you need them
- Sum per-term BM25 contributions for multi-term queries.
- Use a k-sized heap for the top-k.
Watch for these mistakes
- Believing embeddings make BM25 obsolete — they are complementary
- Leaving k1/b at defaults without tuning on your corpus
- Skipping document length normalization
- Not building search evals to compare against vector retrieval