Inferensys

Glossary

Maximal Marginal Relevance (MMR)

A re-ranking algorithm that balances relevance to the query with diversity among the results to avoid redundancy in the final retrieved document set.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
DIVERSITY-DRIVEN RETRIEVAL

What is Maximal Marginal Relevance (MMR)?

A re-ranking algorithm that balances relevance to the query with diversity among the results to avoid redundancy in the final retrieved document set.

Maximal Marginal Relevance (MMR) is a re-ranking algorithm that iteratively selects documents by maximizing a linear combination of relevance to the query and novelty relative to already-selected documents. The core mechanism uses a tunable lambda parameter to trade off between these two objectives, penalizing candidates that are too similar to the existing result set.

Originally proposed by Carbonell and Goldstein in 1998 for text summarization, MMR is now critical in Retrieval-Augmented Generation (RAG) pipelines. It prevents the context window from being saturated with near-duplicate chunks, ensuring the language model receives a diverse set of evidence for factual grounding.

Algorithm Mechanics

Key Characteristics of MMR

Maximal Marginal Relevance (MMR) is a re-ranking algorithm that constructs a final result set by iteratively selecting documents that maximize a linear combination of relevance to the query and dissimilarity to already-selected documents.

01

The Core Objective Function

MMR operates by greedily selecting the next document D that maximizes the following score:

MMR = Argmax [ λ * Sim(D, Q) - (1 - λ) * max Sim(D, Di) ]

  • λ (Lambda): A hyperparameter between 0 and 1 controlling the trade-off.
  • Sim(D, Q): The similarity between a candidate document and the query.
  • max Sim(D, Di): The maximum similarity between the candidate and any already-selected document.

When λ=1, the algorithm is a standard relevance-only ranking. When λ=0, it maximizes diversity by selecting documents most dissimilar to everything already chosen.

02

The Redundancy Penalty Mechanism

The key innovation of MMR is the subtractive penalty term that actively suppresses redundant information.

  • A candidate document highly relevant to the query but nearly identical to an already-selected document receives a high penalty, reducing its MMR score.
  • A slightly less relevant but topically distinct document can outrank it because its penalty term is low.
  • This prevents the common failure mode of standard similarity search where the top-k results are near-duplicates of each other, ensuring the final list covers diverse aspects of the query.
03

Greedy Incremental Construction

MMR builds the result set one document at a time using a greedy selection process, not a global optimization.

  • Step 1: The first document selected is always the single most relevant item to the query.
  • Step 2: The algorithm iterates, recalculating the MMR score for all remaining candidates against the growing set of chosen documents.
  • Trade-off: This greedy approach is computationally efficient (polynomial time) but does not guarantee a globally optimal diverse set. It is a practical heuristic that works well in real-time retrieval systems.
04

The Lambda Diversity Trade-off

The λ parameter is the single control knob for balancing relevance and diversity, and tuning it is highly application-specific.

  • High λ (e.g., 0.7-0.9): Favors relevance. Useful for question-answering where the top document must be correct, and diversity is a secondary concern.
  • Low λ (e.g., 0.3-0.5): Favors diversity. Ideal for exploratory search, summarization of large document collections, or product recommendation where showing varied options is critical.
  • Practical Tuning: The optimal λ is typically found through offline evaluation on a labeled dataset measuring both precision and subtopic recall.
05

Application in RAG and AI Summarization

MMR is a critical post-retrieval step in modern Retrieval-Augmented Generation (RAG) pipelines to manage the context window.

  • Context Diversity: A vector store may retrieve 20 semantically similar chunks. Applying MMR selects the top-5 most diverse chunks to fit within the LLM's token limit, providing broader grounding.
  • Hallucination Reduction: By forcing the model to synthesize an answer from distinct, non-redundant sources, MMR reduces the risk of the model overfitting to a single repetitive piece of evidence.
  • Implementation: LangChain and LlamaIndex provide native MMR vector store retrievers that apply the algorithm directly on embedding similarity scores.
06

Limitations and Computational Cost

Despite its effectiveness, MMR has distinct limitations compared to modern learned alternatives.

  • Linear Similarity Assumption: MMR uses a simple linear combination of cosine similarities. It cannot learn complex, non-linear patterns of redundancy that a cross-encoder reranker might capture.
  • Quadratic Complexity: The greedy algorithm requires computing pairwise similarity between the candidate set and the growing selected set, leading to O(n*k) complexity where n is the candidate pool size and k is the number of selections.
  • Static Lambda: A single global λ cannot adapt to different query types. A factual query ("capital of France") needs no diversity, while an ambiguous query ("jaguar") needs high diversity. Adaptive MMR variants attempt to predict λ per-query.
MMR EXPLAINED

Frequently Asked Questions

Clear, technical answers to the most common questions about the Maximal Marginal Relevance algorithm and its role in reducing redundancy in retrieval systems.

Maximal Marginal Relevance (MMR) is a re-ranking algorithm that selects documents by balancing their relevance to a user's query against their similarity to documents already selected for the final result set. The core objective is to minimize redundancy while preserving query relevance. MMR operates by iteratively building a result set S from a candidate set C. At each step, it selects the document d that maximizes the following scoring function: MMR = Argmax[ λ * Sim1(d, Q) - (1 - λ) * max(Sim2(d, di)) ], where Q is the query, di is a document already in S, Sim1 measures query relevance, Sim2 measures inter-document similarity, and λ is a tunable parameter controlling the diversity-relevance trade-off. When λ=1, the algorithm behaves as a standard relevance-only ranking; when λ=0, it produces a maximally diverse but potentially irrelevant set. The algorithm was introduced by Carbonell and Goldstein in 1998 and remains foundational in modern retrieval-augmented generation (RAG) pipelines to prevent near-duplicate passages from dominating the context window.

Prasad Kumkar

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.