DocumentationAPI Reference📓 Tutorials🧑‍🍳 Cookbook🤝 Integrations💜 Discord


Use this component to embed a simple string (such as a query) into a sparse vector.

Position in a PipelineBefore sparse embedding Retriever in a query/RAG pipeline
Inputs“text”: A string
Outputs“sparse_embedding”: A SparseEmbedding object

For embedding lists of documents, use the FastembedSparseDocumentEmbedder, which enriches the document with the computed sparse embedding.


FastembedSparseTextEmbedder transforms a string into a sparse vector using sparse embedding models supported by FastEmbed.

When you perform sparse embedding retrieval, use this component first to transform your query into a sparse vector. Then, the sparse embedding Retriever will use the vector to search for similar or relevant documents.

Compatible Models

You can find the supported models in the FastEmbed documentation.

Currently, supported models are based on SPLADE, a technique for producing sparse representations for text, where each non-zero value in the embedding is the importance weight of a term in the BERT WordPiece vocabulary. For more information, see our docs that explain sparse embedding-based Retrievers further.


To start using this integration with Haystack, install the package with:

pip install fastembed-haystack


You can set the path where the model will be stored in a cache directory. Also, you can set the number of threads a single onnxruntime session can use:

cache_dir= "/your_cacheDirectory"
embedder = FastembedSparseTextEmbedder(

If you want to use the data parallel encoding, you can set the parallel parameter.

  • If parallel > 1, data-parallel encoding will be used. This is recommended for offline encoding of large datasets.
  • If parallel is 0, use all available cores.
  • If None, don't use data-parallel processing; use the default onnxruntime threading instead.


If you create both a Sparse Text Embedder and a Sparse Document Embedder based on the same model, Haystack utilizes a shared resource behind the scenes to conserve resources.


On its own

from haystack_integrations.components.embedders.fastembed import FastembedSparseTextEmbedder

text = """It clearly says online this will work on a Mac OS system. 
The disk comes and it does not, only Windows. 
Do Not order this if you have a Mac!!"""

text_embedder = FastembedSparseTextEmbedder(model="prithvida/Splade_PP_en_v1")

sparse_embedding =["sparse_embedding"]

In a pipeline

Currently, sparse embedding retrieval is only supported by QdrantDocumentStore.
First, install the package with:

pip install qdrant-haystack

Then, try out this pipeline:

from haystack import Document, Pipeline
from haystack_integrations.document_stores.qdrant import QdrantDocumentStore
from haystack_integrations.components.retrievers.qdrant import QdrantSparseEmbeddingRetriever
from haystack_integrations.components.embedders.fastembed import FastembedSparseTextEmbedder, FastembedSparseDocumentEmbedder, FastembedTextEmbedder

document_store = QdrantDocumentStore(

documents = [
    Document(content="My name is Wolfgang and I live in Berlin"),
    Document(content="I saw a black horse running"),
    Document(content="Germany has many big cities"),
    Document(content="fastembed is supported by and maintained by Qdrant."),

sparse_document_embedder = FastembedSparseDocumentEmbedder(

documents_with_sparse_embeddings =["documents"]

query_pipeline = Pipeline()
query_pipeline.add_component("sparse_text_embedder", FastembedSparseTextEmbedder())
query_pipeline.add_component("sparse_retriever", QdrantSparseEmbeddingRetriever(document_store=document_store))

query = "Who supports fastembed?"

result ={"sparse_text_embedder": {"text": query}})

print(result["sparse_retriever"]["documents"][0])  # noqa: T201

# Document(id=...,
#  content: 'fastembed is supported by and maintained by Qdrant.',
#  score: 0.561..)

Related Links

Check out the API reference in the GitHub repo or in our docs: