Maximal Marginal Relevance (MMR) is a ranking algorithm used in information retrieval and search systems to select a subset of items that are both highly relevant to a query and maximally diverse from one another. It formalizes the trade-off between relevance and novelty by iteratively choosing the document that maximizes a weighted combination of its similarity to the query and its dissimilarity to documents already selected. This process directly combats redundancy, ensuring the final result set covers distinct aspects of the information need.
Glossary
Maximal Marginal Relevance (MMR)

What is Maximal Marginal Relevance (MMR)?
Maximal Marginal Relevance (MMR) is a ranking algorithm designed to optimize information retrieval result sets by balancing relevance with diversity, thereby reducing redundancy.
The algorithm is defined by a lambda (λ) parameter that controls the balance between relevance and diversity. A higher λ prioritizes pure relevance, behaving like a standard similarity search, while a lower λ emphasizes novelty. MMR is foundational in semantic search, retrieval-augmented generation (RAG), and recommender systems where presenting a varied, non-repetitive set of answers or items is critical. It operates on vector embeddings, calculating cosine similarity for both relevance to the query and dissimilarity within the result set.
Core Characteristics of MMR
Maximal Marginal Relevance (MMR) is a ranking algorithm that optimizes information retrieval by balancing relevance to a query with diversity among selected results. It is defined by its core operational parameters and mathematical formulation.
The Core Trade-off: Relevance vs. Novelty
MMR formalizes the fundamental tension in result ranking. It selects the next document d_i from a candidate set R that maximizes a weighted combination of two scores:
- Relevance Score: How well d_i matches the original query Q, typically computed via cosine similarity with a query embedding or a score like BM25.
- Novelty Score: How dissimilar d_i is from all documents S already selected in the result set, measured by maximal similarity to any document in S.
The algorithm explicitly prevents the top results from being near-duplicates of each other, ensuring each selected item adds new information.
The Lambda (λ) Parameter
The lambda (λ) parameter is a tunable hyperparameter between 0 and 1 that controls the balance between relevance and diversity in the MMR equation:
MMR(d_i) = λ * Sim1(d_i, Q) - (1 - λ) * max_{d_j in S} Sim2(d_i, d_j)
- λ = 1.0: Pure relevance ranking. Diversity is ignored, reverting to a standard similarity search.
- λ = 0.5: Equal weight to relevance and novelty. A common default for general-purpose diversification.
- λ = 0.0: Pure diversity ranking. The query is ignored; results are selected solely to be different from each other.
Engineering teams tune λ based on the use case: lower for exploratory search, higher for fact-finding missions.
Greedy Selection Algorithm
MMR uses a greedy, iterative selection process because the optimal set selection is NP-hard. The algorithm proceeds as follows:
- Start with an empty result set S and a full candidate set R.
- Select the document from R with the highest relevance score to Q and move it to S.
- For each remaining position k:
- For every document d_i in R, compute its MMR score.
- Select the document d_i with the highest MMR score.
- Remove d_i from R and add it to S.
- Repeat step 3 until S reaches the desired size.
This greedy approach is computationally efficient, requiring O(kn) similarity computations for k results and n candidates.
Similarity Function Flexibility
MMR is agnostic to the specific similarity functions used for Sim1 (query-document) and Sim2 (document-document). This allows integration with various retrieval backends:
- Sparse Retrieval: Use BM25 or TF-IDF for
Sim1andSim2. - Dense Retrieval: Use cosine similarity between vector embeddings (e.g., from Sentence-BERT).
- Hybrid Retrieval: Use a weighted combination of sparse and dense scores for
Sim1. - Cross-Encoder Reranking: Use a more accurate but slower neural model for final
Sim1scoring after an initial fast retrieval.
The choice of similarity function directly impacts the semantic definition of both "relevance" and "novelty."
Application in RAG and Agentic Systems
In Retrieval-Augmented Generation (RAG) and autonomous agent workflows, MMR is critical for context window management.
- Preventing Redundancy: When constructing a context window from multiple retrieved documents, MMR ensures each chunk provides unique information, maximizing the utility of limited model tokens.
- Mitigating Bias: Without MMR, a retriever might return several highly similar documents that reinforce a single perspective or fact, potentially biasing the LLM's synthesis.
- Supporting Multi-Step Reasoning: For agents, diverse context chunks can contain different pieces of evidence required for complex, multi-faceted reasoning, as opposed to repetitive evidence for a single sub-task.
Computational Complexity & Optimizations
The naive MMR implementation has a complexity of O(kn) for k results and n candidates, with each step requiring a similarity computation against all items in S. For large-scale systems, this can be optimized:
- Pre-computed Document-Document Similarity: For static corpora, a pre-computed similarity matrix can cache
Sim2values, trading memory for speed. - Approximate Nearest Neighbor (ANN) Search: Use vector indexes like HNSW for fast retrieval of top-relevance candidates (
Sim1), reducingnin the initial candidate set R. - Cluster-Based Pruning: First cluster candidates, then apply MRR to select diverse clusters before selecting within clusters.
- Threshold-Based Novelty: Ignore the
maxoperation if similarity to any doc in S is below a threshold, speeding up the calculation.
Frequently Asked Questions
Maximal Marginal Relevance is a core ranking algorithm in information retrieval designed to balance relevance with diversity, preventing redundant results. These FAQs address its mechanics, applications, and implementation for engineers building retrieval systems.
Maximal Marginal Relevance (MMR) is a ranking algorithm used in information retrieval to select a subset of items from a larger candidate set that are both highly relevant to a query and sufficiently diverse from one another, thereby reducing redundancy in the final result list.
Introduced in a 1998 paper by Carbonell and Goldstein, MMR formalizes the trade-off between relevance and novelty. It operates by iteratively selecting the document that maximizes a weighted combination of its similarity to the query and its dissimilarity (or minimal similarity) to the documents already chosen. The core equation is:
MMR = argmax [ λ * Sim(D_i, Q) - (1 - λ) * max Sim(D_i, D_j) ]
Where Sim(D_i, Q) is the relevance score of document i to query Q, max Sim(D_i, D_j) is its maximum similarity to any already-selected document j, and λ is a tunable parameter between 0 and 1 that controls the diversity-relevance balance.
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.
Related Terms
Maximal Marginal Relevance (MMR) operates within a broader ecosystem of algorithms and data structures designed for intelligent information retrieval. These related concepts define the technical landscape for reducing redundancy and optimizing relevance.
Semantic Chunking
The foundational preprocessing step for MMR. Semantic chunking segments documents into coherent units based on contextual meaning and topic boundaries, rather than arbitrary character counts. This creates the candidate pool of passages that MMR will later rank and diversify.
- Purpose: To produce chunks where internal content is semantically cohesive, improving the quality of retrieved text for language models.
- Contrast with MMR: Chunking creates the items; MMR selects and orders a subset of those items for final output.
Hybrid Search
A retrieval strategy that MMR can be applied to post-fusion. Hybrid search combines results from:
- Sparse retrieval (e.g., BM25) for exact keyword matching.
- Dense retrieval (e.g., vector similarity) for semantic understanding.
The combined, ranked list is then an ideal candidate for MMR processing to reduce redundancy among the top results from both retrieval methods, ensuring the final set is both relevant and diverse.
Query Expansion
A technique often used before retrieval to improve recall, which changes the input to MMR. Query expansion augments a user's original search query with additional related terms or phrases.
- Effect on MMR: By retrieving a broader set of initially relevant documents, the pool for MMR's diversity selection becomes richer and potentially more varied.
- Synergy: Query expansion casts a wider net; MMR refines the catch to avoid repetitive results.
Dense Vector Index
The core infrastructure that enables the similarity calculations MMR relies on. A dense vector index (e.g., in a vector database) stores high-dimensional embeddings of text chunks.
- MMR's Dependency: To compute the "marginal relevance" of a new chunk, MMR must efficiently find its similarity to already-selected chunks. This requires fast Approximate Nearest Neighbor (ANN) search provided by indices like HNSW or IVF.
- Performance: The efficiency of the underlying index directly impacts the latency of an MMR reranking step.
Reciprocal Rank Fusion (RRF)
An alternative ranking method to MMR for combining multiple result lists. RRF is a simple, score-free method used in hybrid search:
- It takes ranked lists from different retrievers (e.g., keyword and vector).
- It assigns a score based on the reciprocal of the sum of each item's rank across lists.
- It reranks all items based on this fused score.
Key Difference from MMR: RRF focuses on aggregating rankings from multiple sources but does not explicitly optimize for diversity within the final list, which is MMR's primary objective.
Information Retrieval (IR) Evaluation
The framework for measuring algorithms like MMR. Key metrics assess the trade-off MMR manages:
- Precision@K: Measures the fraction of relevant items in the top K results. MMR aims to maintain high precision while introducing diversity.
- Recall: Measures the fraction of all relevant items retrieved. MMR typically operates on a pre-retrieved set, so it doesn't directly affect recall.
- Novelty & Diversity: Metrics like Alpha-nDCG or Intent-Aware Metrics explicitly measure the diversity of subtopics covered in a result set, which is what MMR is designed to maximize.

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