maximal_marginal_relevance#

langchain_core.vectorstores.utils.maximal_marginal_relevance(query_embedding: np.ndarray, embedding_list: list, lambda_mult: float = 0.5, k: int = 4) List[int][source]#

Calculate maximal marginal relevance.

Parameters:
  • query_embedding (np.ndarray) – The query embedding.

  • embedding_list (list) – A list of embeddings.

  • lambda_mult (float) – The lambda parameter for MMR. Default is 0.5.

  • k (int) – The number of embeddings to return. Default is 4.

Returns:

A list of indices of the embeddings to return.

Raises:

ImportError – If numpy is not installed.

Return type:

List[int]