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

WatsonxTextEmbedder

Embed strings using IBM watsonx.ai embedding models. Use this component in query pipelines to transform user queries into vectors for embedding-based retrieval.

Key Features

  • Uses IBM watsonx.ai embedding models such as ibm/slate-30m-english-rtrvr-v2.
  • Outputs a float vector embedding suitable for use with embedding retrievers.
  • The embedding model must match the one used by WatsonxDocumentEmbedder in the indexing pipeline.
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 WatsonxTextEmbedder 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 same watsonx.ai embedding model used in your indexing pipeline.
    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 prefix, suffix, truncate_input_tokens, and api_base_url.

Connections

WatsonxTextEmbedder receives the user query as a text string, typically from the Input component. It outputs a float vector through its embedding output, which you connect to an embedding retriever.

Source Code

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

Usage Examples

Basic Configuration

  WatsonxTextEmbedder:
type: haystack_integrations.components.embedders.watsonx.WatsonxTextEmbedder
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

Using the Component in a Pipeline

# haystack-pipeline
components:
WatsonxTextEmbedder:
type: haystack_integrations.components.embedders.watsonx.WatsonxTextEmbedder
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

retriever:
type: haystack_integrations.components.retrievers.opensearch.embedding_retriever.OpenSearchEmbeddingRetriever
init_parameters:
top_k: 10
document_store:
type: haystack_integrations.document_stores.opensearch.document_store.OpenSearchDocumentStore
init_parameters:
hosts:
index: my-index
embedding_dim: 384

connections:
- sender: WatsonxTextEmbedder.embedding
receiver: retriever.query_embedding

max_runs_per_component: 100

metadata: {}

inputs:
query:
- WatsonxTextEmbedder.text

Parameters

Inputs

ParameterTypeDescription
textstrThe text to embed.

Outputs

ParameterTypeDescription
embeddingList[float]The embedding of the text.
metaDict[str, Any]Metadata about the 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 the text before embedding.
suffixstr""A string to add at the end of the text before embedding.
timeoutOptional[float]NoneRequest timeout in seconds.
max_retriesOptional[int]NoneMaximum number of retries on API errors.

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
textstrThe text to embed.