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
ParameterTypeDefaultDescription
lambda_multfloat0.5Weight between relevance and diversity, from 0.0 to 1.0. 1.0 ranks by relevance alone and 0.0 by difference alone.
candidate_multiplierint5Candidates Knowledge fetches per requested result.
max_candidatesint100Ceiling on the candidate fetch. It never reduces the fetch below max_results.
top_nOptional[int]NoneMaximum 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.