HybridSearchConfig#
-
class langchain_postgres.v2.hybrid_search_config.HybridSearchConfig(tsv_column: str | None = '', tsv_lang: str | None = 'pg_catalog.english', fts_query: str | None = '', fusion_function: ~typing.Callable[[~typing.Sequence[~sqlalchemy.engine.row.RowMapping], ~typing.Sequence[~sqlalchemy.engine.row.RowMapping], ~typing.Any], ~typing.Sequence[~typing.Any]] =
weighted_sum_ranking>, fusion_function_parameters: dict[str, ~typing.Any] = )[source]#, primary_top_k: int = 4, secondary_top_k: int = 4, index_name: str = 'langchain_tsv_index', index_type: str = 'GIN' AlloyDB Vector Store Hybrid Search Config.
Queries might be slow if the hybrid search column does not exist. For best hybrid search performance, consider creating a TSV column and adding GIN index.
Attributes
fts_query
index_name
index_type
primary_top_k
secondary_top_k
tsv_column
tsv_lang
Methods
__init__
([tsv_column, tsv_lang, fts_query, ...])fusion_function
(secondary_search_results[, ...])Ranks documents using a weighted sum of scores from two sources.
- Parameters:
tsv_column (str | None)
tsv_lang (str | None)
fts_query (str | None)
fusion_function (Callable[[Sequence[RowMapping], Sequence[RowMapping], Any], Sequence[Any]])
fusion_function_parameters (dict[str, Any])
primary_top_k (int)
secondary_top_k (int)
index_name (str)
index_type (str)
-
__init__(tsv_column: str | None = '', tsv_lang: str | None = 'pg_catalog.english', fts_query: str | None = '', fusion_function: ~typing.Callable[[~typing.Sequence[~sqlalchemy.engine.row.RowMapping], ~typing.Sequence[~sqlalchemy.engine.row.RowMapping], ~typing.Any], ~typing.Sequence[~typing.Any]] =
weighted_sum_ranking>, fusion_function_parameters: dict[str, ~typing.Any] = ) None #, primary_top_k: int = 4, secondary_top_k: int = 4, index_name: str = 'langchain_tsv_index', index_type: str = 'GIN' - Parameters:
tsv_column (str | None)
tsv_lang (str | None)
fts_query (str | None)
fusion_function (Callable[[Sequence[RowMapping], Sequence[RowMapping], Any], Sequence[Any]])
fusion_function_parameters (dict[str, Any])
primary_top_k (int)
secondary_top_k (int)
index_name (str)
index_type (str)
- Return type:
None
- fusion_function(
- secondary_search_results: Sequence[RowMapping],
- primary_results_weight: float = 0.5,
- secondary_results_weight: float = 0.5,
- fetch_top_k: int = 4,
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]]