Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Probabilistic Ranking and BM25

The Vector Space Model ranks effectively, but its weighting and similarity measures are heuristic. Probabilistic retrieval asks a more direct question: given query QQ and document DiD_i, how likely is the document to be relevant? The Binary Independence Model (BIR) develops this idea from binary term evidence. BM25 then retains its probabilistic term weighting while adding the term-frequency saturation and document-length normalization missing from BIR and vector-space scoring.

Binary Independence Model

The BIR model uses the same tokenized vocabulary as the previous models, but represents each query and document as a set of terms. It was formalized by Robertson and Spärck Jones; see Relevance Weighting of Search Terms in the Further Reading section of the chapter summary. A component is 1 when a term is present and 0 when it is absent. It assumes that terms contribute independently and that non-query terms occur equally often in relevant and non-relevant documents. Under these assumptions, only query terms present in a document affect its rank.

Let RR denote relevance and NRNR non-relevance for query QQ. Ranking by the posterior odds

P(R∣Di,Q)P(NR∣Di,Q)\frac{P(R\mid D_i,Q)}{P(NR\mid D_i,Q)}

is equivalent to ranking by the document evidence after query-dependent constants are removed. Define

rj=P(di,j=1∣R,Q),nj=P(di,j=1∣NR,Q).r_j=P(d_{i,j}=1\mid R,Q), \qquad n_j=P(d_{i,j}=1\mid NR,Q).

The first probability measures how often term tjt_j occurs in relevant documents; the second measures how often it occurs in non-relevant documents. The resulting score is additive, but several probability terms must cancel before we reach that form. The derivation below explains why only query terms present in the document remain.

Relevance Feedback

Initial estimates. Before any relevance information is available, the system must produce a first ranking. BIR commonly assumes that every query term has an equal chance of occurring in a relevant document, rj=0.5r_j=0.5. It estimates occurrence in non-relevant documents from the term’s document frequency in the complete collection:

rj=0.5,nj=df(tj)+0.5N+1.r_j=0.5, \qquad n_j=\frac{\text{df}(t_j)+0.5}{N+1}.

These initial values produce the first cjc_j weights and therefore the first result list.

Collecting feedback. The user can now mark retrieved documents as relevant or non-relevant, for example through like and dislike controls. These judgements provide a sample of both classes. Because rjr_j is the probability that term tjt_j occurs in a relevant document, we can estimate it by counting how many judged relevant documents contain the term. We estimate njn_j in the same way from the judged non-relevant documents.

Updating the estimates. Suppose the user has judged KK documents and marked LL of them as relevant. Let kjk_j be the number of judged documents containing tjt_j, and let ljl_j be the number that both contain tjt_j and are relevant. The relevant sample therefore contains ljl_j occurrences among LL documents. The non-relevant sample contains kj−ljk_j-l_j occurrences among K−LK-L documents. Without smoothing, the corresponding estimates would be

rj≈ljL,nj≈kj−ljK−L.r_j\approx\frac{l_j}{L}, \qquad n_j\approx\frac{k_j-l_j}{K-L}.

In practice, BIR adds pseudo-counts so that small samples do not produce probabilities of exactly 0 or 1:

rj=lj+0.5L+1,nj=kj−lj+0.5K−L+1.r_j=\frac{l_j+0.5}{L+1}, \qquad n_j=\frac{k_j-l_j+0.5}{K-L+1}.

The updated probabilities produce new cjc_j weights and a revised ranking. Further rounds of feedback can refine the estimates, although users may be unwilling to judge many results.

BIR marks a change in ambition, not only a change in formula. The Vector Space Model ranks by geometric heuristics that happen to work well; BIR instead tries to explain relevance from first principles, estimating how likely a document is to be relevant given its terms. It still represents documents as term vectors and still combines evidence with the same OR-like accumulation as VSM: any query term found in the document contributes its weight to the score. What changes is the meaning of that weight. Instead of a heuristic tf-idf product, cjc_j estimates the independent contribution of each query term toward relevance, grounded in how often the term separates relevant from non-relevant documents.

The restrictive assumptions behind this first version, binary term presence, term independence, and no document-length effect, are not inherent to the probabilistic idea itself. They make BIR tractable, and later probabilistic models relax them one at a time. The 2-Poisson model, for instance, models within-document term frequency directly instead of treating term presence as binary, at the cost of a more complex parameter estimation problem; see Robertson and Walker’s Some Simple Effective Approximations to the 2-Poisson Model for Probabilistic Weighted Retrieval in the Further Reading section of the chapter summary. Probabilistic language models take yet another route, estimating the probability that a document’s language model would generate the query. The section below develops BM25, which keeps BIR’s additive, per-term structure but approximates the 2-Poisson model’s term-frequency behaviour with a simpler saturating function.

