MmrReranker class final

Trades relevance against variety.

The redundancy problem

Retrieval ranks by similarity to the question, and near-duplicate passages are similar to the same questions. A changelog, a FAQ, a document that was re-published under a new title — all of them produce candidate lists whose top five entries are five copies of one fact, filling the prompt without adding anything.

Maximal marginal relevance picks greedily: at each step it selects the candidate maximising λ · relevance − (1 − λ) · similarity to what is already chosen. With lambda at 1 it is plain relevance ordering; lower values buy variety at the cost of some relevance. 0.7 is a sensible default.

It needs vectors

Similarity between candidates is measured on their embeddings, so the retriever must have been asked for them — VectorRetriever(includeVectors: true). Given results without vectors this re-ranker cannot do its job, and it says so rather than silently degrading to plain truncation.

Implemented types

Constructors

MmrReranker({required List<double>? vectorOf(RetrievedChunk result), double lambda = 0.7, String name = 'mmr'})
Creates a diversity-aware re-ranker.
const

Properties

hashCode int
The hash code for this object.
no setterinherited
lambda double
How strongly relevance is favoured over variety, from 0 to 1.
final
name String
A short name, used in events and traces.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
vectorOf List<double>? Function(RetrievedChunk result)
Supplies the embedding for a result, or null when there is none.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
rerank(String query, List<RetrievedChunk> results, {int topK = 4, AgenticContext? context}) Future<List<RetrievedChunk>>
Reorders results for query, keeping at most topK.
override
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
inherited