watsonx-haystack 1.7.0__tar.gz → 3.0.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 (26) hide show
  1. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/CHANGELOG.md +32 -1
  2. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/LICENSE.txt +1 -1
  3. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/PKG-INFO +3 -3
  4. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/pydoc/config_docusaurus.yml +0 -1
  5. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/pyproject.toml +1 -2
  6. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/src/haystack_integrations/components/embedders/watsonx/document_embedder.py +19 -24
  7. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/src/haystack_integrations/components/embedders/watsonx/text_embedder.py +17 -22
  8. watsonx_haystack-3.0.0/src/haystack_integrations/components/generators/watsonx/chat/__init__.py +6 -0
  9. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/src/haystack_integrations/components/generators/watsonx/chat/chat_generator.py +25 -12
  10. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/tests/test_chat_generator.py +184 -164
  11. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/tests/test_document_embedder.py +85 -89
  12. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/tests/test_text_embedder.py +67 -78
  13. watsonx_haystack-1.7.0/src/haystack_integrations/components/generators/watsonx/__init__.py +0 -6
  14. watsonx_haystack-1.7.0/src/haystack_integrations/components/generators/watsonx/generator.py +0 -294
  15. watsonx_haystack-1.7.0/tests/test_generator.py +0 -433
  16. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/.gitignore +0 -0
  17. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/README.md +0 -0
  18. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/examples/chat_generator_example.py +0 -0
  19. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/examples/embedders_example.py +0 -0
  20. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
  21. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/src/haystack_integrations/components/embedders/watsonx/__init__.py +0 -0
  22. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/src/haystack_integrations/components/generators/py.typed +0 -0
  23. {watsonx_haystack-1.7.0/src/haystack_integrations/components/generators/watsonx/chat → watsonx_haystack-3.0.0/src/haystack_integrations/components/generators/watsonx}/__init__.py +0 -0
  24. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/tests/__init__.py +0 -0
  25. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/tests/conftest.py +0 -0
  26. {watsonx_haystack-1.7.0 → watsonx_haystack-3.0.0}/tests/test_files/apple.jpg +0 -0
@@ -1,6 +1,37 @@
1
1
  # Changelog
2
2
 
