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
embeddingfield. - Supports high-throughput processing with configurable batch size and concurrency.
- Supports adding metadata fields to the text before embedding.
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
WatsonxDocumentEmbeddercomponent onto the canvas from the Component Library. - Click on the component to open the configuration panel.
- On the General tab:
- Set the
modelto the watsonx.ai embedding model you want to use. - 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
batch_size,concurrency_limit,meta_fields_to_embed, andtruncate_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
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | A list of documents to embed. |
Outputs
| Parameter | Type | Description |
|---|---|---|
documents | List[Document] | The documents with their embedding field populated. |
meta | Dict[str, Any] | Metadata about the embedding 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 each document's text before embedding. |
suffix | str | "" | A string to add at the end of each document's text before embedding. |
batch_size | int | 1000 | The number of documents to process in each batch. |
concurrency_limit | int | 5 | The maximum number of concurrent API requests. |
timeout | Optional[float] | None | Request timeout in seconds. |
max_retries | Optional[int] | None | Maximum number of retries on API errors. |
meta_fields_to_embed | Optional[List[str]] | None | A list of document metadata field names to include in the text before embedding. |
embedding_separator | str | "\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.
| Parameter | Type | Default | Description |
|---|---|---|---|
documents | List[Document] | A list of documents to embed. |
Related Information
Was this page helpful?