FastembedTextEmbedder
Compute text embeddings using Fastembed embedding models.
Key Features
- Uses Fastembed, a lightweight, fast Python library for embedding generation.
- Outputs a dense embedding vector for the input text.
- Must use the same embedding model as
FastembedDocumentEmbedderused in the index. - Supports optional text prefix and suffix for models that require instruction-style input.
Configuration
- Drag the
FastembedTextEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Select the embedding model. You can find supported models in the FastEmbed documentation.
- Go to the Advanced tab to configure additional settings such as
prefix,suffix,parallel, andlocal_files_only.
Connections
FastembedTextEmbedder receives a text string (the user query) as input. It outputs an embedding list of floats. Connect its output to an embedding retriever to find matching documents. Use the same model as the one used to embed documents in the document store.
Source Code
To check this component's source code, open fastembed_text_embedder.py in the Haystack Core Integrations repository.
Connections
FastembedTextEmbedder 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 dense embedding vector as List[float]. Connect its embedding output to the query_embedding input of an embedding retriever.
Usage Examples
Basic Configuration
FastembedTextEmbedder:
type: haystack_integrations.components.embedders.fastembed.fastembed_text_embedder.FastembedTextEmbedder
init_parameters:
model: BAAI/bge-small-en-v1.5
prefix: ''
suffix: ''
progress_bar: true
local_files_only: false
This query pipeline uses FastembedTextEmbedder to embed the query for semantic search:
components:
FastembedTextEmbedder:
type: haystack_integrations.components.embedders.fastembed.fastembed_text_embedder.FastembedTextEmbedder
init_parameters:
model: BAAI/bge-small-en-v1.5
cache_dir:
threads:
prefix: ""
suffix: ""
progress_bar: true
parallel:
local_files_only: false
embedding_retriever:
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
init_parameters:
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: 'default'
max_chunk_bytes: 104857600
embedding_dim: 384
return_embedding: false
method:
mappings:
settings:
create_index: true
http_auth:
use_ssl:
verify_certs:
timeout:
top_k: 10
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: FastembedTextEmbedder.embedding
receiver: embedding_retriever.query_embedding
- sender: embedding_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: embedding_retriever.documents
receiver: answer_builder.documents
inputs:
query:
- FastembedTextEmbedder.text
- ChatPromptBuilder.query
- answer_builder.query
filters:
- embedding_retriever.filters
outputs:
documents: embedding_retriever.documents
answers: answer_builder.answers
max_runs_per_component: 100
metadata: {}
Parameters
Inputs
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | A string to embed. |
Outputs
| Parameter | Type | Default | Description |
|---|---|---|---|
embedding | List[float] | A list of floats representing the embedding of the input text. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | BAAI/bge-small-en-v1.5 | Local path or name of the model in Fastembed's model hub, such as BAAI/bge-small-en-v1.5. |
cache_dir | Optional[str] | None | The 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. |
threads | Optional[int] | None | The number of threads single onnxruntime session can use. |
prefix | str | "" | A string to add to the beginning of each text. |
suffix | str | "" | A string to add to the end of each text. |
progress_bar | bool | True | If True, displays progress bar during embedding. |
parallel | Optional[int] | None | If > 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_only | bool | False | If True, only use the model files in the cache_dir. |
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 |
|---|---|---|---|
text | str | A string to embed. |
Was this page helpful?