Maximum Marginal Relevance
Maximum Marginal Relevance (MMR) is a re-ranking method that balances how relevant a result is against how different it is from results already chosen.
Overview
It matters because pure relevance ranking often returns near-duplicate passages that waste space in a RAG context window.
Deep Dive
When a search system scores documents purely by relevance to a query, the top results are frequently redundant — five passages all saying the same thing. MMR, introduced by Carbonell and Goldstein in 1998, fixes this by selecting results one at a time. At each step it picks the candidate that maximizes a weighted blend: lambda times its relevance to the query, minus (1 minus lambda) times its maximum similarity to anything already selected. A lambda near 1 favors pure relevance; near 0 it favors diversity. In retrieval-augmented generation, MMR is popular for fetching a varied set of chunks so the language model sees complementary evidence rather than the same fact repeated, improving coverage without enlarging the context.
Technical Insight
MMR is a greedy, iterative algorithm. Both relevance and inter-document similarity are usually computed as cosine similarity between embedding vectors. The scoring formula is: MMR = argmax over remaining docs of [ lambda * sim(doc, query) - (1 - lambda) * max sim(doc, selected) ]. Because it re-evaluates against the growing selected set each round, it is order-dependent and runs in roughly O(k*n) similarity comparisons for k picks from n candidates.
Strategic Impact
Speed and scale
Language workflows can move faster without sacrificing consistency.
Access and reach
It expands access across languages and communication styles.
Clearer decisions
Teams can spend more time on judgment while automation handles repetition.
The Future of Maximum Marginal Relevance
MMR remains a lightweight default in vector-database clients like LangChain and Chroma, where it is offered as a one-line retrieval mode. Future systems increasingly pair it with learned diversity objectives, cluster-based selection, and cross-encoder rerankers that judge novelty more semantically than cosine distance. As context windows grow, the emphasis shifts from saving space to curating genuinely complementary evidence, keeping diversity-aware selection like MMR relevant even when raw capacity is abundant.
Real-World Implementation
A RAG chatbot uses MMR retrieval so its top 5 chunks cover different aspects of a policy instead of five paraphrases of the same paragraph.
A research summarization tool applies MMR to pick passages that minimize overlap, producing a broader, less repetitive summary.
A news aggregator ranks articles with MMR to show varied coverage of an event rather than ten outlets repeating one wire story.
LangChain's vector store retriever exposes search_type='mmr' with a fetch_k and lambda_mult to diversify returned documents.
Risks & Guardrails
Hallucinated facts can quietly enter reports, support flows, or research outputs.
Prompt sensitivity can create inconsistent results across similar requests.
Sensitive text data may be exposed if access controls are weak.
Implementation Roadmap
Define output format, tone, and quality standards before rollout.
Ground responses with trusted sources whenever accuracy matters.
Keep a human review checkpoint for high-stakes outputs.
Track failure patterns and retrain prompts or workflows regularly.
Keep Exploring
Free newsletter
Keep up with AI in 3 minutes a day
One short email each weekday with the three AI stories that actually matter. Free forever, no ads.
One email each weekday. Unsubscribe in one click. We never sell or share your address.
Test yourself
Take the Maximum Marginal Relevance quiz
Instant feedback on every answer, and a shareable certificate with a verifiable ID once you pass a course.
Support free AI education. AI Understanding is a 501(c)(3) nonprofit — no ads, no paywall, ever. Make a donation
Next guide
Non-Maximum Suppression
Frequently asked questions
What is Maximum Marginal Relevance?
Maximum Marginal Relevance (MMR) is a re-ranking method that balances how relevant a result is against how different it is from results already chosen. It matters because pure relevance ranking often returns near-duplicate passages that waste space in a RAG context window.
What is the primary problem MMR is designed to solve?
MMR addresses the tendency of relevance-only ranking to surface many results that say essentially the same thing, by rewarding novelty.
In the MMR formula, what does a lambda value close to 1 emphasize?
Lambda weights relevance; near 1 the relevance term dominates, while near 0 the diversity (low-similarity) term dominates.
How does MMR select its results?
MMR is a greedy iterative method: each pick maximizes relevance minus the maximum similarity to the items already chosen.
What similarity measure is most commonly used inside MMR for text embeddings?
Cosine similarity between embedding vectors is the standard choice for both query relevance and inter-document comparison in MMR.
Why is MMR especially useful in retrieval-augmented generation (RAG)?
By diversifying retrieved chunks, MMR helps the model see varied evidence rather than the same fact repeated, improving coverage.