BM25 Retrieval is a bag-of-words ranking function that estimates the relevance of a document to a given search query based on term frequency, inverse document frequency, and document length normalization. In clinical entity linking, it functions as a robust candidate generation mechanism, rapidly scanning a knowledge base index to retrieve a shortlist of plausible UMLS concepts for an ambiguous medical mention, ensuring high recall before computationally intensive neural reranking.
Glossary
BM25 Retrieval

What is BM25 Retrieval?
A foundational probabilistic ranking function that serves as a high-recall lexical baseline for generating candidate entities in clinical entity linking pipelines.
The algorithm refines the classic TF-IDF approach by introducing a saturation parameter (k1) for term frequency and a length normalization parameter (b), preventing longer documents from being unfairly penalized. As a purely lexical system, it complements dense bi-encoder architectures by catching exact or near-exact string matches that semantic models might miss, making it an essential, low-latency first stage in a production clinical entity linking pipeline.
Key Features of BM25
BM25 is a probabilistic ranking function that estimates the relevance of documents to a given search query. It serves as a robust, high-recall baseline for candidate generation in clinical entity linking pipelines.
Term Frequency Saturation
Unlike simple TF-IDF, BM25 applies a non-linear saturation function to term frequency. This prevents a document containing a term 100 times from being scored 100 times higher than one containing it 10 times.
- The formula uses
tf / (k1 * ((1 - b) + b * (docLength / avgDocLength)) + tf) - k1 (typically 1.2–2.0) controls the saturation curve steepness
- This models the diminishing returns of repeated term usage in clinical notes
Document Length Normalization
BM25 compensates for the natural tendency of longer documents to contain more term occurrences. The b parameter (0 to 1) controls the degree of length normalization.
b=1fully normalizes by length, treating all documents equallyb=0applies no normalization, favoring longer documents- In clinical entity linking, b=0.75 is common to slightly favor comprehensive records without overwhelming short, focused notes
Inverse Document Frequency Component
BM25 incorporates an IDF-like weight that penalizes common terms and rewards rare, discriminative ones. The formula uses log((N - n + 0.5) / (n + 0.5)) where N is total documents and n is documents containing the term.
- Rare disease names receive high IDF boosts
- Common words like 'patient' or 'normal' are naturally suppressed
- This is critical for distinguishing between common and rare clinical entities in large corpora
Bag-of-Words Independence
BM25 treats documents as unordered collections of terms, ignoring word order and syntax. This lexical simplicity makes it:
- Extremely fast to compute using inverted indices
- Highly interpretable and debuggable
- Robust to typos and clinical shorthand variations
- An ideal candidate generation stage before neural reranking
For clinical entity linking, BM25 retrieves a broad set of candidate UMLS concepts that a cross-encoder can then precisely rank.
Probabilistic Relevance Foundation
BM25 is derived from the Binary Independence Model, a probabilistic framework that ranks documents by the odds of relevance given term occurrences. The formula estimates:
Score(D, Q) = Σ IDF(qi) * (tf(qi, D) * (k1 + 1)) / (tf(qi, D) + k1 * (1 - b + b * |D|/avgdl))
This probabilistic grounding provides theoretical justification for its strong empirical performance across decades of IR research.
Frequently Asked Questions
Clear, technical answers to common questions about the BM25 ranking function and its role as a lexical baseline in clinical entity linking pipelines.
BM25, or Best Matching 25, is a bag-of-words ranking function that estimates the relevance of a document to a given search query based on term frequency, inverse document frequency, and document length normalization. It operates by calculating a score for each matching term between the query and a candidate document, then summing these contributions. The algorithm applies saturation to term frequency, meaning that the impact of a term appearing multiple times diminishes logarithmically, preventing keyword stuffing from dominating the score. Simultaneously, it penalizes long documents through a soft normalization factor, recognizing that a term appearing in a short document is a stronger relevance signal than the same term in a lengthy one. The k1 and b parameters control the saturation curve and length normalization strength, respectively, allowing practitioners to tune the function for specific corpora. In a clinical entity linking pipeline, BM25 serves as a robust lexical baseline for the candidate generation stage, rapidly retrieving a shortlist of plausible knowledge base entries whose descriptions contain overlapping tokens with the ambiguous clinical mention.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Foundational algorithms and techniques that establish the lexical baseline for candidate generation in clinical entity linking pipelines.
TF-IDF Weighting
The statistical foundation upon which BM25 is built. Term Frequency-Inverse Document Frequency assigns a weight to each term in a document proportional to how often it appears, offset by how common it is across the entire corpus. In a clinical context, a rare term like 'rhabdomyosarcoma' receives a much higher weight than a ubiquitous term like 'patient'. BM25 refines this by introducing saturation curves to prevent high-frequency terms from dominating and by normalizing for document length, making it a more robust evolution of the basic TF-IDF model.
Candidate Generation
The initial, high-recall stage of an entity linking pipeline where BM25 is most commonly deployed. The goal is to retrieve a small, manageable set of plausible knowledge base entries for an ambiguous mention like 'cold'. BM25 acts as a fast, non-neural filter over a search index of entity descriptions and synonyms, efficiently narrowing down millions of concepts to a top-k list—perhaps 50-100 candidates—that a more computationally expensive neural cross-encoder can then precisely rank.
Lexical Variant Generation
A preprocessing technique that significantly boosts BM25's recall. Before indexing, programmatic rules generate morphological and orthographic variations of clinical terms to populate the search index. For example, the term 'myocardial infarction' might be expanded to include 'infarction of myocardium', 'MI', and 'heart attack'. This ensures that BM25's exact-match heuristics can bridge the gap between the shorthand found in clinical notes and the canonical forms stored in ontologies like SNOMED CT.
Inverted Index
The core data structure that makes BM25 retrieval computationally feasible at scale. An inverted index maps each unique term to a sorted list of document IDs where it appears, along with positional data. When a query like 'acute chest pain' is processed, the engine fetches the posting lists for 'acute', 'chest', and 'pain' and performs a fast intersection. This allows BM25 to score only documents containing at least one query term, avoiding a linear scan of the entire knowledge base.
Sparse Vector Representation
The mathematical encoding of text used by BM25, standing in contrast to the dense vectors used in neural semantic search. A sparse vector has a dimensionality equal to the vocabulary size, where most values are zero. Only the terms present in the document have non-zero weights. This representation is highly interpretable—you can see exactly which tokens contributed to a match—and is extremely efficient for exact keyword matching, making it an ideal, transparent baseline before introducing the opacity of dense embeddings.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us