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

WatsonxDocumentEmbedder

Compute embeddings for a list of documents using IBM watsonx.ai embedding models. Use this component in indexing pipelines to prepare documents for embedding-based retrieval.

Key Features

  • Uses IBM watsonx.ai embedding models such as ibm/slate-30m-english-rtrvr-v2.
  • Stores the computed embedding in each document's embedding field.
  • Supports high-throughput processing with configurable batch size and concurrency.
  • Supports adding metadata fields to the text before embedding.
Embedding Models in Query Pipelines and Indexes

The embedding model you use to embed documents in your indexing pipeline must be the same as the embedding model you use to embed the query in your query pipeline.

This means the embedders for your indexing and query pipelines must match. For example, if you use CohereDocumentEmbedder to embed your documents, you should use CohereTextEmbedder with the same model to embed your queries.

Configuration

  1. Drag the WatsonxDocumentEmbedder component onto the canvas from the Component Library.
  2. Click on the component to open the configuration panel.
  3. On the General tab:
    1. Set the model to the watsonx.ai embedding model you want to use.
    2. Create secrets for your watsonx.ai credentials: WATSONX_API_KEY and WATSONX_PROJECT_ID. For instructions, see Create Secrets.
  4. Go to the Advanced tab to configure batch_size, concurrency_limit, meta_fields_to_embed, and truncate_input_tokens.

Connections

WatsonxDocumentEmbedder receives a list of documents, typically from a document splitter or converter. It outputs the same documents with embeddings added to their embedding field, ready to be sent to a DocumentWriter.

Source Code

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

Usage Examples

Basic Configuration

  WatsonxDocumentEmbedder:
type: haystack_integrations.components.embedders.watsonx.WatsonxDocumentEmbedder
init_parameters:
api_key:
type: env_var
env_vars:
- WATSONX_API_KEY
strict: false
project_id:
type: env_var
env_vars:
- WATSONX_PROJECT_ID
strict: false
model: ibm/slate-30m-english-rtrvr-v2
batch_size: 1000

Parameters

Inputs

ParameterTypeDescription
documentsList[Document]A list of documents to embed.

Outputs

ParameterTypeDescription
documentsList[Document]The documents with their embedding field populated.
metaDict[str, Any]Metadata about the embedding request.

Init Parameters

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
modelstribm/slate-30m-english-rtrvr-v2The name of the watsonx.ai embedding model.
api_keySecretSecret.from_env_var("WATSONX_API_KEY")The IBM Cloud API key for watsonx.ai.
api_base_urlstrhttps://us-south.ml.cloud.ibm.comThe IBM Cloud watsonx.ai API base URL.
project_idSecretSecret.from_env_var("WATSONX_PROJECT_ID")The watsonx.ai project ID.
truncate_input_tokensOptional[int]NoneThe maximum number of input tokens. Text exceeding this limit is truncated.
prefixstr""A string to add at the beginning of each document's text before embedding.
suffixstr""A string to add at the end of each document's text before embedding.
batch_sizeint1000The number of documents to process in each batch.
concurrency_limitint5The maximum number of concurrent API requests.
timeoutOptional[float]NoneRequest timeout in seconds.
max_retriesOptional[int]NoneMaximum number of retries on API errors.
meta_fields_to_embedOptional[List[str]]NoneA list of document metadata field names to include in the text before embedding.
embedding_separatorstr"\n"The separator used to join the document text and metadata fields.

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]A list of documents to embed.