# MongoDBAtlasHybridSearchRetriever

> **Class** in `langchain_mongodb`

📖 [View in docs](https://reference.langchain.com/python/langchain-mongodb/retrievers/hybrid_search/MongoDBAtlasHybridSearchRetriever)

Hybrid Search Retriever combines vector and full-text searches
weighting them the via Reciprocal Rank Fusion (RRF) algorithm.

Increasing the vector_penalty will reduce the importance on the vector search.
Increasing the fulltext_penalty will correspondingly reduce the fulltext score.
For more on the algorithm,see
https://learn.microsoft.com/en-us/azure/search/hybrid-search-ranking

## Signature

```python
MongoDBAtlasHybridSearchRetriever(
    self,
    *,
    vectorstore: MongoDBAtlasVectorSearch,
    search_index_name: str,
    k: int = 4,
    oversampling_factor: int = 10,
    pre_filter: Optional[Dict[str, Any]] = None,
    post_filter: Optional[List[Dict[str, Any]]] = None,
    vector_penalty: float = 60.0,
    fulltext_penalty: float = 60.0,
    vector_weight: float = 1.0,
    fulltext_weight: float = 1.0,
    show_embeddings: float = False,
    top_k: Optional[int] = None,
    auto_create_index: bool = True,
    auto_index_timeout: int = 15,
    **kwargs: Any = {},
)
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `vectorstore` | `MongoDBAtlasVectorSearch` | Yes | MongoDBAtlasVectorSearch instance. |
| `search_index_name` | `str` | Yes | Atlas Search Index (full-text) name. |
| `k` | `int` | No | Number of documents to return. Defaults to 4. (default: `4`) |
| `oversampling_factor` | `int` | No | This times k is the number of candidates chosen at each step. Defaults to 10. (default: `10`) |
| `pre_filter` | `Optional[Dict[str, Any]]` | No | (Optional) Any MQL match expression comparing an indexed field. (default: `None`) |
| `post_filter` | `Optional[List[Dict[str, Any]]]` | No | (Optional) Pipeline of MongoDB aggregation stages for postprocessing. (default: `None`) |
| `vector_penalty` | `float` | No | Penalty applied to vector search results in RRF: scores=1/(rank + penalty). Defaults to 60.0. (default: `60.0`) |
| `fulltext_penalty` | `float` | No | Penalty applied to full-text search results in RRF: scores=1/(rank + penalty). Defaults to 60.0. (default: `60.0`) |
| `vector_weight` | `float` | No | Weight applied to vector search results in RRF: score = weight * (1 / (rank + penalty + 1)). Defaults to 1.0. (default: `1.0`) |
| `fulltext_weight` | `float` | No | Weight applied to full-text search results in RRF: score = weight * (1 / (rank + penalty + 1)). Defaults to 1.0. (default: `1.0`) |
| `show_embeddings` | `float` | No | If true, returned Document metadata will include vectors. Defaults to False. (default: `False`) |
| `top_k` | `Optional[int]` | No | (Deprecated) Number of documents to return. Use k instead. (default: `None`) |
| `auto_create_index` | `bool` | No | Whether to automatically create the full-text search index if it does not exist. Defaults to True. (default: `True`) |
| `auto_index_timeout` | `int` | No | How long to wait for the automatic index creation to complete, in seconds. Defaults to 15. (default: `15`) |
| `vector_index_options` | `unknown` | Yes | Unused; kept for backward compatibility. Defaults to None. |
| `**kwargs` | `Any` | No | Additional keyword arguments. (default: `{}`) |

## Extends

- `BaseRetriever`

## Constructors

```python
__init__(
    self,
    *,
    vectorstore: MongoDBAtlasVectorSearch,
    search_index_name: str,
    k: int = 4,
    oversampling_factor: int = 10,
    pre_filter: Optional[Dict[str, Any]] = None,
    post_filter: Optional[List[Dict[str, Any]]] = None,
    vector_penalty: float = 60.0,
    fulltext_penalty: float = 60.0,
    vector_weight: float = 1.0,
    fulltext_weight: float = 1.0,
    show_embeddings: float = False,
    top_k: Optional[int] = None,
    auto_create_index: bool = True,
    auto_index_timeout: int = 15,
    **kwargs: Any = {},
) -> None
```

| Name | Type |
|------|------|
| `vectorstore` | `MongoDBAtlasVectorSearch` |
| `search_index_name` | `str` |
| `k` | `int` |
| `oversampling_factor` | `int` |
| `pre_filter` | `Optional[Dict[str, Any]]` |
| `post_filter` | `Optional[List[Dict[str, Any]]]` |
| `vector_penalty` | `float` |
| `fulltext_penalty` | `float` |
| `vector_weight` | `float` |
| `fulltext_weight` | `float` |
| `show_embeddings` | `float` |
| `top_k` | `Optional[int]` |
| `auto_create_index` | `bool` |
| `auto_index_timeout` | `int` |


## Properties

- `vectorstore`
- `search_index_name`
- `k`
- `oversampling_factor`
- `pre_filter`
- `post_filter`
- `vector_penalty`
- `fulltext_penalty`
- `vector_weight`
- `fulltext_weight`
- `show_embeddings`
- `top_k`
- `collection`

## Methods

- [`close()`](https://reference.langchain.com/python/langchain-mongodb/retrievers/hybrid_search/MongoDBAtlasHybridSearchRetriever/close)

---

[View source on GitHub](https://github.com/langchain-ai/langchain-mongodb/blob/edee54e78705190a78087e13013412a39d71a651/libs/langchain-mongodb/langchain_mongodb/retrievers/hybrid_search.py#L23)