> ## Documentation Index
> Fetch the complete documentation index at: https://docs.camel-ai.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Camel.retrievers.hybrid retrival

<a id="camel.retrievers.hybrid_retrival" />

<a id="camel.retrievers.hybrid_retrival.HybridRetriever" />

## HybridRetriever

```python theme={"system"}
class HybridRetriever(BaseRetriever):
```

<a id="camel.retrievers.hybrid_retrival.HybridRetriever.__init__" />

### **init**

```python theme={"system"}
def __init__(
    self,
    embedding_model: Optional[BaseEmbedding] = None,
    vector_storage: Optional[BaseVectorStorage] = None
):
```

Initializes the HybridRetriever with optional embedding model and
vector storage.

**Parameters:**

* **embedding\_model** (Optional\[BaseEmbedding]): An optional embedding model used by the VectorRetriever. Defaults to None.
* **vector\_storage** (Optional\[BaseVectorStorage]): An optional vector storage used by the VectorRetriever. Defaults to None.

<a id="camel.retrievers.hybrid_retrival.HybridRetriever.process" />

### process

```python theme={"system"}
def process(self, content_input_path: str):
```

Processes the content input path for both vector and BM25
retrievers.

**Parameters:**

* **content\_input\_path** (str): File path or URL of the content to be processed.

<a id="camel.retrievers.hybrid_retrival.HybridRetriever._sort_rrf_scores" />

### \_sort\_rrf\_scores

```python theme={"system"}
def _sort_rrf_scores(
    self,
    vector_retriever_results: List[Dict[str, Any]],
    bm25_retriever_results: List[Dict[str, Any]],
    top_k: int,
    vector_weight: float,
    bm25_weight: float,
    rank_smoothing_factor: float
):
```

Sorts and combines results from vector and BM25 retrievers using
Reciprocal Rank Fusion (RRF).

**Parameters:**

* **vector\_retriever\_results**: A list of dictionaries containing the results from the vector retriever, where each dictionary contains a 'text' entry.
* **bm25\_retriever\_results**: A list of dictionaries containing the results from the BM25 retriever, where each dictionary contains a 'text' entry.
* **top\_k**: The number of top results to return after sorting by RRF score.
* **vector\_weight**: The weight to assign to the vector retriever results in the RRF calculation.
* **bm25\_weight**: The weight to assign to the BM25 retriever results in the RRF calculation.
* **rank\_smoothing\_factor**: A hyperparameter for the RRF calculation that helps smooth the rank positions.

**Returns:**

List\[Dict\[str, Union\[str, float]]]: A list of dictionaries
representing the sorted results. Each dictionary contains the
'text'from the retrieved items and their corresponding 'rrf\_score'.

<a id="camel.retrievers.hybrid_retrival.HybridRetriever.query" />

### query

```python theme={"system"}
def query(
    self,
    query: str,
    top_k: int = 20,
    vector_weight: float = 0.8,
    bm25_weight: float = 0.2,
    rank_smoothing_factor: int = 60,
    vector_retriever_top_k: int = 50,
    vector_retriever_similarity_threshold: float = 0.5,
    bm25_retriever_top_k: int = 50,
    return_detailed_info: bool = False
):
```

Executes a hybrid retrieval query using both vector and BM25
retrievers.

**Parameters:**

* **query** (str): The search query.
* **top\_k** (int): Number of top results to return (default 20).
* **vector\_weight** (float): Weight for vector retriever results in RRF.
* **bm25\_weight** (float): Weight for BM25 retriever results in RRF.
* **rank\_smoothing\_factor** (int): RRF hyperparameter for rank smoothing.
* **vector\_retriever\_top\_k** (int): Top results from vector retriever.
* **vector\_retriever\_similarity\_threshold** (float): Similarity threshold for vector retriever.
* **bm25\_retriever\_top\_k** (int): Top results from BM25 retriever.
* **return\_detailed\_info** (bool): Return detailed info if True.

**Returns:**

Union\[
dict\[str, Sequence\[Collection\[str]]],
dict\[str, Sequence\[Union\[str, float]]]
]: By default, returns only the text information. If
`return_detailed_info` is `True`, return detailed information
including rrf scores.
