Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
sjrl committed Nov 14, 2024
1 parent cb6aa3e commit 8029e92
Show file tree
Hide file tree
Showing 22 changed files with 71 additions and 24 deletions.
2 changes: 1 addition & 1 deletion integrations/nvidia/src/haystack_integrations/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand All @@ -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"


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand All @@ -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"


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# 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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion integrations/nvidia/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion integrations/nvidia/tests/test_base_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion integrations/nvidia/tests/test_document_embedder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
2 changes: 1 addition & 1 deletion integrations/nvidia/tests/test_embedding_truncate_mode.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down
47 changes: 46 additions & 1 deletion integrations/nvidia/tests/test_ranker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down Expand Up @@ -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")
2 changes: 1 addition & 1 deletion integrations/nvidia/tests/test_text_embedder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2022-present deepset GmbH <[email protected]>
# SPDX-FileCopyrightText: 2024-present deepset GmbH <[email protected]>
#
# SPDX-License-Identifier: Apache-2.0

Expand Down

0 comments on commit 8029e92

Please sign in to comment.