nvidia-haystack 0.3.0__tar.gz → 0.5.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 (41) hide show
  1. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/CHANGELOG.md +40 -0
  2. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/PKG-INFO +12 -50
  3. nvidia_haystack-0.5.0/README.md +20 -0
  4. nvidia_haystack-0.5.0/examples/chat_generator_with_structured_outputs.py +34 -0
  5. nvidia_haystack-0.5.0/pydoc/config_docusaurus.yml +34 -0
  6. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/pyproject.toml +6 -10
  7. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/embedders/nvidia/document_embedder.py +23 -22
  8. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/embedders/nvidia/text_embedder.py +12 -12
  9. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/generators/nvidia/chat/chat_generator.py +23 -7
  10. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/generators/nvidia/generator.py +12 -13
  11. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/rankers/nvidia/ranker.py +12 -18
  12. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/utils/nvidia/client.py +4 -0
  13. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/utils/nvidia/models.py +4 -0
  14. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/utils/nvidia/nim_backend.py +6 -6
  15. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/conftest.py +3 -3
  16. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_document_embedder.py +14 -16
  17. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_generator.py +1 -1
  18. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_nim_backend.py +7 -3
  19. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_nvidia_chat_generator.py +253 -2
  20. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_ranker.py +0 -6
  21. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_text_embedder.py +5 -7
  22. nvidia_haystack-0.3.0/README.md +0 -58
  23. nvidia_haystack-0.3.0/pydoc/config.yml +0 -35
  24. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/.gitignore +0 -0
  25. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/LICENSE.txt +0 -0
  26. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/embedders/nvidia/__init__.py +0 -0
  27. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/embedders/nvidia/truncate.py +0 -0
  28. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/embedders/py.typed +0 -0
  29. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/generators/nvidia/__init__.py +0 -0
  30. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/generators/nvidia/chat/__init__.py +0 -0
  31. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/generators/py.typed +0 -0
  32. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/rankers/nvidia/__init__.py +0 -0
  33. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/rankers/nvidia/py.typed +0 -0
  34. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/components/rankers/nvidia/truncate.py +0 -0
  35. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/utils/nvidia/__init__.py +0 -0
  36. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/utils/nvidia/utils.py +0 -0
  37. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/src/haystack_integrations/utils/py.typed +0 -0
  38. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/__init__.py +0 -0
  39. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_base_url.py +0 -0
  40. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_embedding_truncate_mode.py +0 -0
  41. {nvidia_haystack-0.3.0 → nvidia_haystack-0.5.0}/tests/test_utils.py +0 -0
@@ -1,5 +1,45 @@
1
1
  # Changelog
2
2
 
