Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

OpenSearchHybridRetriever

Retrieve documents from an OpenSearchDocumentStore using hybrid search, combining BM25 keyword-based retrieval with dense embedding retrieval. Use this super-component in query pipelines to get the benefits of both lexical and semantic search.

Embedding Models in Query Pipelines and Indexes

The embedding model you use to embed documents in your indexing pipeline must be the same as the embedding model you use to embed the query in your query pipeline.

This means the embedders for your indexing and query pipelines must match. For example, if you use CohereDocumentEmbedder to embed your documents, you should use CohereTextEmbedder with the same model to embed your queries.

Key Features

  • Combines BM25 keyword search and embedding-based vector search in a single component.
  • Uses Reciprocal Rank Fusion (RRF) by default to merge results, with configurable join modes and weights.
  • Exposes separate top_k and filter settings for each retrieval method.
  • Built as a Haystack super_component — wraps an internal pipeline with OpenSearchBM25Retriever, a text embedder, OpenSearchEmbeddingRetriever, and a DocumentJoiner.

Configuration

Add Workspace-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Workspace>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in the current workspace.

Add Organization-Level Integration

  1. Click your profile icon and choose Settings.
  2. Go to Organization>Integrations.
  3. Find the provider you want to connect and click Connect next to them.
  4. Enter the API key and any other required details.
  5. Click Connect. You can use this integration in pipelines and indexes in all workspaces in the current organization.
  1. First, configure an OpenSearchDocumentStore with both BM25 and embedding support.
  2. Drag the OpenSearchHybridRetriever component onto the canvas from the Component Library.
  3. Set the embedder parameter to a text embedder component (for example, SentenceTransformersTextEmbedder).
  4. Adjust top_k_bm25 and top_k_embedding to control how many candidates each retriever returns before merging.

Connections

OpenSearchHybridRetriever receives a text query string as input. It outputs a list of Document objects merged from both BM25 and embedding results.

Source Code

To check this component's source code, open open_search_hybrid_retriever.py in the Haystack Core Integrations repository.

Usage Examples

Basic Configuration

  OpenSearchHybridRetriever:
type: haystack_integrations.components.retrievers.opensearch.open_search_hybrid_retriever.OpenSearchHybridRetriever
init_parameters:
document_store: OpenSearchDocumentStore
embedder:
type: haystack_integrations.components.embedders.sentence_transformers.sentence_transformers_text_embedder.SentenceTransformersTextEmbedder
init_parameters:
model: sentence-transformers/all-MiniLM-L6-v2
top_k_bm25: 10
top_k_embedding: 10
join_mode: reciprocal_rank_fusion

Parameters

Inputs

ParameterTypeDescription
querystrThe text query to search for.
filters_bm25Optional[Dict[str, Any]]Filters to apply to the BM25 retriever.
filters_embeddingOptional[Dict[str, Any]]Filters to apply to the embedding retriever.
top_k_bm25Optional[int]Maximum number of BM25 results to return. Overrides the init-time value.
top_k_embeddingOptional[int]Maximum number of embedding results to return. Overrides the init-time value.

Outputs

ParameterTypeDescription
documentsList[Document]A merged list of documents from both BM25 and embedding retrieval.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
document_storeOpenSearchDocumentStoreThe OpenSearch document store to retrieve documents from.
embedderTextEmbedderA text embedder component used to embed the query for vector search.
filters_bm25Optional[Dict[str, Any]]NoneDefault filters to apply to BM25 retrieval.
fuzzinessint or str0Fuzziness setting for BM25 keyword matching.
top_k_bm25int10Maximum number of BM25 candidates to retrieve.
scale_scoreboolFalseWhether to scale BM25 scores to a [0, 1] range.
all_terms_must_matchboolFalseWhether all query terms must appear in a document for BM25 matching.
filter_policy_bm25FilterPolicyFilterPolicy.REPLACEFilter policy for BM25 retrieval.
custom_query_bm25Optional[Dict[str, Any]]NoneA custom OpenSearch query for BM25 retrieval.
filters_embeddingOptional[Dict[str, Any]]NoneDefault filters to apply to embedding retrieval.
top_k_embeddingint10Maximum number of embedding candidates to retrieve.
filter_policy_embeddingFilterPolicyFilterPolicy.REPLACEFilter policy for embedding retrieval.
custom_query_embeddingOptional[Dict[str, Any]]NoneA custom OpenSearch query for embedding retrieval.
join_modeJoinModeJoinMode.RECIPROCAL_RANK_FUSIONHow to merge results from BM25 and embedding retrievers.
weightsOptional[List[float]]NoneWeights for each retriever when merging results.
top_kOptional[int]NoneMaximum number of documents to return after merging.
sort_by_scoreboolTrueWhether to sort merged results by score.

Run Method Parameters

These are the parameters you can configure for the component's run() method. This means you can pass these parameters at query time through the API, in Playground, or when running a job. For details, see Modify Pipeline Parameters at Query Time.

ParameterTypeDefaultDescription
querystrThe text query to search for.
filters_bm25Optional[Dict[str, Any]]NoneRuntime filters for BM25 retrieval.
filters_embeddingOptional[Dict[str, Any]]NoneRuntime filters for embedding retrieval.
top_k_bm25Optional[int]NoneMaximum BM25 results. Overrides the init-time value.
top_k_embeddingOptional[int]NoneMaximum embedding results. Overrides the init-time value.