← 2 Session 3 - Index construction and ranking foundations - Mon 07 Sep 4 →
All decks
  1. 1 Why retrieval nowMon 31 Aug
  2. 2 The inverted indexWed 02 Sep
  3. 3 Index construction and ranking foundationsMon 07 Sep
  4. 4 BM25: finish probabilistic rankingWed 09 Sep
  5. 5 Evaluation and the changing goals of retrieval benchmarksMon 14 Sep
  6. 6 Coarse retrieval and rerankingWed 16 Sep
  7. 7 LLM embeddings and rerankingMon 28 Sep
  8. 9 Hard queries: reasoning and ambiguityWed 07 Oct
  9. 10 Approximate nearest neighbour search and search systemsMon 12 Oct
  10. 12 Attention as retrievalMon 19 Oct
  11. 14 Memory as an architectural axisMon 26 Oct
  12. 16 Memory learned at test timeMon 02 Nov
  13. 18 Language models with an index attachedMon 09 Nov
  14. 20 Retrieval-augmented generationMon 16 Nov
  15. 22 Agentic retrieval and deep researchMon 23 Nov
  16. 23 Agent memory: write, manage, readWed 25 Nov
  17. 24 Learning what to rememberMon 30 Nov
  18. 26 Evaluating agent memoryMon 07 Dec
  19. 28 Privacy, personalisation and unlearningMon 14 Dec
Contents
  1. 1Index construction and probabilistic ranking
  2. 2Announcements
  3. 3The roadmap
  4. 4One assumption left
  5. 5BSBI - blocked sort-based indexing
  6. 6Ten blocks
  7. 7SPIMI - group by hashing
  8. 8Stop at the end of block ingestion
  9. 9Two decisions
  10. 10The shape in Lucene
  11. 11What transfers from BSBI
  12. 12Where it sits
  13. 13What matching has not answered
  14. 14Derive the score
  15. 15Two counts, two kinds of evidence
  16. 16Combine repetition with rarity
  17. 17Build document and query vectors
  18. 18What would justify the score?
  19. 19Define the relevance we want to predict
  20. 20Put more relevant documents near the top
  21. 21Use word evidence to infer relevance
  22. 22Cancel the denominator without changing the order
  23. 23Estimate term presence instead of whole documents
  24. 24Add the evidence from the query terms
  25. 25Use absence as a shared reference
  26. 26Obtain one weight for each matching term
  27. 27Estimate the probabilities without relevance labels
  28. 28Substitute the estimates to obtain IDF

The recording

1

Index construction and probabilistic ranking

Information Retrieval for AI

Session 3 - Mon 07 Sep 2026

KAIST AI - Seong Joon Oh

2

Announcements

  • Groups. Propose your own on the first-day survey by Mon 14 Sep. Remaining places are filled at random after that.
  • Discussion sessions begin Wed 30 Sep. The first review is due Tue 29 Sep, 18:00.
  • Recording. Lectures are recorded. Discussion sessions and project workshops are not.

Course syllabus

3

The roadmap

  1. Building the index - carried over
  2. Derive BM25 from Bayesian probability
    • Relevance odds and term likelihoods
    • IDF from Bayesian estimates
    • Saturation from a hidden term model
    • Length normalisation and the final formula
  3. Predict what a BM25 parameter changes
  4. Query likelihood and feedback

We stop where we stop. The rest opens next time.

4

One assumption left

The construction so far assumed the term-docID pairs fit in memory.

A larger collection or a smaller memory budget breaks that assumption.

How do we build the same index in blocks?

Introduction to Information RetrievalIntroduction to Information RetrievalManning, Raghavan & Schutze - 2008 - Cambridge University Pressalso session 2, 4, 5, section 4.2, pp. 69-71.

5

BSBI - blocked sort-based indexing

Blocked sort-based indexing (BSBI) groups by sorting.

  1. Fill memory with (termID, docID) pairs
  2. Sort them
  3. Collapse the runs into postings lists
  4. Write the result out as one sorted block

Keep the global term-to-termID map, clear the block workspace, and continue with the next block. The map is what makes the sort key mean the same term in every block: if one block assigns caesar -> 17 and the next assigns it 4001, the merge emits two entries for one term.

Introduction to Information RetrievalIntroduction to Information RetrievalManning, Raghavan & Schutze - 2008 - Cambridge University Pressalso session 2, 4, 5, section 4.2, pp. 69-71.

6

Ten blocks

f1f2f3f4f5f6f7f8f9f10each one sorted on the same key, and a complete index over its part of the collectionn-way mergeone forward cursor per fileno random lookup within a blockthe index

Merging ten sorted indexes. The merge opens ten read buffers and one write buffer.

7

SPIMI - group by hashing

Process documents in increasing docID order. Use a per-block dictionary from term string to a growing postings list.

