# weighted_sum_ranking

> **Function** in `langchain_postgres`

📖 [View in docs](https://reference.langchain.com/python/langchain-postgres/v2/hybrid_search_config/weighted_sum_ranking)

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

## Signature

```python
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,
    **kwargs: Any = {},
) -> Sequence[dict[str, Any]]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `primary_search_results` | `Sequence[RowMapping]` | Yes | A list of (document, distance) tuples from the primary search. |
| `secondary_search_results` | `Sequence[RowMapping]` | Yes | A list of (document, distance) tuples from the secondary search. |
| `primary_results_weight` | `float` | No | The weight for the primary source's scores. Defaults to 0.5. (default: `0.5`) |
| `secondary_results_weight` | `float` | No | The weight for the secondary source's scores. Defaults to 0.5. (default: `0.5`) |
| `fetch_top_k` | `int` | No | The number of documents to fetch after merging the results. Defaults to 4. (default: `4`) |

## Returns

`Sequence[dict[str, Any]]`

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

---

[View source on GitHub](https://github.com/langchain-ai/langchain-postgres/blob/9d819182da7e3fb1b815e6c9a6b7c2cd1eb4bc0e/langchain_postgres/v2/hybrid_search_config.py#L42)