Skip to main content
MMR (Maximal Marginal Relevance) balances relevance with diversity by penalizing documents too similar to those already selected. The result set covers more aspects of a topic instead of repeating similar content.

How it works

MMR iteratively selects documents by balancing query relevance against redundancy with already-selected documents.

MMR algorithm

MMR iteratively selects documents by scoring each candidate with:
Where:
  • λ (lambda_param) - Trade-off between relevance and diversity (0.0-1.0)
  • sim(d, query) - Cosine similarity between document and query embeddings
  • max_sim(d, selected) - Maximum similarity to any already-selected document

Selection process

  1. First document - Select most relevant to query
  2. Iterative selection - For remaining slots:
    • Calculate relevance to query for each candidate
    • Calculate redundancy (max similarity to selected docs)
    • Compute MMR score with lambda weighting
    • Select document with highest MMR score
  3. Repeat - Until k documents selected

Lambda parameter guidelines

float
Controls the relevance-diversity trade-off:
  • λ = 1.0 - Pure relevance ranking (no diversity penalty)
  • λ = 0.7-0.8 - Emphasize relevance, mild diversity (recommended for precision)
  • λ = 0.5 - Balanced relevance and diversity (good default)
  • λ = 0.3-0.4 - Emphasize diversity (recommended for exploratory search)
  • λ = 0.0 - Pure diversity (minimum redundancy, ignores relevance)

Key features

  • Tune relevance vs diversity to fit the task
  • Uses cosine similarity for both relevance and diversity scoring
  • Particularly useful for summarization and exploratory search
  • Greedy algorithm ensures efficiency

Implementation

Use cases

When users need to understand different aspects of a topic:

Multi-document summarization

Provide diverse context to LLMs:

Reducing near-duplicates

When search returns many similar results:
When relevance is critical:

Lambda parameter tuning

Task-specific recommendations

Tuning guidelines

1

Start with default

Begin with lambda_param=0.5 (balanced)
2

Evaluate results

Check for redundancy or missing relevant docs
3

Adjust based on metrics

  • Too much redundancy? Decrease lambda (more diversity)
  • Missing relevant results? Increase lambda (more relevance)
4

A/B test

Compare user engagement across lambda values

Example with full pipeline

Performance characteristics

Time complexity

  • First selection: O(n) to find most relevant
  • Subsequent selections: O((k-1) × n) for k selections from n candidates
  • Overall: O(k × n)
For typical values (k=10, n=100), this is very fast (~ms).

Space complexity

  • O(n × d) for storing embeddings (n docs, d dimensions)
  • Cosine similarity computed on-demand

Optimization tips

Pre-compute and cache embeddings for retrieved documents to avoid repeated embedding calls. Only re-embed when document content changes.

Comparison with other diversity methods

Integration with diversity filtering

MMR is one of the diversity methods available in the diversity filtering pipeline:
See Diversity filtering for more details.

Diversity filtering

Complete diversity pipeline with MMR and clustering

Semantic search

Initial retrieval before MMR

Reranking

Cross-encoder scoring alternative

Contextual compression

Reduce retrieved context