But I want to use MMR (Minimal Marginal Relevance), instead of similarity_search. Can someone please point out how I can do that? The retriever I am using is:
MMR (Maximal Marginal Relevance) is a reranking algorithm that selects items iteratively to balance:
relevance to the query, and
non-redundancy with already selected items.
Formally, at each step it chooses: argmax_i [ Ξ» * sim(query, doc_i) β (1 β Ξ») * max_j sim(doc_i, doc_j) ]
where Ξ» β [0,1] controls the tradeoff between relevance and diversity.
MMR does not produce calibrated or comparable βrelevance scores.β It outputs an ordered list of k items. Any intermediate value computed during selection is transient and not meaningful across queries. Implementations typically return the base similarity scores (e.g., cosine similarity) from the vector store.
Possible usage to get scores:
Retrieve a larger candidate pool using base similarity scores.
(Optionally) filter by a score threshold.
Apply MMR to reorder and return the top-k items.
If you need scores, attach the underlying similarity scores; MMR is designed for selection order, not for scoring.