Skip to main content

MmrConfig

Struct MmrConfig 

Source
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

YearDevelopment
1998MMR introduced (Carbonell & Goldstein)
2008xQuAD extends MMR with explicit subtopics
2012PM-2 proportional model
2020sMMR widely used in RAG to reduce redundancy

MMR remains the go-to algorithm for diversity because:

  1. Simple to implement and explain
  2. Single tunable parameter (λ)
  3. Works with any similarity function
  4. 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:

  • d is a candidate document
  • q is the query
  • S is the set of already-selected documents
  • Sim(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

λ ValueEffect
λ = 1.0Pure relevance (standard ranking)
λ = 0.7Mild diversity (typical for search)
λ = 0.5Balanced relevance/diversity
λ = 0.3Strong diversity preference
λ = 0.0Pure 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: f32

Balance parameter λ ∈ [0,1].

  • λ = 1.0: pure relevance (no diversity)
  • λ = 0.5: balanced
  • λ = 0.0: pure diversity
§top_k: usize

Maximum results to return.

Implementations§

Source§

impl MmrConfig

Source

pub fn new(lambda: f32) -> Self

Create MMR config with specified lambda.

§Arguments
  • lambda: Balance between relevance and diversity. Valid: [0.0, 1.0].
§Panics

Panics if lambda is outside [0.0, 1.0].

Source

pub const fn with_top_k(self, top_k: usize) -> Self

Set the number of results to return.

Trait Implementations§

Source§

impl Clone for MmrConfig

Source§

fn clone(&self) -> MmrConfig

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MmrConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for MmrConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for MmrConfig

Source§

fn eq(&self, other: &MmrConfig) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for MmrConfig

Source§

impl StructuralPartialEq for MmrConfig

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.