The feedback mechanism also has a practical limitation worth mentioning. A user who rates a first result list of 10 documents gives us a sample of size K=10K=10 from which to estimate rjr_j and njn_j, far too small to pin down these probabilities reliably, especially for terms that appear in only one or two of the judged documents. Larger judged samples would improve the estimates, but no user will realistically rate hundreds of documents to make search work. This tension between statistical need and user effort is a recurring theme in relevance feedback, not a flaw specific to BIR.

Okapi BM25

BM25 was developed at London’s City University by Stephen Robertson, Karen Spärck Jones, and colleagues as a practical approximation to the 2-Poisson model. It became the robust default for free-text retrieval that BIR itself never was. Robertson and Zaragoza’s The Probabilistic Relevance Framework: BM25 and Beyond, listed in the Further Reading section of the chapter summary, surveys the complete derivation and its later extensions.

Three Unresolved Issues

Before introducing the BM25 formula, it helps to see exactly what the two preceding models still get wrong. Each issue below reappears as a concrete design decision in BM25.

Vector-space scoring rewards repetition without limit. Recall the running query cat dog forest from the Vector Space Retrieval section. Its inner product already ranks D7D_7 (four occurrences of “dog”, score 2.773 for that term alone) above D9D_9 (one occurrence of each query term, contributing 0.693 for “dog” toward its combined score of 1.537), even though D9D_9 is the only document that mentions “cat”, “dog”, and “forest” together. If a document repeated “dog” twenty times instead of four, its score would climb to 13.863, growing linearly and without bound. A ranking function that rewards raw repetition this directly is vulnerable to keyword stuffing: an author can inflate a document’s score simply by repeating a term, regardless of whether the document is actually about that topic.

Raw term frequency ignores what “coverage” means for document length. A term occurring once in a 3-token document (such as D9D_9) is stronger evidence of relevance than the same term occurring once in a 20-token document, because in the short document, that one occurrence forms a much larger share of the content. TF-IDF and the inner product treat both occurrences identically. Relevance should depend on how much of the document is about the query term, not merely how many times it appears. To reward the same relevance signal, a longer document should need proportionally more occurrences of a term than a shorter one to reach the same score.

Binary presence throws away frequency information, but the idea behind rjr_j and njn_j is worth keeping. BIR’s document evidence is either 0 or 1, so it cannot express that D7D_7 mentions “dog” four times while D3D_3 mentions it once. At the same time, BIR contributes something valuable: the idea that a term’s ranking weight should reflect how well that term distinguishes relevant from non-relevant documents, not just how rare it is in the collection overall. BM25 keeps this probabilistic idea but combines it with a real-valued term-frequency component.

Term-Frequency Saturation

BM25 replaces the raw count in the TF-IDF product with a bounded function of term frequency:

tf^k1=tf(k1+1)tf+k1,k1>0.\widehat{\text{tf}}_{k_1}=\frac{\text{tf}(k_1+1)}{\text{tf}+k_1}, \qquad k_1>0.

The first occurrence contributes strongly; later occurrences add progressively less; the value never exceeds k1+1k_1+1 no matter how often the term repeats. This directly answers the spamming issue: repeating “dog” twenty times can no longer produce an unbounded score. Parameter k1k_1 controls how quickly the function saturates. Values between 1 and 2 are common, with k1=1.2k_1=1.2 used in the running example. Figure 1 contrasts linear, square-root, and saturating term-frequency weights.

Linear, square-root, and BM25-saturated term-frequency weighting.

Figure 1:Linear, square-root, and BM25-saturated term-frequency weighting.

Document-Length Normalization

Saturation alone does not address the length issue: a document with tf=1 in 3 tokens and a document with tf=1 in 20 tokens still saturate identically. BM25 makes the saturation point depend on document length by scaling the denominator:

tf^k1,b(Di,t)=tf(Di,t)(k1+1)tf(Di,t)+k1(1−b+b∣Di∣avgdl).\widehat{\text{tf}}_{k_1,b}(D_i,t)=\frac{\text{tf}(D_i,t)(k_1+1)}{\text{tf}(D_i,t)+k_1\left(1-b+b\frac{|D_i|}{\text{avgdl}}\right)}.

