watsonx-haystack 2.0.0__tar.gz → 3.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (23) hide show
  1. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/CHANGELOG.md +32 -0
  2. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/PKG-INFO +1 -2
  3. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/pyproject.toml +1 -2
  4. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/watsonx/document_embedder.py +14 -20
  5. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/watsonx/text_embedder.py +14 -20
  6. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/watsonx/chat/chat_generator.py +18 -16
  7. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/tests/test_chat_generator.py +25 -4
  8. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/tests/test_document_embedder.py +16 -3
  9. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/tests/test_text_embedder.py +13 -3
  10. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/.gitignore +0 -0
  11. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/LICENSE.txt +0 -0
  12. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/README.md +0 -0
  13. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/examples/chat_generator_example.py +0 -0
  14. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/examples/embedders_example.py +0 -0
  15. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/pydoc/config_docusaurus.yml +0 -0
  16. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
  17. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/watsonx/__init__.py +0 -0
  18. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/py.typed +0 -0
  19. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/watsonx/__init__.py +0 -0
  20. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/watsonx/chat/__init__.py +0 -0
  21. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/tests/__init__.py +0 -0
  22. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/tests/conftest.py +0 -0
  23. {watsonx_haystack-2.0.0 → watsonx_haystack-3.1.0}/tests/test_files/apple.jpg +0 -0
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/watsonx-v3.0.0] - 2026-10-16
4
+
5
+ ### 🚜 Refactor
6
+
7
+ - [**breaking**] Remove from_dict overrides that only call default_from_dict from 14 components (#4059)
8
+
9
+ ### 🧹 Chores
10
+
11
+ - Drop redundant deserialize_secrets_inplace calls in integrations requiring haystack-ai>=2.23 (#4058)
12
+ - [**breaking**] Drop Python 3.10 support (#4105)
13
+
14
+
15
+ ## [integrations/watsonx-v2.0.0] - 2026-09-11
16
+
17
+ ### 🐛 Bug Fixes
18
+
19
+ - Standardize license files (#3771)
20
+
21
+ ### 🚜 Refactor
22
+
23
+ - [**breaking**] Watsonx - move client creation to warm_up (#3944)
24
+
25
+ ### ⚙️ CI
26
+
27
+ - Improve changelog generation; fix existing changelogs (#3883)
28
+
29
+ ### 🧹 Chores
30
+
31
+ - Clarify how generation_kwargs passed in run are handled (#3805)
32
+ - [**breaking**] Remove deprecated `WatsonxGenerator` (use `WatsonxChatGenerator` instead) (#3889)
33
+
34
+
3
35
  ## [integrations/watsonx-v1.7.0] - 2026-08-07
4
36
 
5
37
  ### 🚀 Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: watsonx-haystack
3
- Version: 2.0.0
3
+ Version: 3.1.0
4
4
  Summary: Watsonx integration for Haystack
5
5
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/watsonx#readme
6
6
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
@@ -18,7 +18,6 @@ Classifier: Programming Language :: Python :: 3.14
18
18
  Requires-Python: >=3.11
19
19
  Requires-Dist: haystack-ai>=3.0.0
20
20
  Requires-Dist: ibm-watsonx-ai>=1.5.13
21
- Requires-Dist: pandas>=2.2.3
22
21
  Description-Content-Type: text/markdown
23
22
 
24
23
  # watsonx-haystack
@@ -22,7 +22,7 @@ classifiers = [
22
22
  "Programming Language :: Python :: 3.13",
23
23
  "Programming Language :: Python :: 3.14",
24
24
  ]
25
- dependencies = ["haystack-ai>=3.0.0", "ibm-watsonx-ai>=1.5.13", "pandas>=2.2.3"]
25
+ dependencies = ["haystack-ai>=3.0.0", "ibm-watsonx-ai>=1.5.13"]
26
26
 
27
27
  [project.urls]
28
28
  Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/watsonx#readme"
@@ -84,7 +84,6 @@ module = [
84
84
  ignore_missing_imports = true
85
85
 
86
86
  [tool.ruff]
87
- target-version = "py310"
88
87
  line-length = 120
89
88
 
90
89
  [tool.ruff.lint]
@@ -7,10 +7,12 @@ from __future__ import annotations
7
7
  from dataclasses import replace
8
8
  from typing import Any
9
9
 
10
- from haystack import Document, component, default_from_dict, default_to_dict
11
- from haystack.utils import Secret, deserialize_secrets_inplace
12
- from ibm_watsonx_ai import Credentials
10
+ from haystack import Document, component, default_to_dict
11
+ from haystack.utils import Secret
12
+ from httpx import Timeout
13
+ from ibm_watsonx_ai import APIClient, Credentials
13
14
  from ibm_watsonx_ai.foundation_models import Embeddings
15
+ from ibm_watsonx_ai.utils.utils import HttpClientConfig
14
16
 
15
17
 
16
18
  @component
@@ -86,9 +88,9 @@ class WatsonxDocumentEmbedder:
86
88
  :param concurrency_limit:
87
89
  Number of parallel requests to make. Default is 5.
88
90
  :param timeout:
89
- Timeout for API requests in seconds.
91
+ Timeout for API requests in seconds. When omitted, the IBM SDK uses its default timeout.
90
92
  :param max_retries:
91
- Maximum number of retries for API requests.
93
+ Maximum number of retries for API requests. When omitted, the IBM SDK uses its default retry policy.
92
94
  """
93
95
 
94
96
  self.model = model
@@ -113,6 +115,11 @@ class WatsonxDocumentEmbedder:
113
115
  return
114
116
 
115
117
  credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
118
+ project_id = self.project_id.resolve_value()
119
+ client_kwargs: dict[str, Any] = {}
120
+ if self.timeout is not None:
121
+ config = HttpClientConfig(timeout=Timeout(self.timeout))
122
+ client_kwargs = {"httpx_client": config, "async_httpx_client": config}
116
123
 
117
124
  params = {}
118
125
  if self.truncate_input_tokens is not None:
@@ -120,8 +127,8 @@ class WatsonxDocumentEmbedder:
120
127
 
121
128
  self.embedder = Embeddings(
122
129
  model_id=self.model,
123
- credentials=credentials,
124
- project_id=self.project_id.resolve_value(),
130
+ api_client=APIClient(credentials=credentials, **client_kwargs),
131
+ project_id=project_id,
125
132
  params=params if params else None, # type: ignore[arg-type]
126
133
  batch_size=self.batch_size,
127
134
  concurrency_limit=self.concurrency_limit,
@@ -158,19 +165,6 @@ class WatsonxDocumentEmbedder:
158
165
  embedding_separator=self.embedding_separator,
159
166
  )
160
167
 
161
- @classmethod
162
- def from_dict(cls, data: dict[str, Any]) -> "WatsonxDocumentEmbedder": # noqa: UP037
163
- """
164
- Deserializes the component from a dictionary.
165
-
166
- :param data:
167
- The dictionary representation of this component.
168
- :returns:
169
- The deserialized component instance.
170
- """
171
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key", "project_id"])
172
- return default_from_dict(cls, data)
173
-
174
168
  def _prepare_texts_to_embed(self, documents: list[Document]) -> list[str]:
175
169
  """
176
170
  Prepare the texts to embed by concatenating the Document text with the metadata fields to embed.
@@ -4,10 +4,12 @@
4
4
 
5
5
  from typing import Any
6
6
 
7
- from haystack import component, default_from_dict, default_to_dict
8
- from haystack.utils import Secret, deserialize_secrets_inplace
9
- from ibm_watsonx_ai import Credentials
7
+ from haystack import component, default_to_dict
8
+ from haystack.utils import Secret
9
+ from httpx import Timeout
10
+ from ibm_watsonx_ai import APIClient, Credentials
10
11
  from ibm_watsonx_ai.foundation_models import Embeddings
12
+ from ibm_watsonx_ai.utils.utils import HttpClientConfig
11
13
 
12
14
 
13
15
  @component
@@ -74,9 +76,9 @@ class WatsonxTextEmbedder:
74
76
  :param suffix:
75
77
  A string to add at the end of each text to embed.
76
78
  :param timeout:
77
- Timeout for API requests in seconds.
79
+ Timeout for API requests in seconds. When omitted, the IBM SDK uses its default timeout.
78
80
  :param max_retries:
79
- Maximum number of retries for API requests.
81
+ Maximum number of retries for API requests. When omitted, the IBM SDK uses its default retry policy.
80
82
  """
81
83
 
82
84
  self.model = model
@@ -97,6 +99,11 @@ class WatsonxTextEmbedder:
97
99
  return
98
100
 
99
101
  credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
102
+ project_id = self.project_id.resolve_value()
103
+ client_kwargs: dict[str, Any] = {}
104
+ if self.timeout is not None:
105
+ config = HttpClientConfig(timeout=Timeout(self.timeout))
106
+ client_kwargs = {"httpx_client": config, "async_httpx_client": config}
100
107
 
101
108
  params = {}
102
109
  if self.truncate_input_tokens is not None:
@@ -104,8 +111,8 @@ class WatsonxTextEmbedder:
104
111
 
105
112
  self.embedder = Embeddings(
106
113
  model_id=self.model,
107
- credentials=credentials,
108
- project_id=self.project_id.resolve_value(),
114
+ api_client=APIClient(credentials=credentials, **client_kwargs),
115
+ project_id=project_id,
109
116
  params=params if params else None, # type: ignore[arg-type]
110
117
  max_retries=self.max_retries,
111
118
  )
@@ -136,19 +143,6 @@ class WatsonxTextEmbedder:
136
143
  max_retries=self.max_retries,
137
144
  )
138
145
 
139
- @classmethod
140
- def from_dict(cls, data: dict[str, Any]) -> "WatsonxTextEmbedder":
141
- """
142
- Deserializes the component from a dictionary.
143
-
144
- :param data:
145
- The dictionary representation of this component.
146
- :returns:
147
- The deserialized component instance.
148
- """
149
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key", "project_id"])
150
- return default_from_dict(cls, data)
151
-
152
146
  def _prepare_input(self, text: str) -> str:
153
147
  if not isinstance(text, str):
154
148
  msg = (
@@ -5,7 +5,7 @@
5
5
  import inspect
6
6
  import json
7
7
  from dataclasses import replace
8
- from datetime import datetime, timezone
8
+ from datetime import UTC, datetime
9
9
  from typing import Any, ClassVar, Literal, get_args
10
10
 
11
11
  from haystack import component, default_from_dict, default_to_dict, logging
@@ -31,9 +31,11 @@ from haystack.tools import (
31
31
  flatten_tools_or_toolsets,
32
32
  serialize_tools_or_toolset,
33
33
  )
34
- from haystack.utils import Secret, deserialize_callable, deserialize_secrets_inplace, serialize_callable
35
- from ibm_watsonx_ai import Credentials
34
+ from haystack.utils import Secret, deserialize_callable, serialize_callable
35
+ from httpx import Timeout
36
+ from ibm_watsonx_ai import APIClient, Credentials
36
37
  from ibm_watsonx_ai.foundation_models import ModelInference
38
+ from ibm_watsonx_ai.utils.utils import HttpClientConfig
37
39
 
38
40
  logger = logging.getLogger(__name__)
39
41
 
@@ -155,10 +157,6 @@ class WatsonxChatGenerator:
155
157
  """
156
158
  Creates an instance of WatsonxChatGenerator.
157
159
 
158
- Before initializing the component, you can set environment variables:
159
- - `WATSONX_TIMEOUT` to override the default timeout
160
- - `WATSONX_MAX_RETRIES` to override the default retry count
161
-
162
160
  :param api_key: IBM Cloud API key for watsonx.ai access.
163
161
  Can be set via `WATSONX_API_KEY` environment variable or passed directly.
164
162
  :param model: The model ID to use for completions. Defaults to "ibm/granite-4-h-small".
@@ -179,9 +177,9 @@ class WatsonxChatGenerator:
179
177
  - `stop_sequences`: List of sequences where generation should stop
180
178
  - `random_seed`: Seed for reproducible results
181
179
  :param timeout: Timeout in seconds for API requests.
182
- Defaults to environment variable `WATSONX_TIMEOUT` or 30 seconds.
180
+ When omitted, the IBM SDK uses its default timeout.
183
181
  :param max_retries: Maximum number of retry attempts for failed requests.
184
- Defaults to environment variable `WATSONX_MAX_RETRIES` or 5.
182
+ When omitted, the IBM SDK uses its default retry policy.
185
183
  :param verify: SSL verification setting. Can be:
186
184
  - True: Verify SSL certificates (default)
187
185
  - False: Skip verification (insecure)
@@ -208,12 +206,17 @@ class WatsonxChatGenerator:
208
206
  if self.client is not None:
209
207
  return
210
208
 
211
- credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
209
+ credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url, verify=self.verify)
210
+ project_id = self.project_id.resolve_value()
211
+ client_kwargs: dict[str, Any] = {}
212
+ if self.timeout is not None:
213
+ config = HttpClientConfig(timeout=Timeout(self.timeout))
214
+ client_kwargs = {"httpx_client": config, "async_httpx_client": config}
215
+
212
216
  self.client = ModelInference(
213
217
  model_id=self.model,
214
- credentials=credentials,
215
- project_id=self.project_id.resolve_value(),
216
- verify=self.verify,
218
+ api_client=APIClient(credentials=credentials, **client_kwargs),
219
+ project_id=project_id,
217
220
  max_retries=self.max_retries,
218
221
  )
219
222
 
@@ -250,7 +253,6 @@ class WatsonxChatGenerator:
250
253
  :returns:
251
254
  The deserialized component instance.
252
255
  """
253
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key", "project_id"])
254
256
  deserialize_tools_or_toolset_inplace(data["init_parameters"], key="tools")
255
257
  init_params = data.get("init_parameters", {})
256
258
  serialized_callback = init_params.get("streaming_callback")
@@ -364,7 +366,7 @@ class WatsonxChatGenerator:
364
366
  watsonx_messages = []
365
367
  content: str | dict[str, Any] | list[dict[str, Any]] | None
366
368
 
367
- flattened_tools = flatten_tools_or_toolsets(tools or self.tools)
369
+ flattened_tools = flatten_tools_or_toolsets(tools if tools is not None else self.tools)
368
370
  _check_duplicate_tool_names(flattened_tools)
369
371
  tool_definitions = [{"type": "function", "function": {**tool.tool_spec}} for tool in flattened_tools]
370
372
 
@@ -430,7 +432,7 @@ class WatsonxChatGenerator:
430
432
  "model_version": chunk.get("model_version"),
431
433
  "created": chunk.get("created"),
432
434
  "created_at": chunk.get("created_at"),
433
- "received_at": datetime.now(timezone.utc).isoformat(),
435
+ "received_at": datetime.now(UTC).isoformat(),
434
436
  }
435
437
 
436
438
  if choice["delta"] and (choice_delta_tool_calls := choice["delta"].get("tool_calls")):
@@ -11,6 +11,7 @@ from haystack.components.generators.utils import print_streaming_chunk
11
11
  from haystack.dataclasses import ChatMessage, ChatRole, ComponentInfo, ImageContent, StreamingChunk
12
12
  from haystack.tools import Tool, Toolset
13
13
  from haystack.utils import Secret
14
+ from httpx import Timeout
14
15
 
15
16
  from haystack_integrations.components.generators.watsonx.chat.chat_generator import WatsonxChatGenerator
16
17
 
@@ -41,7 +42,10 @@ def tools():
41
42
  @pytest.fixture
42
43
  def mock_watsonx() -> Generator[dict[str, MagicMock], None]:
43
44
  """Fixture for setting up common mocks"""
44
- with patch("haystack_integrations.components.generators.watsonx.chat.chat_generator.ModelInference") as mock_model:
45
+ with (
46
+ patch("haystack_integrations.components.generators.watsonx.chat.chat_generator.APIClient"),
47
+ patch("haystack_integrations.components.generators.watsonx.chat.chat_generator.ModelInference") as mock_model,
48
+ ):
45
49
  mock_model_instance = MagicMock()
46
50
  mock_model_instance.chat = MagicMock(
47
51
  return_value={
@@ -309,6 +313,7 @@ class TestComponentLifecycle:
309
313
  def test_warm_up_is_idempotent(self):
310
314
  with (
311
315
  patch("haystack_integrations.components.generators.watsonx.chat.chat_generator.Credentials") as credentials,
316
+ patch("haystack_integrations.components.generators.watsonx.chat.chat_generator.APIClient") as api_client,
312
317
  patch(
313
318
  "haystack_integrations.components.generators.watsonx.chat.chat_generator.ModelInference"
314
319
  ) as model_inference,
@@ -318,18 +323,23 @@ class TestComponentLifecycle:
318
323
  project_id=Secret.from_token("fake-project-id"),
319
324
  api_base_url="https://custom-url.ibm.com",
320
325
  verify=False,
326
+ timeout=2.0,
321
327
  max_retries=5,
322
328
  )
323
329
  generator.warm_up()
324
330
  client = generator.client
325
331
  generator.warm_up()
326
332
 
327
- credentials.assert_called_once_with(api_key="fake-api-key", url="https://custom-url.ibm.com")
333
+ credentials.assert_called_once_with(api_key="fake-api-key", url="https://custom-url.ibm.com", verify=False)
334
+ api_client.assert_called_once()
335
+ kwargs = api_client.call_args.kwargs
336
+ assert kwargs["credentials"] is credentials.return_value
337
+ assert kwargs["httpx_client"].timeout == Timeout(2.0)
338
+ assert kwargs["async_httpx_client"].timeout == Timeout(2.0)
328
339
  model_inference.assert_called_once_with(
329
340
  model_id="ibm/granite-4-h-small",
330
- credentials=credentials.return_value,
341
+ api_client=api_client.return_value,
331
342
  project_id="fake-project-id",
332
- verify=False,
333
343
  max_retries=5,
334
344
  )
335
345
  assert generator.client is client
@@ -515,6 +525,17 @@ class TestRun:
515
525
  assert len(result["replies"]) == 1
516
526
  assert result["replies"][0].text == "Async streaming response"
517
527
 
528
+ def test_prepare_api_call_empty_tools_overrides_init_tools(self, tools: list[Tool]) -> None:
529
+ generator = WatsonxChatGenerator(
530
+ api_key=Secret.from_token("test-api-key"),
531
+ project_id=Secret.from_token("test-project"),
532
+ tools=tools,
533
+ )
534
+ # an empty list must disable tools for this call, not fall back to the init tools
535
+ api_call = generator._prepare_api_call(messages=[ChatMessage.from_user("Test prompt")], tools=[])
536
+
537
+ assert "tools" not in api_call
538
+
518
539
 
519
540
  class TestMessageConversionAndMultimodal:
520
541
  def test_prepare_api_call_with_image(self):
@@ -6,7 +6,9 @@ from unittest.mock import patch
6
6
 
7
7
  import pytest
8
8
  from haystack import Document
9
+ from haystack.core.serialization import component_from_dict
9
10
  from haystack.utils.auth import Secret
11
+ from httpx import Timeout
10
12
 
11
13
  from haystack_integrations.components.embedders.watsonx.document_embedder import WatsonxDocumentEmbedder
12
14
 
@@ -14,7 +16,10 @@ from haystack_integrations.components.embedders.watsonx.document_embedder import
14
16
  @pytest.fixture
15
17
  def mock_embeddings():
16
18
  """Fixture for setting up common mocks"""
17
- with patch("haystack_integrations.components.embedders.watsonx.document_embedder.Embeddings") as embeddings:
19
+ with (
20
+ patch("haystack_integrations.components.embedders.watsonx.document_embedder.APIClient"),
21
+ patch("haystack_integrations.components.embedders.watsonx.document_embedder.Embeddings") as embeddings,
22
+ ):
18
23
  yield embeddings.return_value
19
24
 
20
25
 
@@ -87,12 +92,13 @@ class TestInitializationAndSerialization:
87
92
  },
88
93
  }
89
94
 
90
- component = WatsonxDocumentEmbedder.from_dict(data)
95
+ component = component_from_dict(WatsonxDocumentEmbedder, data, name="component")
91
96
 
92
97
  assert component.model == "ibm/slate-125m-english-rtrvr"
93
98
  assert component.api_base_url == "https://custom-url.ibm.com"
94
99
  assert isinstance(component.project_id, Secret)
95
100
  assert component.project_id == Secret.from_env_var("WATSONX_PROJECT_ID")
101
+ assert component.api_key == Secret.from_env_var("WATSONX_API_KEY")
96
102
  assert component.prefix == "prefix "
97
103
  assert component.suffix == " suffix"
98
104
  assert component.batch_size == 500
@@ -119,6 +125,7 @@ class TestComponentLifecycle:
119
125
  def test_warm_up_is_idempotent(self):
120
126
  with (
121
127
  patch("haystack_integrations.components.embedders.watsonx.document_embedder.Credentials") as credentials,
128
+ patch("haystack_integrations.components.embedders.watsonx.document_embedder.APIClient") as api_client,
122
129
  patch("haystack_integrations.components.embedders.watsonx.document_embedder.Embeddings") as embeddings,
123
130
  ):
124
131
  embedder = WatsonxDocumentEmbedder(
@@ -128,6 +135,7 @@ class TestComponentLifecycle:
128
135
  truncate_input_tokens=128,
129
136
  batch_size=500,
130
137
  concurrency_limit=3,
138
+ timeout=2.0,
131
139
  max_retries=5,
132
140
  )
133
141
  embedder.warm_up()
@@ -135,9 +143,14 @@ class TestComponentLifecycle:
135
143
  embedder.warm_up()
136
144
 
137
145
  credentials.assert_called_once_with(api_key="fake-api-key", url="https://custom-url.ibm.com")
146
+ api_client.assert_called_once()
147
+ kwargs = api_client.call_args.kwargs
148
+ assert kwargs["credentials"] is credentials.return_value
149
+ assert kwargs["httpx_client"].timeout == Timeout(2.0)
150
+ assert kwargs["async_httpx_client"].timeout == Timeout(2.0)
138
151
  embeddings.assert_called_once_with(
139
152
  model_id="ibm/slate-30m-english-rtrvr-v2",
140
- credentials=credentials.return_value,
153
+ api_client=api_client.return_value,
141
154
  project_id="fake-project-id",
142
155
  params={"truncate_input_tokens": 128},
143
156
  batch_size=500,
@@ -5,7 +5,9 @@ import os
5
5
  from unittest.mock import patch
6
6
 
7
7
  import pytest
8
+ from haystack.core.serialization import component_from_dict
8
9
  from haystack.utils.auth import Secret
10
+ from httpx import Timeout
9
11
  from ibm_watsonx_ai.wml_client_error import ApiRequestFailure
10
12
 
11
13
  from haystack_integrations.components.embedders.watsonx.text_embedder import WatsonxTextEmbedder
@@ -71,12 +73,13 @@ class TestInitializationAndSerialization:
71
73
  },
72
74
  }
73
75
 
74
- component = WatsonxTextEmbedder.from_dict(data)
76
+ component = component_from_dict(WatsonxTextEmbedder, data, name="component")
75
77
 
76
78
  assert component.model == "ibm/slate-125m-english-rtrvr"
77
79
  assert component.api_base_url == "https://custom-url.ibm.com"
78
80
  assert isinstance(component.project_id, Secret)
79
81
  assert component.project_id == Secret.from_env_var("WATSONX_PROJECT_ID")
82
+ assert component.api_key == Secret.from_env_var("WATSONX_API_KEY")
80
83
  assert component.prefix == "prefix "
81
84
  assert component.suffix == " suffix"
82
85
 
@@ -101,6 +104,7 @@ class TestComponentLifecycle:
101
104
  def test_warm_up_is_idempotent(self):
102
105
  with (
103
106
  patch("haystack_integrations.components.embedders.watsonx.text_embedder.Credentials") as credentials,
107
+ patch("haystack_integrations.components.embedders.watsonx.text_embedder.APIClient") as api_client,
104
108
  patch("haystack_integrations.components.embedders.watsonx.text_embedder.Embeddings") as embeddings,
105
109
  ):
106
110
  embedder = WatsonxTextEmbedder(
@@ -109,6 +113,7 @@ class TestComponentLifecycle:
109
113
  api_base_url="https://custom-url.ibm.com",
110
114
  project_id=Secret.from_token("fake-project-id"),
111
115
  truncate_input_tokens=128,
116
+ timeout=2.0,
112
117
  max_retries=5,
113
118
  )
114
119
  embedder.warm_up()
@@ -116,9 +121,14 @@ class TestComponentLifecycle:
116
121
  embedder.warm_up()
117
122
 
118
123
  credentials.assert_called_once_with(api_key="fake-api-key", url="https://custom-url.ibm.com")
124
+ api_client.assert_called_once()
125
+ kwargs = api_client.call_args.kwargs
126
+ assert kwargs["credentials"] is credentials.return_value
127
+ assert kwargs["httpx_client"].timeout == Timeout(2.0)
128
+ assert kwargs["async_httpx_client"].timeout == Timeout(2.0)
119
129
  embeddings.assert_called_once_with(
120
130
  model_id="ibm/slate-125m-english-rtrvr",
121
- credentials=credentials.return_value,
131
+ api_client=api_client.return_value,
122
132
  project_id="fake-project-id",
123
133
  params={"truncate_input_tokens": 128},
124
134
  max_retries=5,
@@ -183,7 +193,7 @@ class TestIntegration:
183
193
  with pytest.raises(ApiRequestFailure) as exc_info:
184
194
  embedder.run(very_long_text)
185
195
 
186
- assert "Please reduce the length of the input." in str(exc_info.value)
196
+ assert "Please reduce the length of the input" in str(exc_info.value)
187
197
  assert "512" in str(exc_info.value)
188
198
 
189
199
  def test_text_truncation(self):