watsonx-haystack 3.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-3.0.0 → watsonx_haystack-3.1.0}/CHANGELOG.md +12 -0
  2. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/PKG-INFO +1 -2
  3. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/pyproject.toml +1 -1
  4. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/watsonx/document_embedder.py +12 -5
  5. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/watsonx/text_embedder.py +12 -5
  6. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/watsonx/chat/chat_generator.py +15 -12
  7. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/tests/test_chat_generator.py +25 -4
  8. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/tests/test_document_embedder.py +13 -2
  9. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/tests/test_text_embedder.py +10 -2
  10. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/.gitignore +0 -0
  11. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/LICENSE.txt +0 -0
  12. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/README.md +0 -0
  13. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/examples/chat_generator_example.py +0 -0
  14. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/examples/embedders_example.py +0 -0
  15. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/pydoc/config_docusaurus.yml +0 -0
  16. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
  17. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/embedders/watsonx/__init__.py +0 -0
  18. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/py.typed +0 -0
  19. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/watsonx/__init__.py +0 -0
  20. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/src/haystack_integrations/components/generators/watsonx/chat/__init__.py +0 -0
  21. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/tests/__init__.py +0 -0
  22. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/tests/conftest.py +0 -0
  23. {watsonx_haystack-3.0.0 → watsonx_haystack-3.1.0}/tests/test_files/apple.jpg +0 -0
@@ -1,5 +1,17 @@
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
+
3
15
  ## [integrations/watsonx-v2.0.0] - 2026-09-11
4
16
 
5
17
  ### 🐛 Bug Fixes
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: watsonx-haystack
3
- Version: 3.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"
@@ -9,8 +9,10 @@ from typing import Any
9
9
 
10
10
  from haystack import Document, component, default_to_dict
11
11
  from haystack.utils import Secret
12
- from ibm_watsonx_ai import Credentials
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,
@@ -6,8 +6,10 @@ from typing import Any
6
6
 
7
7
  from haystack import component, default_to_dict
8
8
  from haystack.utils import Secret
9
- from ibm_watsonx_ai import Credentials
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
  )
@@ -32,8 +32,10 @@ from haystack.tools import (
32
32
  serialize_tools_or_toolset,
33
33
  )
34
34
  from haystack.utils import Secret, deserialize_callable, serialize_callable
35
- from ibm_watsonx_ai import Credentials
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
 
@@ -363,7 +366,7 @@ class WatsonxChatGenerator:
363
366
  watsonx_messages = []
364
367
  content: str | dict[str, Any] | list[dict[str, Any]] | None
365
368
 
366
- 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)
367
370
  _check_duplicate_tool_names(flattened_tools)
368
371
  tool_definitions = [{"type": "function", "function": {**tool.tool_spec}} for tool in flattened_tools]
369
372
 
@@ -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):
@@ -8,6 +8,7 @@ import pytest
8
8
  from haystack import Document
9
9
  from haystack.core.serialization import component_from_dict
10
10
  from haystack.utils.auth import Secret
11
+ from httpx import Timeout
11
12
 
12
13
  from haystack_integrations.components.embedders.watsonx.document_embedder import WatsonxDocumentEmbedder
13
14
 
@@ -15,7 +16,10 @@ from haystack_integrations.components.embedders.watsonx.document_embedder import
15
16
  @pytest.fixture
16
17
  def mock_embeddings():
17
18
  """Fixture for setting up common mocks"""
18
- 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
+ ):
19
23
  yield embeddings.return_value
20
24
 
21
25
 
@@ -121,6 +125,7 @@ class TestComponentLifecycle:
121
125
  def test_warm_up_is_idempotent(self):
122
126
  with (
123
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,
124
129
  patch("haystack_integrations.components.embedders.watsonx.document_embedder.Embeddings") as embeddings,
125
130
  ):
126
131
  embedder = WatsonxDocumentEmbedder(
@@ -130,6 +135,7 @@ class TestComponentLifecycle:
130
135
  truncate_input_tokens=128,
131
136
  batch_size=500,
132
137
  concurrency_limit=3,
138
+ timeout=2.0,
133
139
  max_retries=5,
134
140
  )
135
141
  embedder.warm_up()
@@ -137,9 +143,14 @@ class TestComponentLifecycle:
137
143
  embedder.warm_up()
138
144
 
139
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)
140
151
  embeddings.assert_called_once_with(
141
152
  model_id="ibm/slate-30m-english-rtrvr-v2",
142
- credentials=credentials.return_value,
153
+ api_client=api_client.return_value,
143
154
  project_id="fake-project-id",
144
155
  params={"truncate_input_tokens": 128},
145
156
  batch_size=500,
@@ -7,6 +7,7 @@ from unittest.mock import patch
7
7
  import pytest
8
8
  from haystack.core.serialization import component_from_dict
9
9
  from haystack.utils.auth import Secret
10
+ from httpx import Timeout
10
11
  from ibm_watsonx_ai.wml_client_error import ApiRequestFailure
11
12
 
12
13
  from haystack_integrations.components.embedders.watsonx.text_embedder import WatsonxTextEmbedder
@@ -103,6 +104,7 @@ class TestComponentLifecycle:
103
104
  def test_warm_up_is_idempotent(self):
104
105
  with (
105
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,
106
108
  patch("haystack_integrations.components.embedders.watsonx.text_embedder.Embeddings") as embeddings,
107
109
  ):
108
110
  embedder = WatsonxTextEmbedder(
@@ -111,6 +113,7 @@ class TestComponentLifecycle:
111
113
  api_base_url="https://custom-url.ibm.com",
112
114
  project_id=Secret.from_token("fake-project-id"),
113
115
  truncate_input_tokens=128,
116
+ timeout=2.0,
114
117
  max_retries=5,
115
118
  )
116
119
  embedder.warm_up()
@@ -118,9 +121,14 @@ class TestComponentLifecycle:
118
121
  embedder.warm_up()
119
122
 
120
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)
121
129
  embeddings.assert_called_once_with(
122
130
  model_id="ibm/slate-125m-english-rtrvr",
123
- credentials=credentials.return_value,
131
+ api_client=api_client.return_value,
124
132
  project_id="fake-project-id",
125
133
  params={"truncate_input_tokens": 128},
126
134
  max_retries=5,
@@ -185,7 +193,7 @@ class TestIntegration:
185
193
  with pytest.raises(ApiRequestFailure) as exc_info:
186
194
  embedder.run(very_long_text)
187
195
 
188
- 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)
189
197
  assert "512" in str(exc_info.value)
190
198
 
191
199
  def test_text_truncation(self):