reciprocal_rank_fusion#

langchain_postgres.v2.hybrid_search_config.reciprocal_rank_fusion(
primary_search_results: Sequence[RowMapping],
secondary_search_results: Sequence[RowMapping],
rrf_k: float = 60,
fetch_top_k: int = 4,
) Sequence[dict[str, Any]][source]#

Ranks documents using Reciprocal Rank Fusion (RRF) 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.

  • rrf_k (float) – The RRF parameter k. Defaults to 60.

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

Returns:

A list of (document_id, rrf_score) tuples, sorted by rrf_score in descending order.

Return type:

Sequence[dict[str, Any]]