MmrHelper#

class langchain_astradb.utils.mmr_helper.MmrHelper(k: int, query_embedding: list[float], lambda_mult: float = 0.5, score_threshold: float = -inf)[source]#

Helper for executing an MMR traversal query.

Parameters:
  • query_embedding (list[float]) – The embedding of the query to use for scoring.

  • lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.

  • score_threshold (float) – Only documents with a score greater than or equal this threshold will be chosen. Defaults to -infinity.

  • k (int)

Create a new Traversal MMR helper.

Attributes

Methods

__init__(k,Β query_embedding[,Β lambda_mult,Β ...])

Create a new Traversal MMR helper.

add_candidates(candidates)

Add candidates to the consideration set.

candidate_ids()

Return the IDs of the candidates.

pop_best()

Select and pop the best item being considered.

__init__(k: int, query_embedding: list[float], lambda_mult: float = 0.5, score_threshold: float = -inf) β†’ None[source]#

Create a new Traversal MMR helper.

Parameters:
  • k (int)

  • query_embedding (list[float])

  • lambda_mult (float)

  • score_threshold (float)

Return type:

None

add_candidates(candidates: dict[str, list[float]]) β†’ None[source]#

Add candidates to the consideration set.

Parameters:

candidates (dict[str, list[float]])

Return type:

None

candidate_ids() β†’ Iterable[str][source]#

Return the IDs of the candidates.

Return type:

Iterable[str]

pop_best() β†’ str | None[source]#

Select and pop the best item being considered.

Updates the consideration set based on it.

Returns:

A tuple containing the ID of the best item.

Return type:

str | None