3
+ ## [integrations/nvidia-v0.4.0] - 2025-10-23
4
+
5
+ ### 🚀 Features
6
+
7
+ - `NvidiaChatGenerator` add integration tests for mixing Tool/Toolset (#2422)
8
+
9
+ ### 📚 Documentation
10
+
11
+ - Add pydoc configurations for Docusaurus (#2411)
12
+ - Fix docstrings to avoid errors in API reference generation (#2423)
13
+
14
+ ### 🧪 Testing
15
+
16
+ - Make tests successfully run from forks (#2203)
17
+ - Remove deprecated NV-Embed-QA model from Nvidia tests (#2370)
18
+
19
+ ### ⚙️ CI
20
+
21
+ - Temporarily install `click<8.3.0` (#2288)
22
+
23
+ ### 🧹 Chores
24
+
25
+ - Remove black (#1985)
26
+ - Standardize readmes - part 2 (#2205)
27
+
28
+ ### 🌀 Miscellaneous
29
+
30
+ - Add structured output support in `NvidiaChatGenerator` (#2405)
31
+
32
+ ## [integrations/nvidia-v0.3.0] - 2025-06-20
33
+
34
+ ### 🐛 Bug Fixes
35
+
36
+ - Fix Nvidia types + add py.typed (#1970)
37
+
38
+ ### 🧹 Chores
39
+
40
+ - Align core-integrations Hatch scripts (#1898)
41
+ - Update md files for new hatch scripts (#1911)
42
+
3
43
  ## [integrations/nvidia-v0.2.0] - 2025-06-05
4
44
 
5
45
  ### 🚀 Features
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nvidia-haystack
3
- Version: 0.3.0
3
+ Version: 0.5.0
4
4
  Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/nvidia#readme
5
5
  Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
6
6
  Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/nvidia
@@ -18,7 +18,7 @@ Classifier: Programming Language :: Python :: 3.13
18
18
  Classifier: Programming Language :: Python :: Implementation :: CPython
19
19
  Classifier: Programming Language :: Python :: Implementation :: PyPy
20
20
  Requires-Python: >=3.9
21
- Requires-Dist: haystack-ai>=2.13.0
21
+ Requires-Dist: haystack-ai>=2.19.0
22
22
  Requires-Dist: requests>=2.25.0
23
23
  Requires-Dist: tqdm>=4.21.0
24
24
  Description-Content-Type: text/markdown
@@ -28,56 +28,18 @@ Description-Content-Type: text/markdown
28
28
  [![PyPI - Version](https://img.shields.io/pypi/v/nvidia-haystack.svg)](https://pypi.org/project/nvidia-haystack)
29
29
  [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nvidia-haystack.svg)](https://pypi.org/project/nvidia-haystack)
30
30
 
31
- ---
32
-
33
- **Table of Contents**
34
-
35
- - [nvidia-haystack](#nvidia-haystack)
36
- - [Installation](#installation)
37
- - [Contributing](#contributing)
38
- - [License](#license)
39
-
40
- ## Installation
31
+ - [Integration page](https://haystack.deepset.ai/integrations/nvidia)
32
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/nvidia/CHANGELOG.md)
41
33
 
42
- ```console
43
- pip install nvidia-haystack
44
- ```
34
+ ---
45
35
 
46
36
  ## Contributing
47
37
 
48
- `hatch` is the best way to interact with this project, to install it:
49
-
50
- ```sh
51
- pip install hatch
52
- ```
53
-
54
- With `hatch` installed, to run all the tests:
55
-
56
- ```
57
- hatch run test:all
58
- ```
59
-
60
- > Note: integration tests will be skipped unless the env var NVIDIA_API_KEY is set. The api key needs to be valid
61
- > in order to pass the tests.
62
-
63
- To only run unit tests:
64
-
65
- ```
66
- hatch run test:unit
67
- ```
68
-
69
- To format your code and perform linting using Ruff (with automatic fixes), run:
70
-
71
- ```
72
- hatch run fmt
73
- ```
74
-
75
- To check for static type errors, run:
76
-
77
- ```console
78
- $ hatch run test:types
79
- ```
80
-
81
- ## License
38
+ Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
82
39
 
83
- `nvidia-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
40
+ To run integration tests locally, you need to export the `NVIDIA_API_KEY` environment variable. Some tests require additional environment variables:
41
+ - `NVIDIA_NIM_EMBEDDER_MODEL`
42
+ - `NVIDIA_NIM_ENDPOINT_URL`
43
+ - `NVIDIA_NIM_GENERATOR_MODEL`
44
+ - `NVIDIA_NIM_RANKER_MODEL`
45
+ - `NVIDIA_NIM_RANKER_ENDPOINT_URL`
@@ -0,0 +1,20 @@
1
+ # nvidia-haystack
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/nvidia-haystack.svg)](https://pypi.org/project/nvidia-haystack)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/nvidia-haystack.svg)](https://pypi.org/project/nvidia-haystack)
5
+
6
+ - [Integration page](https://haystack.deepset.ai/integrations/nvidia)
7
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/nvidia/CHANGELOG.md)
8
+
9
+ ---
10
+
11
+ ## Contributing
12
+
13
+ Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
14
+
15
+ To run integration tests locally, you need to export the `NVIDIA_API_KEY` environment variable. Some tests require additional environment variables:
16
+ - `NVIDIA_NIM_EMBEDDER_MODEL`
17
+ - `NVIDIA_NIM_ENDPOINT_URL`
18
+ - `NVIDIA_NIM_GENERATOR_MODEL`
19
+ - `NVIDIA_NIM_RANKER_MODEL`
20
+ - `NVIDIA_NIM_RANKER_ENDPOINT_URL`
@@ -0,0 +1,34 @@
1
+ # SPDX-FileCopyrightText: 2024-present deepset GmbH <info@deepset.ai>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+
5
+
6
+ # This example demonstrates how to use the NvidiaChatGenerator component
7
+ # with structured outputs.
8
+ # To run this example, you will need to
9
+ # set `NVIDIA_API_KEY` environment variable
10
+
11
+ from haystack.dataclasses import ChatMessage
12
+
13
+ from haystack_integrations.components.generators.nvidia import NvidiaChatGenerator
14
+
15
+ json_schema = {
16
+ "type": "object",
17
+ "properties": {"title": {"type": "string"}, "rating": {"type": "number"}},
18
+ "required": ["title", "rating"],
19
+ }
20
+ chat_messages = [
21
+ ChatMessage.from_user(
22
+ """
23
+ Return the title and the rating based on the following movie review according
24
+ to the provided json schema.
25
+ Review: Inception is a really well made film. I rate it four stars out of five."""
26
+ )
27
+ ]
28
+
29
+ component = NvidiaChatGenerator(
30
+ model="meta/llama-3.1-70b-instruct",
31
+ generation_kwargs={"extra_body": {"nvext": {"guided_json": json_schema}}},
32
+ )
33
+ results = component.run(chat_messages)
34
+ # print(results)
@@ -0,0 +1,34 @@
1
+ loaders:
2
+ - ignore_when_discovered:
3
+ - __init__
4
+ modules:
5
+ - haystack_integrations.components.embedders.nvidia.document_embedder
6
+ - haystack_integrations.components.embedders.nvidia.text_embedder
7
+ - haystack_integrations.components.embedders.nvidia.truncate
8
+ - haystack_integrations.components.generators.nvidia.generator
9
+ - haystack_integrations.components.generators.nvidia.chat.chat_generator
10
+ - haystack_integrations.components.rankers.nvidia.ranker
11
+ - haystack_integrations.components.rankers.nvidia.truncate
12
+ search_path:
13
+ - ../src
14
+ type: haystack_pydoc_tools.loaders.CustomPythonLoader
15
+ processors:
16
+ - do_not_filter_modules: false
17
+ documented_only: true
18
+ expression: null
19
+ skip_empty_modules: true
20
+ type: filter
21
+ - type: smart
22
+ - type: crossref
23
+ renderer:
24
+ description: Nvidia integration for Haystack
25
+ id: integrations-nvidia
26
+ markdown:
27
+ add_member_class_prefix: false
28
+ add_method_class_prefix: true
29
+ classdef_code_block: false
30
+ descriptive_class_title: false
31
+ descriptive_module_title: true
32
+ filename: nvidia.md
33
+ title: Nvidia
34
+ type: haystack_pydoc_tools.renderers.DocusaurusRenderer
@@ -23,7 +23,7 @@ classifiers = [
23
23
  "Programming Language :: Python :: Implementation :: CPython",
24
24
  "Programming Language :: Python :: Implementation :: PyPy",
25
25
  ]
26
- dependencies = ["haystack-ai>=2.13.0", "requests>=2.25.0", "tqdm>=4.21.0"]
26
+ dependencies = ["haystack-ai>=2.19.0", "requests>=2.25.0", "tqdm>=4.21.0"]
27
27
 
28
28
  [project.urls]
29
29
  Documentation = "https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/nvidia#readme"
@@ -46,8 +46,8 @@ installer = "uv"
46
46
  dependencies = ["haystack-pydoc-tools", "ruff"]
47
47
 
48
48
  [tool.hatch.envs.default.scripts]
49
- docs = ["pydoc-markdown pydoc/config.yml"]
50
- fmt = "ruff check --fix {args} && ruff format {args}"
49
+ docs = ["pydoc-markdown pydoc/config_docusaurus.yml"]
50
+ fmt = "ruff check --fix {args}; ruff format {args}"
51
51
  fmt-check = "ruff check {args} && ruff format --check {args}"
52
52
 
53
53
  [tool.hatch.envs.test]
@@ -66,7 +66,7 @@ dependencies = [
66
66
  unit = 'pytest -m "not integration" {args:tests}'
67
67
  integration = 'pytest -m "integration" {args:tests}'
68
68
  all = 'pytest {args:tests}'
69
- cov-retry = 'all --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x'
69
+ cov-retry = 'pytest --cov=haystack_integrations --reruns 3 --reruns-delay 30 -x {args:tests}'
70
70
 
71
71
  types = """mypy -p haystack_integrations.components.embedders.nvidia \
72
72
  -p haystack_integrations.components.generators.nvidia \
@@ -80,13 +80,9 @@ check_untyped_defs = true
80
80
  disallow_incomplete_defs = true
81
81
 
82
82
 
83
- [tool.black]
84
- target-version = ["py38"]
85
- line-length = 120
86
- skip-string-normalization = true
87
83
 
88
84
  [tool.ruff]
89
- target-version = "py38"
85
+ target-version = "py39"
90
86
  line-length = 120
91
87
 
92
88
  [tool.ruff.lint]
@@ -164,4 +160,4 @@ addopts = "--strict-markers"
164
160
  markers = [
165
161
  "integration: integration tests",
166
162
  ]
167
- log_cli = true
163
+ log_cli = true
@@ -4,7 +4,8 @@
4
4
 
5
5
  import os
6
6
  import warnings
7
- from typing import Any, Dict, List, Optional, Tuple, Union
7
+ from dataclasses import replace
8
+ from typing import Any, Optional, Union
8
9
 
9
10
  from haystack import Document, component, default_from_dict, default_to_dict, logging
10
11
  from haystack.utils import Secret, deserialize_secrets_inplace
@@ -28,7 +29,7 @@ class NvidiaDocumentEmbedder:
28
29
 
29
30
  doc = Document(content="I love pizza!")
30
31
 
31
- text_embedder = NvidiaDocumentEmbedder(model="NV-Embed-QA", api_url="https://ai.api.nvidia.com/v1/retrieval/nvidia")
32
+ text_embedder = NvidiaDocumentEmbedder(model="nvidia/nv-embedqa-e5-v5", api_url="https://integrate.api.nvidia.com/v1")
32
33
  text_embedder.warm_up()
33
34
 
34
35
  result = document_embedder.run([doc])
@@ -45,11 +46,11 @@ class NvidiaDocumentEmbedder:
45
46
  suffix: str = "",
46
47
  batch_size: int = 32,
47
48
  progress_bar: bool = True,
48
- meta_fields_to_embed: Optional[List[str]] = None,
49
+ meta_fields_to_embed: Optional[list[str]] = None,
49
50
  embedding_separator: str = "\n",
50
51
  truncate: Optional[Union[EmbeddingTruncateMode, str]] = None,
51
52
  timeout: Optional[float] = None,
52
- ):
53
+ ) -> None:
53
54
  """
54
55
  Create a NvidiaTextEmbedder component.
55
56
 
@@ -61,7 +62,7 @@ class NvidiaDocumentEmbedder:
61
62
  API key for the NVIDIA NIM.
62
63
  :param api_url:
63
64
  Custom API URL for the NVIDIA NIM.
64
- Format for API URL is http://host:port
65
+ Format for API URL is `http://host:port`
65
66
  :param prefix:
66
67
  A string to add to the beginning of each text.
67
68
  :param suffix:
@@ -108,7 +109,7 @@ class NvidiaDocumentEmbedder:
108
109
  def class_name(cls) -> str:
109
110
  return "NvidiaDocumentEmbedder"
110
111
 
111
- def default_model(self):
112
+ def default_model(self) -> None:
112
113
  """Set default model in local NIM mode."""
113
114
  valid_models = [
114
115
  model.id for model in self.available_models if not model.base_model or model.base_model == model.id
@@ -129,7 +130,7 @@ class NvidiaDocumentEmbedder:
129
130
  error_message = "No locally hosted model was found."
130
131
  raise ValueError(error_message)
131
132
 
132
- def warm_up(self):
133
+ def warm_up(self) -> None:
133
134
  """
134
135
  Initializes the component.
135
136
  """
@@ -156,7 +157,7 @@ class NvidiaDocumentEmbedder:
156
157
  if not self.model:
157
158
  self.default_model()
158
159
 
159
- def to_dict(self) -> Dict[str, Any]:
160
+ def to_dict(self) -> dict[str, Any]:
160
161
  """
161
162
  Serializes the component to a dictionary.
162
163
 
@@ -179,14 +180,14 @@ class NvidiaDocumentEmbedder:
179
180
  )
180
181
 
181
182
  @property
182
- def available_models(self) -> List[Model]:
183
+ def available_models(self) -> list[Model]:
183
184
  """
184
185
  Get a list of available models that work with NvidiaDocumentEmbedder.
185
186
  """
186
187
  return self.backend.models() if self.backend else []
187
188
 
188
189
  @classmethod
189
- def from_dict(cls, data: Dict[str, Any]) -> "NvidiaDocumentEmbedder":
190
+ def from_dict(cls, data: dict[str, Any]) -> "NvidiaDocumentEmbedder":
190
191
  """
191
192
  Deserializes the component from a dictionary.
192
193
 
@@ -200,7 +201,7 @@ class NvidiaDocumentEmbedder:
200
201
  deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
201
202
  return default_from_dict(cls, data)
202
203
 
203
- def _prepare_texts_to_embed(self, documents: List[Document]) -> List[str]:
204
+ def _prepare_texts_to_embed(self, documents: list[Document]) -> list[str]:
204
205
  texts_to_embed = []
205
206
  for doc in documents:
206
207
  meta_values_to_embed = [
@@ -213,8 +214,8 @@ class NvidiaDocumentEmbedder:
213
214
 
214
215
  return texts_to_embed
215
216
 
216
- def _embed_batch(self, texts_to_embed: List[str], batch_size: int) -> Tuple[List[List[float]], Dict[str, Any]]:
217
- all_embeddings: List[List[float]] = []
217
+ def _embed_batch(self, texts_to_embed: list[str], batch_size: int) -> tuple[list[list[float]], dict[str, Any]]:
218
+ all_embeddings: list[list[float]] = []
218
219
  usage_prompt_tokens = 0
219
220
  usage_total_tokens = 0
220
221
 
@@ -233,8 +234,8 @@ class NvidiaDocumentEmbedder:
233
234
 
234
235
  return all_embeddings, {"usage": {"prompt_tokens": usage_prompt_tokens, "total_tokens": usage_total_tokens}}
235
236
 
236
- @component.output_types(documents=List[Document], meta=Dict[str, Any])
237
- def run(self, documents: List[Document]) -> Dict[str, Union[List[Document], Dict[str, Any]]]:
237
+ @component.output_types(documents=list[Document], meta=dict[str, Any])
238
+ def run(self, documents: list[Document]) -> dict[str, Union[list[Document], dict[str, Any]]]:
238
239
  """
239
240
  Embed a list of Documents.
240
241
 
@@ -246,14 +247,12 @@ class NvidiaDocumentEmbedder:
246
247
  A dictionary with the following keys and values:
247
248
  - `documents` - List of processed Documents with embeddings.
248
249
  - `meta` - Metadata on usage statistics, etc.
249
- :raises RuntimeError:
250
- If the component was not initialized.
251
250
  :raises TypeError:
252
- If the input is not a string.
251
+ If the input is not a list of Documents.
253
252
  """
254
253
  if not self._initialized:
255
- msg = "The embedding model has not been loaded. Please call warm_up() before running."
256
- raise RuntimeError(msg)
254
+ self.warm_up()
255
+
257
256
  elif not isinstance(documents, list) or (documents and not isinstance(documents[0], Document)):
258
257
  msg = (
259
258
  "NvidiaDocumentEmbedder expects a list of Documents as input."
@@ -267,7 +266,9 @@ class NvidiaDocumentEmbedder:
267
266
 
268
267
  texts_to_embed = self._prepare_texts_to_embed(documents)
269
268
  embeddings, metadata = self._embed_batch(texts_to_embed, self.batch_size)
269
+
270
+ new_documents = []
270
271
  for doc, emb in zip(documents, embeddings):
271
- doc.embedding = emb
272
+ new_documents.append(replace(doc, embedding=emb))
272
273
 
273
- return {"documents": documents, "meta": metadata}
274
+ return {"documents": new_documents, "meta": metadata}
@@ -4,7 +4,7 @@
4
4
 
5
5
  import os
6
6
  import warnings
7
- from typing import Any, Dict, List, Optional, Union
7
+ from typing import Any, Optional, Union
8
8
 
9
9
  from haystack import component, default_from_dict, default_to_dict, logging
10
10
  from haystack.utils import Secret, deserialize_secrets_inplace
@@ -30,7 +30,7 @@ class NvidiaTextEmbedder:
30
30
 
31
31
  text_to_embed = "I love pizza!"
32
32
 
33
- text_embedder = NvidiaTextEmbedder(model="NV-Embed-QA", api_url="https://ai.api.nvidia.com/v1/retrieval/nvidia")
33
+ text_embedder = NvidiaTextEmbedder(model="nvidia/nv-embedqa-e5-v5", api_url="https://integrate.api.nvidia.com/v1")
34
34
  text_embedder.warm_up()
35
35
 
36
36
  print(text_embedder.run(text_to_embed))
@@ -58,7 +58,7 @@ class NvidiaTextEmbedder:
58
58
  API key for the NVIDIA NIM.
59
59
  :param api_url:
60
60
  Custom API URL for the NVIDIA NIM.
61
- Format for API URL is http://host:port
61
+ Format for API URL is `http://host:port`
62
62
  :param prefix:
63
63
  A string to add to the beginning of each text.
64
64
  :param suffix:
@@ -146,7 +146,7 @@ class NvidiaTextEmbedder:
146
146
  else:
147
147
  self.default_model()
148
148
 
149
- def to_dict(self) -> Dict[str, Any]:
149
+ def to_dict(self) -> dict[str, Any]:
150
150
  """
151
151
  Serializes the component to a dictionary.
152
152
 
@@ -165,14 +165,14 @@ class NvidiaTextEmbedder:
165
165
  )
166
166
 
167
167
  @property
168
- def available_models(self) -> List[Model]:
168
+ def available_models(self) -> list[Model]:
169
169
  """
170
170
  Get a list of available models that work with NvidiaTextEmbedder.
171
171
  """
172
172
  return self.backend.models() if self.backend else []
173
173
 
174
174
  @classmethod
175
- def from_dict(cls, data: Dict[str, Any]) -> "NvidiaTextEmbedder":
175
+ def from_dict(cls, data: dict[str, Any]) -> "NvidiaTextEmbedder":
176
176
  """
177
177
  Deserializes the component from a dictionary.
178
178
 
@@ -186,8 +186,8 @@ class NvidiaTextEmbedder:
186
186
  deserialize_secrets_inplace(data["init_parameters"], keys=["api_key"])
187
187
  return default_from_dict(cls, data)
188
188
 
189
- @component.output_types(embedding=List[float], meta=Dict[str, Any])
190
- def run(self, text: str) -> Dict[str, Union[List[float], Dict[str, Any]]]:
189
+ @component.output_types(embedding=list[float], meta=dict[str, Any])
190
+ def run(self, text: str) -> dict[str, Union[list[float], dict[str, Any]]]:
191
191
  """
192
192
  Embed a string.
193
193
 
@@ -197,14 +197,14 @@ class NvidiaTextEmbedder:
197
197
  A dictionary with the following keys and values:
198
198
  - `embedding` - Embedding of the text.
199
199
  - `meta` - Metadata on usage statistics, etc.
200
- :raises RuntimeError:
201
- If the component was not initialized.
202
200
  :raises TypeError:
203
201
  If the input is not a string.
202
+ :raises ValueError:
203
+ If the input string is empty.
204
204
  """
205
205
  if not self._initialized:
206
- msg = "The embedding model has not been loaded. Please call warm_up() before running."
207
- raise RuntimeError(msg)
206
+ self.warm_up()
207
+
208
208
  elif not isinstance(text, str):
209
209
  msg = (
210
210
  "NvidiaTextEmbedder expects a string as an input."
@@ -3,12 +3,12 @@
3
3
  # SPDX-License-Identifier: Apache-2.0
4
4
 
5
5
  import os
6
- from typing import Any, Dict, List, Optional, Union
6
+ from typing import Any, Optional
7
7
 
8
8
  from haystack import component, default_to_dict, logging
9
9
  from haystack.components.generators.chat import OpenAIChatGenerator
10
10
  from haystack.dataclasses import StreamingCallbackT
11
- from haystack.tools import Tool, Toolset, serialize_tools_or_toolset
11
+ from haystack.tools import ToolsType, serialize_tools_or_toolset
12
12
  from haystack.utils import serialize_callable
13
13
  from haystack.utils.auth import Secret
14
14
 
@@ -55,12 +55,12 @@ class NvidiaChatGenerator(OpenAIChatGenerator):
55
55
  model: str = "meta/llama-3.1-8b-instruct",
56
56
  streaming_callback: Optional[StreamingCallbackT] = None,
57
57
  api_base_url: Optional[str] = os.getenv("NVIDIA_API_URL", DEFAULT_API_URL),
58
- generation_kwargs: Optional[Dict[str, Any]] = None,
59
- tools: Optional[Union[List[Tool], Toolset]] = None,
58
+ generation_kwargs: Optional[dict[str, Any]] = None,
59
+ tools: Optional[ToolsType] = None,
60
60
  timeout: Optional[float] = None,
61
61
  max_retries: Optional[int] = None,
62
- http_client_kwargs: Optional[Dict[str, Any]] = None,
63
- ):
62
+ http_client_kwargs: Optional[dict[str, Any]] = None,
63
+ ) -> None:
64
64
  """
65
65
  Creates an instance of NvidiaChatGenerator.
66
66
 
@@ -86,6 +86,22 @@ class NvidiaChatGenerator(OpenAIChatGenerator):
86
86
  comprising the top 10% probability mass are considered.
87
87
  - `stream`: Whether to stream back partial progress. If set, tokens will be sent as data-only server-sent
88
88
  events as they become available, with the stream terminated by a data: [DONE] message.
89
+ - `response_format`: For NVIDIA NIM servers, this parameter has limited support.
90
+ - The basic JSON mode with `{"type": "json_object"}` is supported by compatible models, to produce
91
+ valid JSON output.
92
+ To pass the JSON schema to the model, use the `guided_json` parameter in `extra_body`.
93
+ For example:
94
+ ```python
95
+ generation_kwargs={
96
+ "extra_body": {
97
+ "nvext": {
98
+ "guided_json": {
99
+ json_schema
100
+ }
101
+ }
102
+ }
103
+ ```
104
+ For more details, see the [NVIDIA NIM documentation](https://docs.nvidia.com/nim/large-language-models/latest/structured-generation.html).
89
105
  :param tools:
90
106
  A list of tools or a Toolset for which the model can prepare calls. This parameter can accept either a
91
107
  list of `Tool` objects or a `Toolset` instance.
@@ -110,7 +126,7 @@ class NvidiaChatGenerator(OpenAIChatGenerator):
110
126
  http_client_kwargs=http_client_kwargs,
111
127
  )
112
128
 
113
- def to_dict(self) -> Dict[str, Any]:
129
+ def to_dict(self) -> dict[str, Any]:
114
130
  """
115
131
  Serialize this component to a dictionary.
116
132
 
@@ -4,7 +4,7 @@
4
4
 
5
5
  import os
6
6
  import warnings
7
- from typing import Any, Dict, List, Optional, Union
7
+ from typing import Any, Optional, Union
8
8
 
9
9
  from haystack import component, default_from_dict, default_to_dict
10
10
  from haystack.utils.auth import Secret, deserialize_secrets_inplace
@@ -24,7 +24,7 @@ class NvidiaGenerator:
24
24
  from haystack_integrations.components.generators.nvidia import NvidiaGenerator
25
25
 
26
26
  generator = NvidiaGenerator(
27
- model="meta/llama3-70b-instruct",
27
+ model="meta/llama3-8b-instruct",
28
28
  model_arguments={
29
29
  "temperature": 0.2,
30
30
  "top_p": 0.7,
@@ -47,9 +47,9 @@ class NvidiaGenerator:
47
47
  model: Optional[str] = None,
48
48
  api_url: str = os.getenv("NVIDIA_API_URL", DEFAULT_API_URL),
49
49
  api_key: Optional[Secret] = Secret.from_env_var("NVIDIA_API_KEY"),
50
- model_arguments: Optional[Dict[str, Any]] = None,
50
+ model_arguments: Optional[dict[str, Any]] = None,
51
51
  timeout: Optional[float] = None,
52
- ):
52
+ ) -> None:
53
53
  """
54
54
  Create a NvidiaGenerator component.
55
55
 
@@ -90,7 +90,7 @@ class NvidiaGenerator:
90
90
  def class_name(cls) -> str:
91
91
  return "NvidiaGenerator"
92
92
 
93
- def default_model(self):
93
+ def default_model(self) -> None:
94
94
  """Set default model in local NIM mode."""
95
95
  valid_models = [
96
96
  model.id for model in self.available_models if not model.base_model or model.base_model == model.id
@@ -111,7 +111,7 @@ class NvidiaGenerator:
111
111
  error_message = "No locally hosted model was found."
112
112
  raise ValueError(error_message)
113
113
 
114
- def warm_up(self):
114
+ def warm_up(self) -> None:
115
115
  """
116
116
  Initializes the component.
117
117
  """
@@ -134,7 +134,7 @@ class NvidiaGenerator:
134
134
  else:
135
135
  self.default_model()
136
136
 
137
- def to_dict(self) -> Dict[str, Any]:
137
+ def to_dict(self) -> dict[str, Any]:
138
138
  """
139
139
  Serializes the component to a dictionary.
140
140
 
@@ -150,14 +150,14 @@ class NvidiaGenerator:
150
150
  )
151
151
 
152
152
  @property
153
- def available_models(self) -> List[Model]:
153
+ def available_models(self) -> list[Model]:
154
154
  """
155
155
  Get a list of available models that work with ChatNVIDIA.
156
156
  """
157
157
  return self.backend.models() if self.backend else []
158
158
 
159
159
  @classmethod
160
- def from_dict(cls, data: Dict[str, Any]) -> "NvidiaGenerator":
160
+ def from_dict(cls, data: dict[str, Any]) -> "NvidiaGenerator":
161
161
  """
162
162
  Deserializes the component from a dictionary.
163
163
 
@@ -170,8 +170,8 @@ class NvidiaGenerator:
170
170
  deserialize_secrets_inplace(init_params, ["api_key"])
171
171
  return default_from_dict(cls, data)
172
172
 
173
- @component.output_types(replies=List[str], meta=List[Dict[str, Any]])
174
- def run(self, prompt: str) -> Dict[str, Union[List[str], List[Dict[str, Any]]]]:
173
+ @component.output_types(replies=list[str], meta=list[dict[str, Any]])
174
+ def run(self, prompt: str) -> dict[str, Union[list[str], list[dict[str, Any]]]]:
175
175
  """
176
176
  Queries the model with the provided prompt.
177
177
 
@@ -183,8 +183,7 @@ class NvidiaGenerator:
183
183
  - `meta` - Metadata for each reply.
184
184
  """
185
185
  if self.backend is None:
186
- msg = "The generation model has not been loaded. Call warm_up() before running."
187
- raise RuntimeError(msg)
186
+ self.warm_up()
188
187
 
189
188
  assert self.backend is not None
190
189
  replies, meta = self.backend.generate(prompt=prompt)