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

FastembedSparseDocumentEmbedder

Compute sparse document embeddings using Fastembed sparse models.

Key Features​

  • Uses Fastembed sparse models such as SPLADE for sparse embedding generation.
  • Stores the computed sparse embedding in the sparse_embedding field of each document.
  • Supports hybrid search scenarios combining sparse and dense retrieval.
  • Configurable batch size and parallel processing for large datasets.
  • Supports embedding metadata fields alongside document content.

Configuration​

  1. Drag the FastembedSparseDocumentEmbedder 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 batch_size, parallel, meta_fields_to_embed, and model_kwargs.

Connections​

FastembedSparseDocumentEmbedder receives a list of documents from converters or DocumentSplitter in an indexing pipeline. It outputs the same documents with their sparse_embedding field populated. Connect its output to DocumentWriter to store the embedded documents.

Source Code​

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

Connections​

FastembedSparseDocumentEmbedder accepts a list of documents as input. In an indexing pipeline, connect it to converters such as TextFileToDocument or preprocessors such as DocumentSplitter.

It outputs a list of documents with the sparse_embedding field populated. Connect its documents output to DocumentWriter to store the embedded documents.

Usage Examples​

Basic Configuration​

FastembedSparseDocumentEmbedder:
type:
haystack_integrations.components.embedders.fastembed.fastembed_sparse_document_embedder.FastembedSparseDocumentEmbedder
init_parameters:
model: prithivida/Splade_PP_en_v1
batch_size: 32
progress_bar: true
local_files_only: false
embedding_separator: "\n"

This index uses FastembedSparseDocumentEmbedder to create sparse embeddings:

# haystack-pipeline
components:
TextFileToDocument:
type: haystack.components.converters.txt.TextFileToDocument
init_parameters:
encoding: utf-8
store_full_path: false

DocumentSplitter:
type: haystack.components.preprocessors.document_splitter.DocumentSplitter
init_parameters:
split_by: sentence
split_length: 5
split_overlap: 1

FastembedSparseDocumentEmbedder:
type: haystack_integrations.components.embedders.fastembed.fastembed_sparse_document_embedder.FastembedSparseDocumentEmbedder
init_parameters:
model: prithivida/Splade_PP_en_v1
cache_dir:
threads:
batch_size: 32
progress_bar: true
parallel:
local_files_only: false
meta_fields_to_embed:
embedding_separator: "\n"
model_kwargs:

DocumentWriter:
type: haystack.components.writers.document_writer.DocumentWriter
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'sparse-index'
max_chunk_bytes: 104857600
embedding_dim: 768
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
policy: OVERWRITE

connections:
- sender: TextFileToDocument.documents
receiver: DocumentSplitter.documents
- sender: DocumentSplitter.documents
receiver: FastembedSparseDocumentEmbedder.documents
- sender: FastembedSparseDocumentEmbedder.documents
receiver: DocumentWriter.documents

inputs:
files:
- TextFileToDocument.sources

max_runs_per_component: 100

metadata: {}

Parameters​

Inputs​

ParameterTypeDefaultDescription
documentsList[Document]List of Documents to embed.

Outputs​

ParameterTypeDefaultDescription
documentsList[Document]List of Documents with each Document's sparse_embedding field set to the computed embeddings.

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 Hugging Face'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.
batch_sizeint32Number of strings to encode at once.
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.
meta_fields_to_embedOptional[List[str]]NoneList of meta fields that should be embedded along with the Document content.
embedding_separatorstr\nSeparator used to concatenate the meta fields to the Document content.
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
documentsList[Document]List of Documents to embed.