Skip to main content

MultiQueryEmbeddingRetriever

Retrieve documents using multiple text queries in parallel with an embedding-based retriever.

Basic Information

  • Type: haystack.components.retrievers.multi_query_embedding_retriever.MultiQueryEmbeddingRetriever
  • Components it can connect with:
    • QueryExpander: Receives the queries from the QueryExpander component.
    • Ranker, DocumentJoiner: Sends the documents to the Ranker and DocumentJoiner components

Inputs

ParameterTypeDescription
queriesList[str]List of text queries to process.
retriever_kwargsOptional[Dict[str, Any]]Optional dictionary of arguments for the retriever.

Outputs

ParameterTypeDescription
documentsList[Document]List of retrieved documents sorted by relevance score, deduplicated by content.

Overview

MultiQueryEmbeddingRetriever processes multiple text queries in parallel using an underlying embedding-based retriever. It first converts each text query to embeddings using a QueryEmbedder, then uses an embedding-based retriever to find relevant documents for each query.

The results from all queries are combined, deduplicated based on document content, and sorted by relevance score. This approach improves retrieval recall by finding documents relevant to multiple query variations.

This component works best with QueryExpander to enhance the retrieval process. By retrieving documents for multiple semantically similar queries, it helps find relevant documents that might be missed with a single query formulation.

The component requires:

  • A QueryEmbedder that converts text to embeddings
  • An embedding-based retriever that retrieves documents using embeddings

Usage example

Here's an example that combines QueryExpander with MultiQueryEmbeddingRetriever. You could then send the retrieved documents to a Ranker or DocumentJoiner component to combine the results:

components:
query_expander:
type: haystack.components.query.query_expander.QueryExpander
init_parameters:
n_expansions: 3
include_original_query: true

chat_generator:
type: haystack_integrations.components.generators.anthropic.chat.chat_generator.AnthropicChatGenerator
init_parameters: {}
multi_query_retriever:
type: haystack.components.retrievers.multi_query_embedding_retriever.MultiQueryEmbeddingRetriever
init_parameters:
query_embedder:
type: haystack.components.embedders.sentence_transformers_text_embedder.SentenceTransformersTextEmbedder
init_parameters:
model: sentence-transformers/all-MiniLM-L6-v2
retriever:
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
top_k: 5
max_workers: 3

connections:
- sender: query_expander.queries
receiver: multi_query_retriever.queries

max_runs_per_component: 100

metadata: {}

inputs:
query:
- query_expander.query

Parameters

Init parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
retrieverEmbeddingRetrieverThe embedding-based retriever to use for document retrieval. Must implement the EmbeddingRetriever protocol.
query_embedderTextEmbedderThe query embedder to convert text queries to embeddings. Must implement the TextEmbedder protocol.
max_workersintthreeMaximum number of worker threads for parallel processing.

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
queriesList[str]List of text queries to process.
retriever_kwargsOptional[Dict[str, Any]]NoneOptional dictionary of arguments to pass to the retriever's run method (for example, filters, top_k).