MultiQueryTextRetriever
Retrieve documents using multiple text queries in parallel with a text-based retriever. The component retrieves documents for each query using a thread pool, then combines and deduplicates the results. This improves recall by finding documents relevant to multiple query variations.
Key Features
- Processes multiple queries in parallel using a text-based retriever (such as BM25).
- Deduplicates results based on document content across all queries.
- Sorts the combined results by relevance score.
- Configurable parallel processing with a thread pool.
- Designed to work with
QueryExpanderfor query expansion in keyword-based search.
Configuration
- Drag the
MultiQueryTextRetrievercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab, configure the underlying
retriever(a text-based retriever such asOpenSearchBM25Retriever). - Go to the Advanced tab to set
max_workersfor controlling parallel thread execution.
Connections
MultiQueryTextRetriever receives a list of queries through its queries input, typically from QueryExpander. It outputs a deduplicated documents list sorted by relevance score. Connect the documents output to a Ranker, DocumentJoiner, or directly to an LLM component.
Source Code
To check this component's source code, open multi_query_text_retriever.py in the Haystack repository.
Usage Examples
Basic Configuration
MultiQueryTextRetriever:
type: haystack.components.retrievers.multi_query_text_retriever.MultiQueryTextRetriever
init_parameters:
retriever:
type: haystack_integrations.components.retrievers.opensearch.bm25_retriever.OpenSearchBM25Retriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: default
Connections
This example shows how to perform retrieval with QueryExpander and MultiQueryTextRetriever. You can then send the retrieved documents to a Ranker or DocumentJoiner 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
Inputs
| Parameter | Type | Description |
|---|---|---|
queries | List[str] | List of text queries to process. |
retriever_kwargs | Optional[Dict[str, Any]] | Optional dictionary of arguments to pass to the retriever's run method. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | List of retrieved documents sorted by relevance score, deduplicated by content. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
retriever | TextRetriever | The text-based retriever to use for document retrieval. Must implement the TextRetriever protocol. | |
max_workers | int | 3 | Maximum 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
queries | List[str] | List of text queries to process. | |
retriever_kwargs | Optional[Dict[str, Any]] | None | Optional dictionary of arguments to pass to the retriever's run method (for example, filters, top_k). |
Related Information
Was this page helpful?