weighted_sum_ranking#

langchain_postgres.v2.hybrid_search_config.weighted_sum_ranking(
primary_search_results: Sequence[RowMapping],
secondary_search_results: Sequence[RowMapping],
primary_results_weight: float = 0.5,
secondary_results_weight: float = 0.5,
fetch_top_k: int = 4,
) → Sequence[dict[str, Any]][source]#

Ranks documents using a weighted sum of scores from two sources.

Parameters:
  • primary_search_results (Sequence[RowMapping]) – A list of (document, distance) tuples from the primary search.

  • secondary_search_results (Sequence[RowMapping]) – A list of (document, distance) tuples from the secondary search.

  • primary_results_weight (float) – The weight for the primary source’s scores. Defaults to 0.5.

  • secondary_results_weight (float) – The weight for the secondary source’s scores. Defaults to 0.5.

  • fetch_top_k (int) – The number of documents to fetch after merging the results. Defaults to 4.

Returns:

A list of (document, distance) tuples, sorted by weighted_score in descending order.

Return type:

Sequence[dict[str, Any]]