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

FastembedSparseTextEmbedder

Compute sparse text embeddings using Fastembed sparse models.

Key Features

  • Uses Fastembed sparse models such as SPLADE for sparse text embedding.
  • Outputs a sparse embedding that can be used for sparse retrieval.
  • Useful in hybrid search scenarios combining sparse and dense retrieval.
  • Must use the same sparse embedding model as FastembedSparseDocumentEmbedder used in the index.

Configuration

  1. Drag the FastembedSparseTextEmbedder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
  4. Go to the Advanced tab to configure additional settings such as parallel and model_kwargs.

Connections

FastembedSparseTextEmbedder receives a text string (the user query) as input. It outputs a sparse_embedding object. Connect its output to a sparse retriever to find matching documents. Use the same sparse embedding model as the one used to embed documents in the document store.

Source Code

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

Connections

FastembedSparseTextEmbedder accepts a text string as input. In a query pipeline, connect its text input to the query output of the Input component.

It outputs a SparseEmbedding. Connect its sparse_embedding output to the query_sparse_embedding input of a sparse retriever.

Usage Examples

Basic Configuration

  FastembedSparseTextEmbedder:
type: haystack_integrations.components.embedders.fastembed.fastembed_sparse_text_embedder.FastembedSparseTextEmbedder
init_parameters:
model: prithivida/Splade_PP_en_v1
progress_bar: true
local_files_only: false

This query pipeline uses FastembedSparseTextEmbedder for sparse retrieval:

components:
FastembedSparseTextEmbedder:
type: haystack_integrations.components.embedders.fastembed.fastembed_sparse_text_embedder.FastembedSparseTextEmbedder
init_parameters:
model: prithivida/Splade_PP_en_v1
cache_dir:
threads:
progress_bar: true
parallel:
local_files_only: false
model_kwargs:

bm25_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'
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
top_k: 20

ChatPromptBuilder:
type: haystack.components.builders.chat_prompt_builder.ChatPromptBuilder
init_parameters:
template:
- role: system
content: "You are a helpful assistant answering questions based on the provided documents."
- role: user
content: "Documents:\n{% for doc in documents %}\n{{ doc.content }}\n{% endfor %}\n\nQuestion: {{ query }}"

OpenAIChatGenerator:
type: haystack.components.generators.chat.openai.OpenAIChatGenerator
init_parameters:
api_key:
type: env_var
env_vars:
- OPENAI_API_KEY
strict: false
model: gpt-4o-mini

OutputAdapter:
type: haystack.components.converters.output_adapter.OutputAdapter
init_parameters:
template: '{{ replies[0] }}'
output_type: List[str]

answer_builder:
type: deepset_cloud_custom_nodes.augmenters.deepset_answer_builder.DeepsetAnswerBuilder
init_parameters:
reference_pattern: acm

connections:
- sender: bm25_retriever.documents
receiver: ChatPromptBuilder.documents
- sender: ChatPromptBuilder.prompt
receiver: OpenAIChatGenerator.messages
- sender: OpenAIChatGenerator.replies
receiver: OutputAdapter.replies
- sender: OutputAdapter.output
receiver: answer_builder.replies
- sender: bm25_retriever.documents
receiver: answer_builder.documents

inputs:
query:
- bm25_retriever.query
- ChatPromptBuilder.query
- answer_builder.query
filters:
- bm25_retriever.filters

outputs:
documents: bm25_retriever.documents
answers: answer_builder.answers

max_runs_per_component: 100

metadata: {}

Parameters

Inputs

ParameterTypeDefaultDescription
textstrA string to embed.

Outputs

ParameterTypeDefaultDescription
sparse_embeddingSparseEmbeddingA sparse embedding representing the input text.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelstrprithivida/Splade_PP_en_v1Local path or name of the model in Fastembed's model hub, such as prithivida/Splade_PP_en_v1.
cache_dirOptional[str]NoneThe path to the cache directory. Can be set using the FASTEMBED_CACHE_PATH env variable. Defaults to fastembed_cache in the system's temp directory.
threadsOptional[int]NoneThe number of threads single onnxruntime session can use.
progress_barboolTrueIf True, displays progress bar during embedding.
parallelOptional[int]NoneIf > 1, data-parallel encoding is used, recommended for offline encoding of large datasets. If 0, use all available cores. If None, don't use data-parallel processing, use default onnxruntime threading instead.
local_files_onlyboolFalseIf True, only use the model files in the cache_dir.
model_kwargsOptional[Dict[str, Any]]NoneDictionary containing model parameters such as k, b, avg_len, language.

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
textstrA string to embed.