# BM25

> BM25: A keyword-search scoring function that ranks documents by the query words they contain, weighting rare words more and long documents less.

Canonical: https://llmdojo.dev/glossary/bm25

A keyword-search scoring function that ranks documents by the query words they contain, weighting rare words more and long documents less.

Learn it in the lesson: [Selecting what goes in](https://llmdojo.dev/learn/prompt-context-engineering/context-selection/selecting-by-relevance) (Prompt and Context Engineering · Choosing Context: Selection, Ordering and Compression).

## Interview questions about BM25

- [You rank passages with reciprocal rank fusion of BM25 and embeddings, and keep the top one. The passage that answers the query never reaches the model. How?](https://llmdojo.dev/interview/q/you-rank-passages-with-reciprocal-rank-fusion-of-bm25-and-embeddings-and)
- [What does BM25 add to TF-IDF?](https://llmdojo.dev/interview/q/what-does-bm25-add-to-tf-idf)
- [Your retriever's top passage is usually on topic but often contradicts the right answer. What's going on, and what do you change?](https://llmdojo.dev/interview/q/your-retriever-s-top-passage-is-usually-on-topic-but-often-contradicts)
- [How does reciprocal rank fusion work, and why use ranks rather than scores?](https://llmdojo.dev/interview/q/how-does-reciprocal-rank-fusion-work-and-why-use-ranks-rather-than)
- [When can fusion make retrieval worse?](https://llmdojo.dev/interview/q/when-can-fusion-make-retrieval-worse)
- [Anthropic reports large gains from contextual retrieval. What exactly did they measure, and what does it cost?](https://llmdojo.dev/interview/q/anthropic-reports-large-gains-from-contextual-retrieval-what-exactly-did-they-measure)
- [Why combine keyword and embedding search, and where does a reranker fit?](https://llmdojo.dev/interview/q/why-combine-keyword-and-embedding-search-and-where-does-a-reranker-fit)
- [Design a RAG system that has to meet strict latency and cost targets while serving many tenants.](https://llmdojo.dev/interview/q/design-a-rag-system-that-has-to-meet-strict-latency-and-cost)

## Related
- [Lost in the middle](https://llmdojo.dev/glossary/lost-in-the-middle)
- [Needle in a haystack](https://llmdojo.dev/glossary/needle-in-a-haystack)
- [Reciprocal rank fusion](https://llmdojo.dev/glossary/reciprocal-rank-fusion)
- [Glossary of every term](https://llmdojo.dev/glossary)
