Compute Maximal Marginal Relevance (MMR).
MMR is a technique used to select documents that are both relevant to the query and diverse among themselves. This function returns the indices of the top-k embeddings that maximize the marginal relevance.
maximal_marginal_relevance(
query_embedding: np.ndarray,
embedding_list: list,
lambda_mult: float = 0.5,
k: int = 4
) -> List[int]Notes:
The Maximal Marginal Relevance (MMR) is computed using the following formula:
MMR = argmax_{D_i ∈ R \ S} [λ * Sim(D_i, Q) - (1 - λ) * max_{D_j ∈ S} Sim(D_i, D_j)]
where:
| Name | Type | Description |
|---|---|---|
query_embedding* | np.ndarray | The embedding vector of the query. |
embedding_list* | list of np.ndarray | A list containing the embedding vectors of the candidate documents. |
lambda_mult | float | Default: 0.5The trade-off parameter between relevance and diversity. Defaults to 0.5. |
k | int | Default: 4The number of embeddings to select. Defaults to 4. |