Inferensys

Glossary

Maximum Marginal Relevance (MMR)

A re-ranking algorithm that selects documents by balancing their relevance to the query against their similarity to already-selected documents, reducing redundancy in the final retrieved 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.
RE-RANKING ALGORITHM

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.

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.

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.

Algorithm Mechanics

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.

01

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.

02

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.

03

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.

04

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.

05

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.

06

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.

RE-RANKING ALGORITHM COMPARISON

MMR vs. Other Re-Ranking Methods

A technical comparison of Maximum Marginal Relevance against alternative re-ranking strategies used in retrieval-augmented generation pipelines.

FeatureMaximum Marginal Relevance (MMR)Cross-Encoder Re-rankingReciprocal 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

MMR EXPLAINED

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.

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.