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
WatsonxDocumentEmbedderin the indexing pipeline.
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
- Drag the
WatsonxTextEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the
modelto the same watsonx.ai embedding model used in your indexing pipeline. - Create secrets for your watsonx.ai credentials:
WATSONX_API_KEYandWATSONX_PROJECT_ID. For instructions, see Create Secrets.
- Set the
- Go to the Advanced tab to configure
prefix,suffix,truncate_input_tokens, andapi_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
| Parameter | Type | Description |
|---|---|---|
text | str | The text to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
embedding | List[float] | The embedding of the text. |
meta | Dict[str, Any] | Metadata about the request. |
Init Parameters
These are the parameters you can configure in Pipeline Builder:
| Parameter | Type | Default | Description |
|---|---|---|---|
model | str | ibm/slate-30m-english-rtrvr-v2 | The name of the watsonx.ai embedding model. |
api_key | Secret | Secret.from_env_var("WATSONX_API_KEY") | The IBM Cloud API key for watsonx.ai. |
api_base_url | str | https://us-south.ml.cloud.ibm.com | The IBM Cloud watsonx.ai API base URL. |
project_id | Secret | Secret.from_env_var("WATSONX_PROJECT_ID") | The watsonx.ai project ID. |
truncate_input_tokens | Optional[int] | None | The maximum number of input tokens. Text exceeding this limit is truncated. |
prefix | str | "" | A string to add at the beginning of the text before embedding. |
suffix | str | "" | A string to add at the end of the text before embedding. |
timeout | Optional[float] | None | Request timeout in seconds. |
max_retries | Optional[int] | None | Maximum 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
text | str | The text to embed. |
Related Information
Was this page helpful?