Modules/Gen AI/ MMR Lab

Maximal Marginal Relevance

The three most relevant chunks are sometimes three copies of the same idea. MMR picks the next chunk by how much it adds, not by how relevant it is in isolation.

Selection

0.5

1.0 = pure relevance (same as MMR off). 0.0 = pure diversity, ignores relevance entirely.

query: "database indexing performance", top 3 of 6 selected

Selected, In Order

Pairwise Similarity

Coverage

Sub-topics covered1 of 3

 

MMR: A Practical Guide

Trading a little relevance for a lot of coverage.

Quick Context

Plain top-k retrieval picks the k highest-scoring documents independently. If a document collection has several near-identical passages about the same popular sub-topic, all of them can legitimately score near the top — and a naive top-k fills the context with repetition instead of coverage, wasting the retrieval budget on saying the same thing three times.

The formula

MMR = argmaxd ∈ remaining [ λ · relevance(d, query) − (1−λ) · maxs ∈ selected similarity(d, s) ]

Selection happens one document at a time, not all at once. The first pick is whatever is most relevant, exactly like ordinary retrieval. Every pick after that is penalised by how similar it is to whatever has already been chosen — so a document that would have ranked highly on relevance alone can lose to a less relevant document that covers new ground.

Interactive Exploration Guide

  1. Read the pairwise similarity grid. Three of the six candidates are near-duplicates of each other — high similarity across that block — while the rest cover different ground.
  2. Leave MMR off. The top 3 by relevance alone are the query-planning chunk plus two of the three near-duplicate B-tree chunks — the hash-index sub-topic is crowded out entirely, covering only 2 of 3 sub-topics with two of three slots spent restating the same B-tree point.
  3. Turn MMR on at λ=0.5. The first pick does not change — it is still the most relevant document, since nothing has been selected yet to be similar to. The second and third picks do change: instead of a second B-tree chunk, MMR reaches for the hash-index one, and coverage goes from 2 of 3 sub-topics to all 3.
  4. Push λ to 1.0. The similarity penalty vanishes entirely and the result is identical to MMR being off — λ=1 is pure relevance by construction.
  5. Pull λ to 0.0. Relevance stops mattering at all; only spreading out matters, which can surface a barely-related document purely because nothing already picked resembles it.

Key Takeaway

MMR selects documents one at a time, and after the first pick, every subsequent choice is weighed against how similar it is to what has already been selected — trading some relevance for coverage. λ controls the trade directly: 1.0 is ordinary top-k relevance ranking, 0.0 ignores relevance and maximises spread, and everything between balances the two. It costs one similarity comparison against the selected set per candidate per step, which is cheap next to embedding or reranking and is standard in any RAG system retrieving more than a couple of chunks per query.

Predict, then reveal

About to run: set λ (relevance weight) to its maximum (1). Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Recall check

0 of 3

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. Without scrolling back — what is the one-line takeaway from this module?

  2. What does this module say about “Selection”?

  3. What does this module say about “Quick Context”?

Cheat sheet

Maximal Marginal Relevance (MMR)

The three most relevant chunks are sometimes three copies of the same idea. MMR picks the next chunk by how much it adds, not by how relevant it is in isolation.

GEN AI · vizlearn.in/gen_ai/maximal_marginal_relevance.html