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.
Glossary
Maximal Marginal Relevance (MMR)

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
Related Terms
Explore the core algorithms and concepts that interact with Maximal Marginal Relevance to balance relevance and diversity in high-dimensional retrieval systems.

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