Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove deprecated Nvidia Cloud Functions backend and related code #803

Merged
merged 1 commit into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from tqdm import tqdm

from ._nim_backend import NimBackend
from ._nvcf_backend import NvcfBackend
from .backend import EmbedderBackend
from .truncate import EmbeddingTruncateMode

Expand All @@ -14,16 +13,15 @@
class NvidiaDocumentEmbedder:
"""
A component for embedding documents using embedding models provided by
[NVIDIA AI Foundation Endpoints](https://www.nvidia.com/en-us/ai-data-science/foundation-models/)
and NVIDIA Inference Microservices.
[NVIDIA NIMs](https://ai.nvidia.com).

Usage example:
```python
from haystack_integrations.components.embedders.nvidia import NvidiaDocumentEmbedder

doc = Document(content="I love pizza!")

text_embedder = NvidiaDocumentEmbedder(model="nvolveqa_40k")
text_embedder = NvidiaDocumentEmbedder(model="NV-Embed-QA", api_url="https://ai.api.nvidia.com/v1/retrieval/nvidia")
text_embedder.warm_up()

result = document_embedder.run([doc])
Expand All @@ -33,9 +31,9 @@ class NvidiaDocumentEmbedder:

def __init__(
self,
model: str,
model: str = "NV-Embed-QA",
api_key: Optional[Secret] = Secret.from_env_var("NVIDIA_API_KEY"),
api_url: Optional[str] = None,
api_url: str = "https://ai.api.nvidia.com/v1/retrieval/nvidia",
prefix: str = "",
suffix: str = "",
batch_size: int = 32,
Expand All @@ -50,9 +48,9 @@ def __init__(
:param model:
Embedding model to use.
:param api_key:
API key for the NVIDIA AI Foundation Endpoints.
API key for the NVIDIA NIM.
:param api_url:
Custom API URL for the NVIDIA Inference Microservices.
Custom API URL for the NVIDIA NIM.
:param prefix:
A string to add to the beginning of each text.
:param suffix:
Expand Down Expand Up @@ -95,22 +93,15 @@ def warm_up(self):
if self._initialized:
return

if self.api_url is None:
if self.api_key is None:
msg = "API key is required for NVIDIA AI Foundation Endpoints."
raise ValueError(msg)

self.backend = NvcfBackend(self.model, api_key=self.api_key, model_kwargs={"model": "passage"})
else:
model_kwargs = {"input_type": "passage"}
if self.truncate is not None:
model_kwargs["truncate"] = str(self.truncate)
self.backend = NimBackend(
self.model,
api_url=self.api_url,
api_key=self.api_key,
model_kwargs=model_kwargs,
)
model_kwargs = {"input_type": "passage"}
if self.truncate is not None:
model_kwargs["truncate"] = str(self.truncate)
self.backend = NimBackend(
self.model,
api_url=self.api_url,
api_key=self.api_key,
model_kwargs=model_kwargs,
)

self._initialized = True

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from haystack.utils import Secret, deserialize_secrets_inplace

from ._nim_backend import NimBackend
from ._nvcf_backend import NvcfBackend
from .backend import EmbedderBackend
from .truncate import EmbeddingTruncateMode

Expand All @@ -13,8 +12,7 @@
class NvidiaTextEmbedder:
"""
A component for embedding strings using embedding models provided by
[NVIDIA AI Foundation Endpoints](https://www.nvidia.com/en-us/ai-data-science/foundation-models/)
and NVIDIA Inference Microservices.
[NVIDIA NIMs](https://ai.nvidia.com).

For models that differentiate between query and document inputs,
this component embeds the input string as a query.
Expand All @@ -25,7 +23,7 @@ class NvidiaTextEmbedder:

text_to_embed = "I love pizza!"

text_embedder = NvidiaTextEmbedder(model="nvolveqa_40k")
text_embedder = NvidiaTextEmbedder(model="NV-Embed-QA", api_url="https://ai.api.nvidia.com/v1/retrieval/nvidia")
text_embedder.warm_up()

print(text_embedder.run(text_to_embed))
Expand All @@ -34,9 +32,9 @@ class NvidiaTextEmbedder:

def __init__(
self,
model: str,
model: str = "NV-Embed-QA",
api_key: Optional[Secret] = Secret.from_env_var("NVIDIA_API_KEY"),
api_url: Optional[str] = None,
api_url: str = "https://ai.api.nvidia.com/v1/retrieval/nvidia",
prefix: str = "",
suffix: str = "",
truncate: Optional[Union[EmbeddingTruncateMode, str]] = None,
Expand All @@ -47,9 +45,9 @@ def __init__(
:param model:
Embedding model to use.
:param api_key:
API key for the NVIDIA AI Foundation Endpoints.
API key for the NVIDIA NIM.
:param api_url:
Custom API URL for the NVIDIA Inference Microservices.
Custom API URL for the NVIDIA NIM.
:param prefix:
A string to add to the beginning of each text.
:param suffix:
Expand Down Expand Up @@ -79,22 +77,15 @@ def warm_up(self):
if self._initialized:
return

if self.api_url is None:
if self.api_key is None:
msg = "API key is required for NVIDIA AI Foundation Endpoints."
raise ValueError(msg)

self.backend = NvcfBackend(self.model, api_key=self.api_key, model_kwargs={"model": "query"})
else:
model_kwargs = {"input_type": "query"}
if self.truncate is not None:
model_kwargs["truncate"] = str(self.truncate)
self.backend = NimBackend(
self.model,
api_url=self.api_url,
api_key=self.api_key,
model_kwargs=model_kwargs,
)
model_kwargs = {"input_type": "query"}
if self.truncate is not None:
model_kwargs["truncate"] = str(self.truncate)
self.backend = NimBackend(
self.model,
api_url=self.api_url,
api_key=self.api_key,
model_kwargs=model_kwargs,
)

self._initialized = True

Expand Down

This file was deleted.

Loading