Elasticsearch & Lucene (50 Qs)•Part 2: Core Architecture & Implementation (Mid-Level)
How does the BM25 relevance ranking algorithm calculate scores?
senior LevelSystem Design
In Simple Words: Okapi BM25 is the default scoring algorithm in Lucene / Elasticsearch, improving upon classical TF-IDF:
- Term Frequency (TF): How often the term appears in the document. BM25 uses asymptotic saturation, preventing a document with 100 mentions of a word from dominating one with 5 mentions.
- Inverse Document Frequency (IDF): Rare terms across the index get much higher weight than common terms like "the" or "is".
- Field Length Normalization: Shorter fields containing the term score higher than massive documents where the term is just an incidental mention.