From 8029e927eedfc34630dd27ad697a02f83013c242 Mon Sep 17 00:00:00 2001 From: Sebastian Husch Lee Date: Thu, 14 Nov 2024 13:37:05 +0100 Subject: [PATCH] updates --- .../src/haystack_integrations/__init__.py | 2 +- .../components/__init__.py | 2 +- .../components/embedders/__init__.py | 2 +- .../components/embedders/nvidia/__init__.py | 2 +- .../embedders/nvidia/document_embedder.py | 3 +- .../embedders/nvidia/text_embedder.py | 3 +- .../components/embedders/nvidia/truncate.py | 2 +- .../components/generators/__init__.py | 3 ++ .../components/rankers/__init__.py | 2 +- .../components/rankers/nvidia/__init__.py | 2 +- .../components/rankers/nvidia/ranker.py | 5 +- .../components/rankers/nvidia/truncate.py | 2 +- .../haystack_integrations/utils/__init__.py | 2 +- .../utils/nvidia/__init__.py | 2 +- .../utils/nvidia/nim_backend.py | 2 +- .../utils/nvidia/utils.py | 2 +- integrations/nvidia/tests/conftest.py | 2 +- integrations/nvidia/tests/test_base_url.py | 2 +- .../nvidia/tests/test_document_embedder.py | 2 +- .../tests/test_embedding_truncate_mode.py | 2 +- integrations/nvidia/tests/test_ranker.py | 47 ++++++++++++++++++- .../nvidia/tests/test_text_embedder.py | 2 +- 22 files changed, 71 insertions(+), 24 deletions(-) diff --git a/integrations/nvidia/src/haystack_integrations/__init__.py b/integrations/nvidia/src/haystack_integrations/__init__.py index c1764a6e0..6b5e14dc1 100644 --- a/integrations/nvidia/src/haystack_integrations/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/__init__.py b/integrations/nvidia/src/haystack_integrations/components/__init__.py index c1764a6e0..6b5e14dc1 100644 --- a/integrations/nvidia/src/haystack_integrations/components/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/components/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/embedders/__init__.py b/integrations/nvidia/src/haystack_integrations/components/embedders/__init__.py index c1764a6e0..6b5e14dc1 100644 --- a/integrations/nvidia/src/haystack_integrations/components/embedders/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/components/embedders/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/__init__.py b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/__init__.py index 95cd51547..827ad7dc6 100644 --- a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/__init__.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/document_embedder.py b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/document_embedder.py index c62359c95..606ec78fd 100644 --- a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/document_embedder.py +++ b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/document_embedder.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 @@ -12,7 +12,6 @@ from haystack_integrations.components.embedders.nvidia.truncate import EmbeddingTruncateMode from haystack_integrations.utils.nvidia import NimBackend, is_hosted, url_validation - _DEFAULT_API_URL = "https://ai.api.nvidia.com/v1/retrieval/nvidia" diff --git a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/text_embedder.py b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/text_embedder.py index 7191b2592..4b7072f33 100644 --- a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/text_embedder.py +++ b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/text_embedder.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 @@ -11,7 +11,6 @@ from haystack_integrations.components.embedders.nvidia.truncate import EmbeddingTruncateMode from haystack_integrations.utils.nvidia import NimBackend, is_hosted, url_validation - _DEFAULT_API_URL = "https://ai.api.nvidia.com/v1/retrieval/nvidia" diff --git a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/truncate.py b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/truncate.py index 39e38c259..931c3cce3 100644 --- a/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/truncate.py +++ b/integrations/nvidia/src/haystack_integrations/components/embedders/nvidia/truncate.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/generators/__init__.py b/integrations/nvidia/src/haystack_integrations/components/generators/__init__.py index e69de29bb..6b5e14dc1 100644 --- a/integrations/nvidia/src/haystack_integrations/components/generators/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/components/generators/__init__.py @@ -0,0 +1,3 @@ +# SPDX-FileCopyrightText: 2024-present deepset GmbH +# +# SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/rankers/__init__.py b/integrations/nvidia/src/haystack_integrations/components/rankers/__init__.py index c1764a6e0..6b5e14dc1 100644 --- a/integrations/nvidia/src/haystack_integrations/components/rankers/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/components/rankers/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/__init__.py b/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/__init__.py index 35e3565a0..05daa1c54 100644 --- a/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/__init__.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/ranker.py b/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/ranker.py index 278a25120..9938b37d1 100644 --- a/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/ranker.py +++ b/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/ranker.py @@ -1,7 +1,8 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 +import warnings from typing import Any, Dict, List, Optional, Union from haystack import Document, component, default_from_dict, default_to_dict, logging @@ -10,7 +11,6 @@ from haystack_integrations.components.rankers.nvidia.truncate import RankerTruncateMode from haystack_integrations.utils.nvidia import NimBackend, url_validation - logger = logging.getLogger(__name__) _DEFAULT_MODEL = "nvidia/nv-rerankqa-mistral-4b-v3" @@ -196,6 +196,7 @@ def run( top_k = top_k if top_k is not None else self._top_k if top_k < 1: logger.warning("top_k should be at least 1, returning nothing") + warnings.warn("top_k should be at least 1, returning nothing", stacklevel=2) return {"documents": []} assert self._backend is not None diff --git a/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/truncate.py b/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/truncate.py index 58ce0f4c3..649ceaf9d 100644 --- a/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/truncate.py +++ b/integrations/nvidia/src/haystack_integrations/components/rankers/nvidia/truncate.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/utils/__init__.py b/integrations/nvidia/src/haystack_integrations/utils/__init__.py index c1764a6e0..6b5e14dc1 100644 --- a/integrations/nvidia/src/haystack_integrations/utils/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/utils/__init__.py @@ -1,3 +1,3 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/utils/nvidia/__init__.py b/integrations/nvidia/src/haystack_integrations/utils/nvidia/__init__.py index 93c5fa119..f08cda6cd 100644 --- a/integrations/nvidia/src/haystack_integrations/utils/nvidia/__init__.py +++ b/integrations/nvidia/src/haystack_integrations/utils/nvidia/__init__.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/utils/nvidia/nim_backend.py b/integrations/nvidia/src/haystack_integrations/utils/nvidia/nim_backend.py index e37aa8735..0279cf608 100644 --- a/integrations/nvidia/src/haystack_integrations/utils/nvidia/nim_backend.py +++ b/integrations/nvidia/src/haystack_integrations/utils/nvidia/nim_backend.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/src/haystack_integrations/utils/nvidia/utils.py b/integrations/nvidia/src/haystack_integrations/utils/nvidia/utils.py index 204b9bf45..f07989405 100644 --- a/integrations/nvidia/src/haystack_integrations/utils/nvidia/utils.py +++ b/integrations/nvidia/src/haystack_integrations/utils/nvidia/utils.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/tests/conftest.py b/integrations/nvidia/tests/conftest.py index 93b09b59d..b6346c672 100644 --- a/integrations/nvidia/tests/conftest.py +++ b/integrations/nvidia/tests/conftest.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/tests/test_base_url.py b/integrations/nvidia/tests/test_base_url.py index 60cee8020..506fbc385 100644 --- a/integrations/nvidia/tests/test_base_url.py +++ b/integrations/nvidia/tests/test_base_url.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/tests/test_document_embedder.py b/integrations/nvidia/tests/test_document_embedder.py index e662674d9..4a62746bb 100644 --- a/integrations/nvidia/tests/test_document_embedder.py +++ b/integrations/nvidia/tests/test_document_embedder.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/tests/test_embedding_truncate_mode.py b/integrations/nvidia/tests/test_embedding_truncate_mode.py index be275a1df..16f9112ea 100644 --- a/integrations/nvidia/tests/test_embedding_truncate_mode.py +++ b/integrations/nvidia/tests/test_embedding_truncate_mode.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 diff --git a/integrations/nvidia/tests/test_ranker.py b/integrations/nvidia/tests/test_ranker.py index c1bb57651..d66bb0f65 100644 --- a/integrations/nvidia/tests/test_ranker.py +++ b/integrations/nvidia/tests/test_ranker.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0 @@ -260,3 +260,48 @@ def test_warm_up_once(self, monkeypatch) -> None: backend = client._backend client.warm_up() assert backend == client._backend + + def test_to_dict(self) -> None: + client = NvidiaRanker() + assert client.to_dict() == { + "type": "haystack_integrations.components.rankers.nvidia.ranker.NvidiaRanker", + "init_parameters": { + "model": "nvidia/nv-rerankqa-mistral-4b-v3", + "top_k": 5, + "truncate": None, + "api_url": None, + "api_key": {"type": "env_var", "env_vars": ["NVIDIA_API_KEY"], "strict": True}, + }, + } + + def test_from_dict(self) -> None: + client = NvidiaRanker.from_dict( + { + "type": "haystack_integrations.components.rankers.nvidia.ranker.NvidiaRanker", + "init_parameters": { + "model": "nvidia/nv-rerankqa-mistral-4b-v3", + "top_k": 5, + "truncate": None, + "api_url": None, + "api_key": {"type": "env_var", "env_vars": ["NVIDIA_API_KEY"], "strict": True}, + }, + } + ) + assert client._model == "nvidia/nv-rerankqa-mistral-4b-v3" + assert client._top_k == 5 + assert client._truncate is None + assert client._api_url is None + assert client._api_key == Secret.from_env_var("NVIDIA_API_KEY") + + def test_from_dict_defaults(self) -> None: + client = NvidiaRanker.from_dict( + { + "type": "haystack_integrations.components.rankers.nvidia.ranker.NvidiaRanker", + "init_parameters": {}, + } + ) + assert client._model == "nvidia/nv-rerankqa-mistral-4b-v3" + assert client._top_k == 5 + assert client._truncate is None + assert client._api_url is None + assert client._api_key == Secret.from_env_var("NVIDIA_API_KEY") diff --git a/integrations/nvidia/tests/test_text_embedder.py b/integrations/nvidia/tests/test_text_embedder.py index 97ffbd5d1..87981ba65 100644 --- a/integrations/nvidia/tests/test_text_embedder.py +++ b/integrations/nvidia/tests/test_text_embedder.py @@ -1,4 +1,4 @@ -# SPDX-FileCopyrightText: 2022-present deepset GmbH +# SPDX-FileCopyrightText: 2024-present deepset GmbH # # SPDX-License-Identifier: Apache-2.0