pub struct MmrConfig {
pub lambda: f32,
pub top_k: usize,
}Expand description
Maximal Marginal Relevance (MMR) configuration.
§Background
MMR was introduced by Carbonell & Goldstein (1998) to address a fundamental tension in information retrieval: relevance vs. diversity.
Traditional ranking optimizes relevance only, leading to redundant results. If the top-5 results are all about the same aspect of a topic, the user gains little from results 2-5.
MMR balances:
- Relevance: How well does this document match the query?
- Diversity: How different is this document from already-selected ones?
§Historical Context
| Year | Development |
|---|---|
| 1998 | MMR introduced (Carbonell & Goldstein) |
| 2008 | xQuAD extends MMR with explicit subtopics |
| 2012 | PM-2 proportional model |
| 2020s | MMR widely used in RAG to reduce redundancy |
MMR remains the go-to algorithm for diversity because:
- Simple to implement and explain
- Single tunable parameter (λ)
- Works with any similarity function
- Greedy selection is fast
§Mathematical Formulation
At each step, select the document that maximizes:
MMR(d) = λ · Sim(d, q) - (1-λ) · max_{s∈S} Sim(d, s)Where:
dis a candidate documentqis the querySis the set of already-selected documentsSim(d, q)is relevance (query-document similarity)max_{s∈S} Sim(d, s)is redundancy (max similarity to any selected doc)λin[0,1]balances relevance and diversity
§The λ Parameter
| λ Value | Effect |
|---|---|
| λ = 1.0 | Pure relevance (standard ranking) |
| λ = 0.7 | Mild diversity (typical for search) |
| λ = 0.5 | Balanced relevance/diversity |
| λ = 0.3 | Strong diversity preference |
| λ = 0.0 | Pure diversity (maximally spread results) |
§Computational Complexity
- Naïve: O(k·n·|S|) where k=results wanted, n=candidates, |S|=selected set
- In practice: O(k·n²) worst case, often much better with pruning
§Reference
Carbonell & Goldstein, “The Use of MMR, Diversity-Based Reranking for Reordering Documents and Producing Summaries”, SIGIR 1998.
Fields§
§lambda: f32Balance parameter λ ∈ [0,1].
- λ = 1.0: pure relevance (no diversity)
- λ = 0.5: balanced
- λ = 0.0: pure diversity
top_k: usizeMaximum results to return.
Implementations§
Trait Implementations§
impl Copy for MmrConfig
impl StructuralPartialEq for MmrConfig
Auto Trait Implementations§
impl Freeze for MmrConfig
impl RefUnwindSafe for MmrConfig
impl Send for MmrConfig
impl Sync for MmrConfig
impl Unpin for MmrConfig
impl UnsafeUnpin for MmrConfig
impl UnwindSafe for MmrConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more