caesar,d1  ->  {caesar: [d1]}
brutus,d1  ->  {caesar: [d1], brutus: [d1]}
caesar,d2  ->  {caesar: [d1,d2], brutus: [d1]}

Append a docID once per term-document pair. For repeated occurrences in that document, keep the same posting and increment its count if frequencies are stored.

Token occurrences need no sort. Distinct dictionary terms are sorted at the flush.

IIR §4.3, pp. 73-74; posting deduplication and optional frequency accumulation made explicit.

8

Stop at the end of block ingestion

After ingestion, before block finalisation
BSBIUnsorted termID-docID pairs. The postings lists for this block still need the sort and a collapsing pass.
SPIMIcaesar -> [d1, d2, d4]. The docIDs are already grouped by term.

The block still has to be written and merged with the others.

9

Two decisions

The key representation and the grouping method can be chosen separately.

Group by sortingGroup by hashing
Key is a termIDBSBIAnother coherent combination
Key is the term stringAnother coherent combinationSPIMI

The textbook algorithms occupy two of the four combinations.

10

The shape in Lucene

Lucene’s IndexWriter buffers changes in memory, flushes segments, and merges segments.

This is the buffering-and-merge shape we saw in SPIMI.

The connection is about the structure of the work, not an identity between implementations.

11

What transfers from BSBI

Create sorted runs that fit in memory. Merge them through forward cursors.

External merge sort also serves grouping and sorting in database systems.

The technique applies beyond inverted-index construction.

12

Where it sits

The knowledge-location spectrum:

  • Non-parametric
  • Sparse, exact term matching
  • No learned encoder
  • Updated by indexing changed documents
13

What matching has not answered

A document either satisfies the Boolean query or it does not.

The matching set can be large.

Which document should we show first?

14

Derive the score

TF-IDF gives us a scoring rule to question.

Start with joint and conditional probability in Introduction to Information RetrievalIntroduction to Information RetrievalManning, Raghavan & Schutze - 2008 - Cambridge University Pressalso session 2, 4, 5, section 11.1.

Follow The Probabilistic Relevance FrameworkThe Probabilistic Relevance Framework: BM25 and BeyondRobertson & Zaragoza - 2009 - FnTIRalso session 4 from relevance odds through term likelihoods, saturation and length normalisation.

15

Two counts, two kinds of evidence

QuantityWhat it countsIn our ten-document example
tf(t, d)Occurrences of t in dterm occurs 4 times in d7
df(t)Documents that contain t4 documents contain term
NDocuments in the collection10 documents

Repeating a word changes tf. Adding another document that contains it changes df.

IIR §6.2, pp. 117-118; counts computed from the course demo corpus.

16

Combine repetition with rarity

One TF-IDF weighting scheme is

vt,d=tf(t,d)logNdf(t).

For term in d7, using natural logarithms,

vterm,d7=4log104≈3.665.

At fixed rarity, this weight is proportional to frequency. If df(t) = N, the IDF and the term weight are zero. Other TF-IDF schemes transform tf before multiplication.

IIR §6.2.2, pp. 118-119

17

Build document and query vectors

Fix vocabulary V. Give both vectors one coordinate per term, in the same order.

vd=[tf(t,d)logNdf(t)]t∈V
vq=[tf(t,q)logNdf(t)]t∈V

Use the same collection IDF for both. An absent term has weight 0.

N = 10; q = term frequency. Three course-corpus coordinates:

TermDocument d₇ coordinateQuery coordinate
term4 log(10/4) ≈ 3.6651 log(10/4) ≈ 0.916
frequency2 log(10/2) ≈ 3.2191 log(10/2) ≈ 1.609
vector1 log(10/1) ≈ 2.3030 log(10/1) = 0

Natural logs; full vectors span V. The live demo counts each distinct query term once.

Compute relevance with cosine similarity between the two vectors.

IIR §6.2.2 and §6.3.1-6.3.2, pp. 120-124

18

What would justify the score?

TF-IDF chooses a function of repetition and rarity. Cosine chooses a comparison between vectors.

What quantity should a ranking estimate?

Start with the probability that a document is relevant. Derive a score from that target, then inspect the choices needed to make it usable.

Live demo - repeat a keyword

IIR §11.1-11.2, pp. 220-222

19

Define the relevance we want to predict

Hold the query q fixed throughout the derivation.

SymbolMeaning
R ∈ {0, 1}Non-relevant or relevant to the information need
dThe document’s observed word representation
P(R = 1 ∣ d, q)Relevance probability given that evidence

We observe the words and infer relevance. We will first use term presence, then account for frequency and document length.

IIR §11.1, pp. 220-221

20

Put more relevant documents near the top

At a cutoff k, choose the results with the largest expected total relevance. Give each relevant result value 1 and each non-relevant result value 0; values add.

𝔼[∑d∈SRd|q,𝒟]=∑d∈SP(Rd=1∣q,𝒟)

Here 𝒟 is the observed collection. In our document model, each posterior uses the evidence in d and q.