3
- ## [unreleased]
3
+ ## [integrations/watsonx-v2.0.0] - 2026-09-11
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - Standardize license files (#3771)
8
+
9
+ ### 🚜 Refactor
10
+
11
+ - [**breaking**] Watsonx - move client creation to warm_up (#3944)
12
+
13
+ ### ⚙️ CI
14
+
15
+ - Improve changelog generation; fix existing changelogs (#3883)
16
+
17
+ ### 🧹 Chores
18
+
19
+ - Clarify how generation_kwargs passed in run are handled (#3805)
20
+ - [**breaking**] Remove deprecated `WatsonxGenerator` (use `WatsonxChatGenerator` instead) (#3889)
21
+
22
+
23
+ ## [integrations/watsonx-v1.7.0] - 2026-08-07
24
+
25
+ ### 🚀 Features
26
+
27
+ - Add Python 3.14 support for WatsonX integration (#3744)
28
+
29
+ ### 🐛 Bug Fixes
30
+
31
+ - Fix new issues raised by ruff 0.16.0 (#3670)
32
+
33
+
34
+ ## [integrations/watsonx-v1.6.0] - 2026-07-09
4
35
 
5
36
  ### 🧪 Testing
6
37
 
@@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work.
58
58
 
59
59
  To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
60
60
 
61
- Copyright [yyyy] [name of copyright owner]
61
+ Copyright 2023-present deepset GmbH
62
62
 
63
63
  Licensed under the Apache License, Version 2.0 (the "License");
64
64
  you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: watsonx-haystack
3
- Version: 1.7.0
3
+ Version: 3.0.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
@@ -16,7 +16,7 @@ Classifier: Programming Language :: Python :: 3.12
16
16
  Classifier: Programming Language :: Python :: 3.13
17
17
  Classifier: Programming Language :: Python :: 3.14
18
18
  Requires-Python: >=3.11
19
- Requires-Dist: haystack-ai>=2.30.0
19
+ Requires-Dist: haystack-ai>=3.0.0
20
20
  Requires-Dist: ibm-watsonx-ai>=1.5.13
21
21
  Requires-Dist: pandas>=2.2.3
22
22
  Description-Content-Type: text/markdown
@@ -1,6 +1,5 @@
1
1
  loaders:
2
2
  - modules:
3
- - haystack_integrations.components.generators.watsonx.generator
4
3
  - haystack_integrations.components.generators.watsonx.chat.chat_generator
5
4
  - haystack_integrations.components.embedders.watsonx.document_embedder
6
5
  - haystack_integrations.components.embedders.watsonx.text_embedder
@@ -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>=2.30.0", "ibm-watsonx-ai>=1.5.13", "pandas>=2.2.3"]
25
+ dependencies = ["haystack-ai>=3.0.0", "ibm-watsonx-ai>=1.5.13", "pandas>=2.2.3"]
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,8 +7,8 @@ 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
10
+ from haystack import Document, component, default_to_dict
11
+ from haystack.utils import Secret
12
12
  from ibm_watsonx_ai import Credentials
13
13
  from ibm_watsonx_ai.foundation_models import Embeddings
14
14
 
@@ -105,21 +105,27 @@ class WatsonxDocumentEmbedder:
105
105
  self.meta_fields_to_embed = meta_fields_to_embed or []
106
106
  self.embedding_separator = embedding_separator
107
107
 
108
- # Initialize the embeddings client
109
- credentials = Credentials(api_key=api_key.resolve_value(), url=api_base_url)
108
+ self.embedder: Embeddings | None = None
109
+
110
+ def warm_up(self) -> None:
111
+ """Create the Watsonx embeddings client."""
112
+ if self.embedder is not None:
113
+ return
114
+
115
+ credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
110
116
 
111
117
  params = {}
112
- if truncate_input_tokens is not None:
113
- params["truncate_input_tokens"] = truncate_input_tokens
118
+ if self.truncate_input_tokens is not None:
119
+ params["truncate_input_tokens"] = self.truncate_input_tokens
114
120
 
115
121
  self.embedder = Embeddings(
116
- model_id=model,
122
+ model_id=self.model,
117
123
  credentials=credentials,
118
- project_id=project_id.resolve_value(),
124
+ project_id=self.project_id.resolve_value(),
119
125
  params=params if params else None, # type: ignore[arg-type]
120
- batch_size=batch_size,
121
- concurrency_limit=concurrency_limit,
122
- max_retries=max_retries,
126
+ batch_size=self.batch_size,
127
+ concurrency_limit=self.concurrency_limit,
128
+ max_retries=self.max_retries,
123
129
  )
124
130
 
125
131
  def _get_telemetry_data(self) -> dict[str, Any]:
@@ -152,19 +158,6 @@ class WatsonxDocumentEmbedder:
152
158
  embedding_separator=self.embedding_separator,
153
159
  )
154
160
 
155
- @classmethod
156
- def from_dict(cls, data: dict[str, Any]) -> "WatsonxDocumentEmbedder": # noqa: UP037
157
- """
158
- Deserializes the component from a dictionary.
159
-
160
- :param data:
161
- The dictionary representation of this component.
162
- :returns:
163
- The deserialized component instance.
164
- """
165
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key", "project_id"])
166
- return default_from_dict(cls, data)
167
-
168
161
  def _prepare_texts_to_embed(self, documents: list[Document]) -> list[str]:
169
162
  """
170
163
  Prepare the texts to embed by concatenating the Document text with the metadata fields to embed.
@@ -203,6 +196,8 @@ class WatsonxDocumentEmbedder:
203
196
  raise TypeError(msg)
204
197
 
205
198
  texts_to_embed = self._prepare_texts_to_embed(documents=documents)
199
+ self.warm_up()
200
+ assert self.embedder is not None # noqa: S101
206
201
  embeddings = self.embedder.embed_documents(texts_to_embed)
207
202
 
208
203
  new_documents = []
@@ -4,8 +4,8 @@
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
7
+ from haystack import component, default_to_dict
8
+ from haystack.utils import Secret
9
9
  from ibm_watsonx_ai import Credentials
10
10
  from ibm_watsonx_ai.foundation_models import Embeddings
11
11
 
@@ -89,19 +89,25 @@ class WatsonxTextEmbedder:
89
89
  self.timeout = timeout
90
90
  self.max_retries = max_retries
91
91
 
92
- # Initialize the embeddings client
93
- credentials = Credentials(api_key=api_key.resolve_value(), url=api_base_url)
92
+ self.embedder: Embeddings | None = None
93
+
94
+ def warm_up(self) -> None:
95
+ """Create the Watsonx embeddings client."""
96
+ if self.embedder is not None:
97
+ return
98
+
99
+ credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
94
100
 
95
101
  params = {}
96
- if truncate_input_tokens is not None:
97
- params["truncate_input_tokens"] = truncate_input_tokens
102
+ if self.truncate_input_tokens is not None:
103
+ params["truncate_input_tokens"] = self.truncate_input_tokens
98
104
 
99
105
  self.embedder = Embeddings(
100
- model_id=model,
106
+ model_id=self.model,
101
107
  credentials=credentials,
102
- project_id=project_id.resolve_value(),
108
+ project_id=self.project_id.resolve_value(),
103
109
  params=params if params else None, # type: ignore[arg-type]
104
- max_retries=max_retries,
110
+ max_retries=self.max_retries,
105
111
  )
106
112
 
107
113
  def _get_telemetry_data(self) -> dict[str, Any]:
@@ -130,19 +136,6 @@ class WatsonxTextEmbedder:
130
136
  max_retries=self.max_retries,
131
137
  )
132
138
 
133
- @classmethod
134
- def from_dict(cls, data: dict[str, Any]) -> "WatsonxTextEmbedder":
135
- """
136
- Deserializes the component from a dictionary.
137
-
138
- :param data:
139
- The dictionary representation of this component.
140
- :returns:
141
- The deserialized component instance.
142
- """
143
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key", "project_id"])
144
- return default_from_dict(cls, data)
145
-
146
139
  def _prepare_input(self, text: str) -> str:
147
140
  if not isinstance(text, str):
148
141
  msg = (
@@ -163,6 +156,8 @@ class WatsonxTextEmbedder:
163
156
  - 'meta': Information about the model usage
164
157
  """
165
158
  text_to_embed = self._prepare_input(text=text)
159
+ self.warm_up()
160
+ assert self.embedder is not None # noqa: S101
166
161
  embedding = self.embedder.embed_query(text_to_embed)
167
162
  return {
168
163
  "embedding": embedding,
@@ -0,0 +1,6 @@
1
+ # SPDX-FileCopyrightText: 2025-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ from haystack_integrations.components.generators.watsonx.chat.chat_generator import WatsonxChatGenerator
5
+
6
+ __all__ = ["WatsonxChatGenerator"]
@@ -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,7 +31,7 @@ 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
34
+ from haystack.utils import Secret, deserialize_callable, serialize_callable
35
35
  from ibm_watsonx_ai import Credentials
36
36
  from ibm_watsonx_ai.foundation_models import ModelInference
37
37
 
@@ -201,12 +201,14 @@ class WatsonxChatGenerator:
201
201
  self.streaming_callback = streaming_callback
202
202
  self.tools = tools
203
203
 
204
- self._initialize_client()
204
+ self.client: ModelInference | None = None
205
205
 
206
- def _initialize_client(self) -> None:
207
- """Initialize the Watsonx client with configured credentials."""
208
- credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
206
+ def warm_up(self) -> None:
207
+ """Create the Watsonx client."""
208
+ if self.client is not None:
209
+ return
209
210
 
211
+ credentials = Credentials(api_key=self.api_key.resolve_value(), url=self.api_base_url)
210
212
  self.client = ModelInference(
211
213
  model_id=self.model,
212
214
  credentials=credentials,
@@ -248,7 +250,6 @@ class WatsonxChatGenerator:
248
250
  :returns:
249
251
  The deserialized component instance.
250
252
  """
251
- deserialize_secrets_inplace(data["init_parameters"], keys=["api_key", "project_id"])
252
253
  deserialize_tools_or_toolset_inplace(data["init_parameters"], key="tools")
253
254
  init_params = data.get("init_parameters", {})
254
255
  serialized_callback = init_params.get("streaming_callback")
@@ -272,8 +273,9 @@ class WatsonxChatGenerator:
272
273
  A list of ChatMessage instances representing the input messages.
273
274
  If a string is provided, it is converted to a list containing a ChatMessage with user role.
274
275
  :param generation_kwargs:
275
- Additional keyword arguments for text generation. These parameters will potentially override the parameters
276
- passed in the `__init__` method.
276
+ Additional keyword arguments for text generation. These are merged per key with the
277
+ `generation_kwargs` passed at initialization: keys provided here take precedence, keys set only
278
+ at initialization are kept.
277
279
  :param streaming_callback:
278
280
  A callback function that is called when a new token is received from the stream.
279
281
  If provided this will override the `streaming_callback` set in the `__init__` method.
@@ -288,6 +290,9 @@ class WatsonxChatGenerator:
288
290
  if not messages:
289
291
  return {"replies": []}
290
292
 
293
+ self.warm_up()
294
+ assert self.client is not None # noqa: S101
295
+
291
296
  resolved_streaming_callback = select_streaming_callback(
292
297
  init_callback=self.streaming_callback, runtime_callback=streaming_callback, requires_async=False
293
298
  )
@@ -315,8 +320,9 @@ class WatsonxChatGenerator:
315
320
  A list of ChatMessage instances representing the input messages.
316
321
  If a string is provided, it is converted to a list containing a ChatMessage with user role.
317
322
  :param generation_kwargs:
318
- Additional keyword arguments for text generation. These parameters will potentially override the parameters
319
- passed in the `__init__` method.
323
+ Additional keyword arguments for text generation. These are merged per key with the
324
+ `generation_kwargs` passed at initialization: keys provided here take precedence, keys set only
325
+ at initialization are kept.
320
326
  :param streaming_callback:
321
327
  A callback function that is called when a new token is received from the stream.
322
328
  If provided this will override the `streaming_callback` set in the `__init__` method.
@@ -331,6 +337,9 @@ class WatsonxChatGenerator:
331
337
  if not messages:
332
338
  return {"replies": []}
333
339
 
340
+ self.warm_up()
341
+ assert self.client is not None # noqa: S101
342
+
334
343
  resolved_streaming_callback = select_streaming_callback(
335
344
  init_callback=self.streaming_callback, runtime_callback=streaming_callback, requires_async=True
336
345
  )
@@ -420,7 +429,7 @@ class WatsonxChatGenerator:
420
429
  "model_version": chunk.get("model_version"),
421
430
  "created": chunk.get("created"),
422
431
  "created_at": chunk.get("created_at"),
423
- "received_at": datetime.now(timezone.utc).isoformat(),
432
+ "received_at": datetime.now(UTC).isoformat(),
424
433
  }
425
434
 
426
435
  if choice["delta"] and (choice_delta_tool_calls := choice["delta"].get("tool_calls")):
@@ -469,6 +478,7 @@ class WatsonxChatGenerator:
469
478
  :returns:
470
479
  A dictionary with the generated responses as ChatMessage instances.
471
480
  """
481
+ assert self.client is not None # noqa: S101
472
482
  chunks: list[StreamingChunk] = []
473
483
  stream = self.client.chat_stream(
474
484
  messages=api_args["messages"], params=api_args["params"], tools=api_args.get("tools")
@@ -501,6 +511,7 @@ class WatsonxChatGenerator:
501
511
 
502
512
  def _handle_standard(self, api_args: dict[str, Any]) -> dict[str, list[ChatMessage]]:
503
513
  """Handle synchronous standard response."""
514
+ assert self.client is not None # noqa: S101
504
515
  response = self.client.chat(
505
516
  messages=api_args["messages"], params=api_args["params"], tools=api_args.get("tools")
506
517
  )
@@ -513,6 +524,7 @@ class WatsonxChatGenerator:
513
524
  callback: StreamingCallbackT,
514
525
  ) -> dict[str, list[ChatMessage]]:
515
526
  """Handle asynchronous streaming response."""
527
+ assert self.client is not None # noqa: S101
516
528
  chunks: list[StreamingChunk] = []
517
529
  stream_generator = await self.client.achat_stream(
518
530
  messages=api_args["messages"], params=api_args["params"], tools=api_args.get("tools")
@@ -548,6 +560,7 @@ class WatsonxChatGenerator:
548
560
 
549
561
  async def _handle_async_standard(self, api_args: dict[str, Any]) -> dict[str, list[ChatMessage]]:
550
562
  """Handle asynchronous standard response."""
563
+ assert self.client is not None # noqa: S101
551
564
  response = await self.client.achat(
552
565
  messages=api_args["messages"], params=api_args["params"], tools=api_args.get("tools")
553
566
  )