Skip to content

Commit

Permalink
feat: update default embedding model to nvidia/nv-embedqa-e5-v5 (#1015)
Browse files Browse the repository at this point in the history
* add tests for preview embedding apis

* update default model to nvidia/nv-embedqa-e5-v5

* lint fixes w/ latest versions of black, isort, hatch
  • Loading branch information
mattf authored Aug 26, 2024
1 parent 6b07663 commit 8544b56
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def __init__(
self._initialized = False

if is_hosted(api_url) and not self.model: # manually set default model
self.model = "NV-Embed-QA"
self.model = "nvidia/nv-embedqa-e5-v5"

def default_model(self):
"""Set default model in local NIM mode."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def __init__(
self._initialized = False

if is_hosted(api_url) and not self.model: # manually set default model
self.model = "NV-Embed-QA"
self.model = "nvidia/nv-embedqa-e5-v5"

def default_model(self):
"""Set default model in local NIM mode."""
Expand Down
3 changes: 2 additions & 1 deletion integrations/nvidia/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import pytest
from haystack.utils import Secret
from haystack_integrations.utils.nvidia import Model, NimBackend
from requests_mock import Mocker

from haystack_integrations.utils.nvidia import Model, NimBackend


class MockBackend(NimBackend):
def __init__(self, model: str, api_key: Optional[Secret] = None, model_kwargs: Optional[Dict[str, Any]] = None):
Expand Down
1 change: 1 addition & 0 deletions integrations/nvidia/tests/test_base_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from haystack_integrations.components.embedders.nvidia import NvidiaDocumentEmbedder, NvidiaTextEmbedder
from haystack_integrations.components.generators.nvidia import NvidiaGenerator

Expand Down
28 changes: 24 additions & 4 deletions integrations/nvidia/tests/test_document_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import pytest
from haystack import Document
from haystack.utils import Secret

from haystack_integrations.components.embedders.nvidia import EmbeddingTruncateMode, NvidiaDocumentEmbedder

from . import MockBackend
Expand All @@ -14,7 +15,7 @@ def test_init_default(self, monkeypatch):
embedder = NvidiaDocumentEmbedder()

assert embedder.api_key == Secret.from_env_var("NVIDIA_API_KEY")
assert embedder.model == "NV-Embed-QA"
assert embedder.model == "nvidia/nv-embedqa-e5-v5"
assert embedder.api_url == "https://ai.api.nvidia.com/v1/retrieval/nvidia"
assert embedder.prefix == ""
assert embedder.suffix == ""
Expand Down Expand Up @@ -372,15 +373,34 @@ def test_run_integration_with_nim_backend(self):
assert isinstance(doc.embedding, list)
assert isinstance(doc.embedding[0], float)

@pytest.mark.parametrize(
"model, api_url",
[
("NV-Embed-QA", None),
("snowflake/arctic-embed-l", "https://integrate.api.nvidia.com/v1"),
("nvidia/nv-embed-v1", "https://integrate.api.nvidia.com/v1"),
("nvidia/nv-embedqa-mistral-7b-v2", "https://integrate.api.nvidia.com/v1"),
("nvidia/nv-embedqa-e5-v5", "https://integrate.api.nvidia.com/v1"),
("baai/bge-m3", "https://integrate.api.nvidia.com/v1"),
],
ids=[
"NV-Embed-QA",
"snowflake/arctic-embed-l",
"nvidia/nv-embed-v1",
"nvidia/nv-embedqa-mistral-7b-v2",
"nvidia/nv-embedqa-e5-v5",
"baai/bge-m3",
],
)
@pytest.mark.skipif(
not os.environ.get("NVIDIA_API_KEY", None),
reason="Export an env var called NVIDIA_API_KEY containing the NVIDIA API key to run this test.",
)
@pytest.mark.integration
def test_run_integration_with_api_catalog(self):
def test_run_integration_with_api_catalog(self, model, api_url):
embedder = NvidiaDocumentEmbedder(
model="NV-Embed-QA",
api_url="https://ai.api.nvidia.com/v1/retrieval/nvidia",
model=model,
**({"api_url": api_url} if api_url else {}),
api_key=Secret.from_env_var("NVIDIA_API_KEY"),
)
embedder.warm_up()
Expand Down
3 changes: 2 additions & 1 deletion integrations/nvidia/tests/test_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@

import pytest
from haystack.utils import Secret
from haystack_integrations.components.generators.nvidia import NvidiaGenerator
from requests_mock import Mocker

from haystack_integrations.components.generators.nvidia import NvidiaGenerator


@pytest.fixture
def mock_local_chat_completion(requests_mock: Mocker) -> None:
Expand Down
26 changes: 23 additions & 3 deletions integrations/nvidia/tests/test_text_embedder.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from haystack.utils import Secret

from haystack_integrations.components.embedders.nvidia import EmbeddingTruncateMode, NvidiaTextEmbedder

from . import MockBackend
Expand Down Expand Up @@ -169,15 +170,34 @@ def test_run_integration_with_nim_backend(self):
assert all(isinstance(x, float) for x in embedding)
assert "usage" in meta

@pytest.mark.parametrize(
"model, api_url",
[
("NV-Embed-QA", None),
("snowflake/arctic-embed-l", "https://integrate.api.nvidia.com/v1"),
("nvidia/nv-embed-v1", "https://integrate.api.nvidia.com/v1"),
("nvidia/nv-embedqa-mistral-7b-v2", "https://integrate.api.nvidia.com/v1"),
("nvidia/nv-embedqa-e5-v5", "https://integrate.api.nvidia.com/v1"),
("baai/bge-m3", "https://integrate.api.nvidia.com/v1"),
],
ids=[
"NV-Embed-QA",
"snowflake/arctic-embed-l",
"nvidia/nv-embed-v1",
"nvidia/nv-embedqa-mistral-7b-v2",
"nvidia/nv-embedqa-e5-v5",
"baai/bge-m3",
],
)
@pytest.mark.skipif(
not os.environ.get("NVIDIA_API_KEY", None),
reason="Export an env var called NVIDIA_API_KEY containing the NVIDIA API key to run this test.",
)
@pytest.mark.integration
def test_run_integration_with_api_catalog(self):
def test_run_integration_with_api_catalog(self, model, api_url):
embedder = NvidiaTextEmbedder(
model="NV-Embed-QA",
api_url="https://ai.api.nvidia.com/v1/retrieval/nvidia",
model=model,
**({"api_url": api_url} if api_url else {}),
api_key=Secret.from_env_var("NVIDIA_API_KEY"),
)
embedder.warm_up()
Expand Down

0 comments on commit 8544b56

Please sign in to comment.