Swap an included document for one with a larger posterior: the expected total increases. Apply this at each cutoff to obtain descending probability order.

Target: compute a score with the same ordering as P(R = 1 ∣ d, q).

IIR §11.2, pp. 221-222; exchange argument shown here

21

Use word evidence to infer relevance

The target P(R = 1 ∣ d, q) is unknown. We can build models of how the document’s words occur within each relevance class.

Bayes’ rule connects those models to our target. For r ∈ {0, 1}:

P(R=r∣d,q)=P(d∣R=r,q)P(R=r∣q)P(d∣q)

P(d ∣ R = r, q) is the word evidence under class r; P(R = r ∣ q) is its prior.

The denominator still depends on the document. We cannot drop it when ranking. We need a way to preserve the order without estimating it.

IIR §11.1, pp. 220-221

22

Cancel the denominator without changing the order

We need an ordering. For 0 < p < 1, p/(1 − p) increases with p, so odds give the same ranking.

Divide the two Bayes expressions. Their shared P(d ∣ q) cancels:

P(R=1∣d,q)P(R=0∣d,q)=P(R=1∣q)P(R=0∣q)P(d∣R=1,q)P(d∣R=0,q)

The prior odds are the same for every document at this fixed q. Rank by the remaining likelihood ratio.

It compares how well the relevant and non-relevant word models explain this document. Those word models are the next quantity we must specify.

IIR §11.3.1, p. 224; positive likelihoods and non-degenerate prior assumed

23

Estimate term presence instead of whole documents

Whole-document patterns are too numerous to estimate separately. Start with xₜ = 1 if term t is present, and 0 otherwise.

Let pₜ be its presence probability in relevant documents and uₜ its presence probability in non-relevant documents, at this q.

Model choices: presence variables are independent given R and q; pₜ = uₜ for non-query terms. Those non-query factors cancel.

P(x∣R=1,q)P(x∣R=0,q)=∏t∈qptxt(1−pt)1−xtutxt(1−ut)1−xt

The binary representation is a modelling choice. q denotes distinct query terms in the product.

IIR §11.3-11.3.1, pp. 223-225

24

Add the evidence from the query terms

The model gives a product of term factors. We want a score we can accumulate one term at a time.

Log is strictly increasing on positive values. It preserves the ranking and turns the product into a sum:

s(q,d)=∑t∈q[xtlogptut+(1−xt)log1−pt1−ut]

A present term selects the first contribution; an absent term selects the second.

The score still includes missing query terms. The index gives us the documents that match each term. We need to express the score through those matches.

IIR §11.3.1, pp. 224-225

25

Use absence as a shared reference

Start with the score for absence of every query term. It depends on q and the term probabilities, not on which document we rank:

C(q)=∑t∈qlog1−pt1−ut

Subtract that same reference from every score:

s(q,d)−C(q)=∑t∈q:xt=1[logptut−log1−pt1−ut]

The ordering is unchanged. Each match replaces its absence contribution; each absent term now contributes zero.

IIR §11.3.1, p. 225

26

Obtain one weight for each matching term

The contribution of a match is the difference we just obtained. Combine the logarithms:

wt=logptut−log1−pt1−ut=logpt(1−ut)ut(1−pt)

The log odds ratio is the result of that subtraction: presence evidence relative to absence.

scoreBIM(q,d)=∑t∈q:xt=1wt

This is the binary independence model (BIM). The score is specified once we estimate pₜ and uₜ.

IIR §11.3.1, pp. 225-226

27

Estimate the probabilities without relevance labels

We have document frequencies but no relevance labels. A Beta(½, ½) prior for the presence probability θ keeps predictive estimates strictly between 0 and 1, so log weights stay finite.

For n Bernoulli observations independent given θ, with c presences, the posterior predictive probability is

θ^=𝔼[θ∣c,n]=c+12n+1
Needed estimateEvidence, choice and result
Relevant presence pₜNo observations, n = c = 0: pₜ = 0.5
Non-relevant presence uₜCollection proxy, n = N and c = df(t): uₜ = (df(t) + 0.5)/(N + 1)

The half-count prior and background proxy are estimation choices. The collection has not been labelled non-relevant.

IIR §11.3.2-11.3.3, pp. 226-227; Beta predictive rule made explicit here

28

Substitute the estimates to obtain IDF

The relevant-class presence odds are pₜ/(1 − pₜ) = 1. Substitute uₜ into the weight:

wt=log1−utut=logN−df(t)+0.5df(t)+0.5≡idfRSJ(t)

This is the probabilistic IDF form of the Robertson-Sparck Jones weight. Document frequency now determines the contribution of a match.

For 1 ≪ df(t) ≪ N, neglect the half counts and use N − df(t) ≈ N:

idfRSJ(t)≈logNdf(t)

We have a rarity weight. Term repetition has not entered the score yet.

IIR §11.3.3, p. 227