MMR Reranker
MMRReranker selects search results that are relevant to the query and different from each other using Maximal Marginal Relevance.
MMRReranker selects search results that are relevant to the query and different from each other. Pass it to the reranker parameter of Knowledge. It requires embeddings on the search results. See Diversify Results With MMR.
from agno.knowledge.reranker.mmr import MMRReranker| Parameter | Type | Default | Description |
|---|---|---|---|
lambda_mult | float | 0.5 | Weight between relevance and diversity, from 0.0 to 1.0. 1.0 ranks by relevance alone and 0.0 by difference alone. |
candidate_multiplier | int | 5 | Candidates Knowledge fetches per requested result. |
max_candidates | int | 100 | Ceiling on the candidate fetch. It never reduces the fetch below max_results. |
top_n | Optional[int] | None | Maximum number of documents to select. Leave unset on Knowledge, which trims to max_results. |
Returned documents are copies with reranking_score set to the MMR score at the moment each was selected. The scores are not in descending order and can be negative.
MMR raises ValueError when a search result has no embedding, when no search result carries an embedder, or when the query and document embeddings have different dimensions.