Here ∣Di∣|D_i| is the number of processed tokens (=document length) and avgdl\text{avgdl} is the collection’s average document length. For the running collection, avgdl=9.67\text{avgdl}=9.67 tokens. A single occurrence of “dog” in a 3-token document (shorter than average) contributes 1.393, while the same single occurrence in a 20-token document (longer than average) contributes only 0.696: the short document needs less repetition to reach the same weight because that occurrence covers a larger share of its content. Parameter b∈[0,1]b\in[0,1] controls the strength of this effect: b=0b=0 disables length normalization entirely, while b=1b=1 applies the full length ratio. Figure 2 shows how the same term frequency receives more weight in a short document than in a long one.

BM25 term-frequency saturation for average, short, and long documents.

Figure 2:BM25 term-frequency saturation for average, short, and long documents.

Probabilistic IDF

The third issue was that BIR’s idea of estimating a term’s discriminating power from rjr_j and njn_j is worth keeping even though its binary document model is not. Substituting the no-feedback BIR estimates (rj=0.5r_j=0.5 and njn_j from document frequency) into the cjc_j formula from the previous section gives exactly the classical BM25 weight:

idfBM25(t)=log⁡N−df(t)+0.5df(t)+0.5.\text{idf}_{\text{BM25}}(t)=\log\frac{N-\text{df}(t)+0.5}{\text{df}(t)+0.5}.

This value becomes negative when a term appears in more than half of the collection. Many implementations instead use the always-positive Lucene variant

idf+(t)=log⁡(1+N−df(t)+0.5df(t)+0.5)=log⁡N+1df(t)+0.5.\text{idf}_{+}(t)=\log\left(1+\frac{N-\text{df}(t)+0.5}{\text{df}(t)+0.5}\right)=\log\frac{N+1}{\text{df}(t)+0.5}.

Figure 3 compares these variants with the smoothed classical IDF introduced earlier. All encode the same core intuition that common terms provide less evidence, but their numerical values are not interchangeable.

Classical, original BM25, and positive Lucene IDF variants.

Figure 3:Classical, original BM25, and positive Lucene IDF variants.

A negative weight is undesirable for an additive scoring function: it would let a matching query term actively lower a document’s score, the opposite of what a match should do, and it complicates summing evidence across query terms of very different commonness. The Lucene weight log⁡N+1df(t)+0.5\log\frac{N+1}{\text{df}(t)+0.5} and the smoothed classical VSM weight log⁡Ndf(t)\log\frac{N}{\text{df}(t)} are nearly identical: comparing them shows that the Lucene variant is equal to the classical one exactly when df(t)=N/2\text{df}(t)=N/2, slightly below it for rare terms, and slightly above it for common terms, never departing far in either direction. This is exactly the region where the original BM25 IDF turns negative, so Lucene’s variant tracks the familiar classical shape almost everywhere while staying non-negative where it matters. Lucene therefore adopts it as a numerically safer stand-in for the same underlying quantity rather than as a conceptually different weighting scheme.

Complete Formula and Running Example

Using the positive IDF variant gives the practical scoring function used in this example.

For Q=Q= cat dog forest, use k1=1.2k_1=1.2, b=0.75b=0.75, and the same preprocessing as before. The 12 documents have avgdl=9.67\text{avgdl}=9.67 tokens. Their positive IDF values are 0.860 for “cat”, 0.693 for “dog”, and 0.550 for “forest”.

Evaluation follows the same efficient pattern as vector-space retrieval. The system takes the union of the query-term posting lists, accumulates one BM25 contribution per matching term, and sorts candidates by decreasing score. Chapter 4 develops the posting-list algorithms used for this process.

Limitations and Modern Applications

BM25 remains lexical and bag-of-words based. It neither connects “cat” with “feline” nor distinguishes the natural and technical meanings of “forest”. It also assumes that document length should influence relevance in a consistent way, so k1k_1 and bb may require tuning for collections with unusual document types. Despite its probabilistic derivation, a BM25 score is a ranking value, not a calibrated probability of relevance.

Advantages: BM25 combines partial matching, discriminative term weighting, term-frequency saturation, and document-length normalization in an efficient additive score. It is transparent, fast, and difficult to improve upon as a lexical baseline.

Disadvantages: It retains lexical matching and term-independence assumptions, requires parameter choices, and does not directly represent phrase meaning or semantic similarity.

BM25 is the default or standard lexical ranker in systems built on Lucene, including Elasticsearch, Solr, and OpenSearch. It is also widely used as a first-stage retriever in retrieval-augmented generation and in hybrid search, where its exact lexical matches complement dense embedding retrieval.