Maximum Marginal Relevance (MMR) is a re-ranking algorithm that iteratively selects documents by maximizing a linear combination of their relevance to a user's query and their novelty relative to documents already selected for the final result set. The core mechanism penalizes candidates that are too similar to previously chosen items, directly suppressing redundant information.
Glossary
Maximum Marginal Relevance (MMR)

What is Maximum Marginal Relevance (MMR)?
A concise definition of Maximum Marginal Relevance, a re-ranking algorithm designed to balance query relevance with result diversity in information retrieval systems.
Formally, MMR computes a score for each candidate document D as λ * Sim(D, Q) - (1-λ) * max(Sim(D, Di)), where Q is the query and Di are already-selected documents. The parameter λ controls the trade-off between relevance and diversity. This technique is foundational in modern retrieval-augmented generation (RAG) pipelines, where it is applied after initial vector similarity search to ensure the context window contains a diverse set of facts rather than repetitive, near-duplicate passages.
Key Characteristics of MMR
Maximum Marginal Relevance (MMR) is a set-based re-ranking algorithm that constructs a diverse result list by iteratively selecting documents that are both relevant to the query and dissimilar from documents already chosen.
The Core Trade-Off: Relevance vs. Redundancy
MMR operates on a linear combination of two competing scores. The algorithm calculates a marginal relevance score for each candidate document. This score is the document's similarity to the query minus the maximum similarity to any document already in the selected set. The lambda parameter controls the weight of this trade-off. A lambda of 1.0 maximizes pure relevance, while a lambda of 0.0 maximizes pure diversity, effectively penalizing any document that resembles an already-chosen one.
Iterative Greedy Selection
MMR builds the final ranked list one document at a time using a greedy selection process. It begins by selecting the single most relevant document for the query. In each subsequent iteration, it re-scores all remaining candidates against the updated set of chosen documents. The algorithm selects the candidate with the highest MMR score and adds it to the output set. This process repeats until the desired number of results is reached, ensuring each new addition contributes maximum novel information.
The Lambda Diversity Parameter
The λ (lambda) parameter is a user-defined constant between 0 and 1 that explicitly controls the diversity-relevance balance. When λ is high (e.g., 0.8), the algorithm strongly favors query relevance, producing a result set that may contain redundant information. When λ is low (e.g., 0.2), the algorithm aggressively penalizes similarity to prior selections, producing a highly diverse set that may drift from the core query intent. Tuning this parameter is critical for domain-specific performance.
Redundancy Penalty via Max Similarity
The novelty component of MMR is calculated by taking the maximum similarity between a candidate document and all documents already in the selected set. This is a conservative penalty: a candidate is judged by its closest neighbor in the output set. This prevents the algorithm from selecting a document that is highly relevant but nearly identical to a previously chosen result. The approach effectively clusters similar documents and selects only the single best representative from each cluster.
Application in RAG Pipelines
In Retrieval-Augmented Generation, MMR is a standard post-retrieval step applied to the initial set of candidates from a vector store. After an Approximate Nearest Neighbor (ANN) search returns the top-K most similar chunks, MMR re-ranks them to maximize the information density of the final context window. This prevents the language model from receiving five nearly identical chunks, which wastes the limited context window and provides no additional factual grounding for generation.
Mathematical Formulation
The MMR score for a candidate document D_i is defined as: MMR = λ * Sim(D_i, Q) - (1 - λ) * max_{D_j ∈ S} Sim(D_i, D_j). Here, Q is the query, S is the set of already-selected documents, and Sim is a similarity function like cosine similarity. The first term rewards relevance to the query. The second term penalizes similarity to the most similar document already chosen. This formula is computed iteratively until the desired number of documents is selected.
MMR vs. Other Re-Ranking Methods
A technical comparison of Maximum Marginal Relevance against alternative re-ranking strategies used in retrieval-augmented generation pipelines.
| Feature | Maximum Marginal Relevance (MMR) | Cross-Encoder Re-ranking | Reciprocal Rank Fusion (RRF) |
|---|---|---|---|
Core Mechanism | Linear combination of query relevance and novelty penalty against already-selected documents | Joint encoding of query-document pairs through a cross-attention transformer for precise relevance scoring | Score-free rank aggregation using reciprocal rank positions from multiple retrieval sources |
Primary Objective | Maximize relevance while minimizing redundancy in the final result set | Maximize pure relevance precision by exhaustively modeling query-document interactions | Produce a consensus ranking from heterogeneous retrieval systems without requiring calibrated scores |
Handles Redundancy | |||
Computational Cost | Moderate: O(n*k) where n is candidate set size and k is selected set size | High: O(n) cross-encoder forward passes where each pass is computationally expensive | Low: O(n log n) for sorting merged results with simple arithmetic scoring |
Requires Relevance Scores | |||
Diversity Parameter Tuning | Explicit λ parameter controls relevance-diversity trade-off; requires per-domain calibration | ||
Typical Pipeline Position | Post-retrieval re-ranker applied after initial vector similarity search | Second-stage re-ranker applied to top-k candidates from a faster bi-encoder retriever | Final fusion step merging result lists from dense vector search and sparse BM25 retrieval |
Latency Profile | < 50 ms for top-100 candidate re-ranking | 100-500 ms per query depending on model size and candidate count | < 10 ms for merging pre-ranked lists |
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 Maximum Marginal Relevance, its implementation, and its role in reducing redundancy in retrieval-augmented generation systems.
Maximum Marginal Relevance (MMR) is a re-ranking algorithm that selects documents by balancing their relevance to a query against their similarity to documents already selected for the final result set. The core mechanism uses a greedy, iterative process: it starts by selecting the single most relevant document, then for each subsequent selection, it scores remaining candidates using a linear combination of their query relevance and a penalty for their maximum similarity to any already-chosen document. This penalty term, controlled by a diversity parameter λ (lambda), explicitly reduces redundancy. When λ=1, the algorithm behaves as a standard relevance-only ranking; when λ=0, it maximizes novelty, selecting documents that are maximally dissimilar to each other regardless of query relevance. The formula is: MMR = argmax[ λ * Sim(D_i, Q) - (1-λ) * max Sim(D_i, D_j) ], where D_i is a candidate document, Q is the query, and D_j represents already-selected documents. This approach was introduced by Carbonell and Goldstein in 1998 and remains foundational in modern retrieval-augmented generation (RAG) pipelines for ensuring diverse context windows.
Related Terms
Core algorithms and strategies that work alongside or contrast with Maximum Marginal Relevance to optimize the diversity and precision of retrieved document sets.
Reciprocal Rank Fusion (RRF)
An algorithm that merges multiple ranked result lists into a single consensus ranking without requiring relevance scores. It assigns a reciprocal score based on each document's rank position, naturally penalizing low-ranked items. Unlike MMR, which operates on a single result set to balance relevance and novelty, RRF is a fusion method designed to combine outputs from different retrieval sources such as vector search and BM25.
Cross-Encoder Re-ranking
A two-stage retrieval refinement where a computationally expensive cross-encoder model processes the query and each candidate document jointly to produce a precise relevance score. This is applied only to the top results from a faster initial retrieval. While MMR re-ranks by penalizing inter-document similarity, a cross-encoder re-ranks by deeply analyzing query-document interaction, often serving as the final scoring step before MMR is applied for diversification.
Hybrid Search
A retrieval approach that combines dense vector similarity search with sparse keyword-based retrieval such as BM25. This leverages the strengths of both semantic understanding and exact term matching. MMR is frequently applied as a post-processing step on the combined candidate set from a hybrid search pipeline to ensure the final results presented to the user or language model are both relevant and non-redundant.
Content De-duplication
The identification and removal of duplicate or near-duplicate content from an indexing pipeline. While MMR reduces semantic redundancy in a ranked list by penalizing similar documents, de-duplication is a hard pre-processing or post-processing filter that removes exact or near-exact copies. MMR handles the gray area of documents that are topically similar but not identical, preventing information overlap in the final context window.
Approximate Nearest Neighbors (ANN)
A class of algorithms that trade a small amount of accuracy for significant gains in speed when finding the most similar vectors in a high-dimensional space. ANN is the initial retrieval engine that generates the candidate set. MMR is a subsequent re-ranking operation applied to this candidate set. The efficiency of the ANN algorithm directly determines the size and quality of the pool that MMR can diversify.
Information Density
A measure of the ratio of unique, substantive facts to total text length within a content chunk. High density improves retrieval precision by reducing noise. MMR complements this by ensuring that even high-density chunks are not selected if they are semantically redundant with already-chosen documents. Together, they maximize the total unique information delivered within a limited token budget for a language model.

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