Skip to content

Commit 33c51e3

Browse files
authored
Merge branch 'main' into main
2 parents d7f3645 + 0bd0cc9 commit 33c51e3

File tree

4 files changed

+183
-130
lines changed

4 files changed

+183
-130
lines changed

docs-website/docs/pipeline-components/embedders/nvidiadocumentembedder.mdx

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,115 +13,137 @@ This component computes the embeddings of a list of documents and stores the obt
1313

1414
| | |
1515
| --- | --- |
16-
| **Most common position in a pipeline** | Before a [`DocumentWriter`](../writers/documentwriter.mdx) in an indexing pipeline |
16+
| **Most common position in a pipeline** | Before a [`DocumentWriter`](../writers/documentwriter.mdx) in an indexing pipeline |
1717
| **Mandatory init variables** | `api_key`: API key for the NVIDIA NIM. Can be set with `NVIDIA_API_KEY` env var. |
1818
| **Mandatory run variables** | `documents`: A list of documents |
1919
| **Output variables** | `documents`: A list of documents (enriched with embeddings) <br /> <br />`meta`: A dictionary of metadata |
20-
| **API reference** | [Nvidia](/reference/integrations-nvidia) |
20+
| **API reference** | [NVIDIA](/reference/integrations-nvidia) |
2121
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/nvidia |
2222

2323
</div>
2424

2525
## Overview
2626

27-
`NvidiaDocumentEmbedder` enriches the metadata of documents with an embedding of their content.
27+
`NvidiaDocumentEmbedder` enriches documents with an embedding of their content.
2828

29-
It can be used with self-hosted models with NVIDIA NIM or models hosted on the [NVIDIA API catalog](https://build.nvidia.com/explore/discover).
29+
You can use this component with self-hosted models using NVIDIA NIM or models hosted on the [NVIDIA API Catalog](https://build.nvidia.com/explore/discover).
3030

31-
To embed a string, use the [`NvidiaTextEmbedder`](nvidiatextembedder.mdx).
31+
To embed a string, use [`NvidiaTextEmbedder`](nvidiatextembedder.mdx).
3232

3333
## Usage
3434

35-
To start using `NvidiaDocumentEmbedder`, first, install the `nvidia-haystack` package:
35+
To start using `NvidiaDocumentEmbedder`, install the `nvidia-haystack` package:
3636

3737
```shell
3838
pip install nvidia-haystack
3939
```
4040

41-
You can use the `NvidiaDocumentEmbedder` with all the embedder models available on the [NVIDIA API catalog](https://docs.api.nvidia.com/nim/reference) or using a model deployed with NVIDIA NIM. Follow the [Deploying Text Embedding Models](https://developer.nvidia.com/docs/nemo-microservices/embedding/source/deploy.html) guide to learn how to deploy the model you want on your infrastructure.
41+
You can use `NvidiaDocumentEmbedder` with all the embedding models available on the [NVIDIA API Catalog](https://docs.api.nvidia.com/nim/reference) or with a model deployed using NVIDIA NIM. For more information, refer to [Deploying Text Embedding Models](https://developer.nvidia.com/docs/nemo-microservices/embedding/source/deploy.html).
4242

4343
### On its own
4444

45-
To use LLMs from the NVIDIA API catalog, you need to specify the correct `api_url` and your API key. You can get your API key directly from the [catalog website](https://build.nvidia.com/explore/discover).
45+
To use models from the NVIDIA API Catalog, you need to specify the `api_url` and your API key. You can get your API key from the [NVIDIA API Catalog](https://build.nvidia.com/explore/discover).
4646

47-
The `NvidiaDocumentEmbedder` needs an Nvidia API key to work. It uses the `NVIDIA_API_KEY` environment variable by default. Otherwise, you can pass an API key at initialization with `api_key`, as in the following example.
47+
`NvidiaDocumentEmbedder` uses the `NVIDIA_API_KEY` environment variable by default. Otherwise, you can pass an API key at initialization with the `api_key` parameter:
4848

4949
```python
50+
from haystack import Document
5051
from haystack.utils.auth import Secret
5152
from haystack_integrations.components.embedders.nvidia import NvidiaDocumentEmbedder
5253

54+
documents = [
55+
Document(content="A transformer is a deep learning architecture"),
56+
Document(content="Large language models use transformer architectures"),
57+
]
58+
5359
embedder = NvidiaDocumentEmbedder(
5460
model="nvidia/nv-embedqa-e5-v5",
5561
api_url="https://integrate.api.nvidia.com/v1",
5662
api_key=Secret.from_token("<your-api-key>"),
5763
)
5864
embedder.warm_up()
5965

60-
result = embedder.run("A transformer is a deep learning architecture")
61-
print(result["embedding"])
66+
result = embedder.run(documents=documents)
67+
print(result["documents"])
6268
print(result["meta"])
6369
```
6470

65-
To use a locally deployed model, you need to set the `api_url` to your localhost and unset your `api_key`.
71+
To use a locally deployed model, set the `api_url` to your localhost and set `api_key` to `None`:
6672

6773
```python
74+
from haystack import Document
6875
from haystack_integrations.components.embedders.nvidia import NvidiaDocumentEmbedder
6976

77+
documents = [
78+
Document(content="A transformer is a deep learning architecture"),
79+
Document(content="Large language models use transformer architectures"),
80+
]
81+
7082
embedder = NvidiaDocumentEmbedder(
7183
model="nvidia/nv-embedqa-e5-v5",
72-
api_url="http://0.0.0.0:9999/v1",
84+
api_url="http://localhost:9999/v1",
7385
api_key=None,
7486
)
7587
embedder.warm_up()
7688

77-
result = embedder.run("A transformer is a deep learning architecture")
78-
print(result["embedding"])
89+
result = embedder.run(documents=documents)
90+
print(result["documents"])
7991
print(result["meta"])
8092
```
8193

8294
### In a pipeline
8395

84-
Here's an example of a RAG pipeline:
96+
The following example shows how to use `NvidiaDocumentEmbedder` in a RAG pipeline:
8597

8698
```python
8799
from haystack import Pipeline, Document
88100
from haystack.document_stores.in_memory import InMemoryDocumentStore
89-
from haystack_integrations.components.embedders.nvidia import NvidiaTextEmbedder, NvidiaDocumentEmbedder
101+
from haystack.components.writers import DocumentWriter
90102
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
103+
from haystack.utils.auth import Secret
104+
from haystack_integrations.components.embedders.nvidia import NvidiaTextEmbedder, NvidiaDocumentEmbedder
91105

92106
document_store = InMemoryDocumentStore(embedding_similarity_function="cosine")
93107

94-
documents = [Document(content="My name is Wolfgang and I live in Berlin"),
95-
Document(content="I saw a black horse running"),
96-
Document(content="Germany has many big cities")]
108+
documents = [
109+
Document(content="My name is Wolfgang and I live in Berlin"),
110+
Document(content="I saw a black horse running"),
111+
Document(content="Germany has many big cities"),
112+
]
97113

98114
indexing_pipeline = Pipeline()
99-
indexing_pipeline.add_component("embedder", NvidiaDocumentEmbedder(
100-
model="nvidia/nv-embedqa-e5-v5",
101-
api_url="https://integrate.api.nvidia.com/v1",
102-
api_key=Secret.from_token("<your-api-key>"),
103-
))
115+
indexing_pipeline.add_component(
116+
"embedder",
117+
NvidiaDocumentEmbedder(
118+
model="nvidia/nv-embedqa-e5-v5",
119+
api_url="https://integrate.api.nvidia.com/v1",
120+
api_key=Secret.from_token("<your-api-key>"),
121+
),
122+
)
104123
indexing_pipeline.add_component("writer", DocumentWriter(document_store=document_store))
105124
indexing_pipeline.connect("embedder", "writer")
106125

107126
indexing_pipeline.run({"embedder": {"documents": documents}})
108127

109128
query_pipeline = Pipeline()
110-
query_pipeline.add_component("text_embedder", NvidiaTextEmbedder(
111-
model="nvidia/nv-embedqa-e5-v5",
112-
api_url="https://integrate.api.nvidia.com/v1",
113-
api_key=Secret.from_token("<your-api-key>"),
114-
))
129+
query_pipeline.add_component(
130+
"text_embedder",
131+
NvidiaTextEmbedder(
132+
model="nvidia/nv-embedqa-e5-v5",
133+
api_url="https://integrate.api.nvidia.com/v1",
134+
api_key=Secret.from_token("<your-api-key>"),
135+
),
136+
)
115137
query_pipeline.add_component("retriever", InMemoryEmbeddingRetriever(document_store=document_store))
116138
query_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
117139

118140
query = "Who lives in Berlin?"
119141

120-
result = query_pipeline.run({"text_embedder":{"text": query}})
142+
result = query_pipeline.run({"text_embedder": {"text": query}})
121143

122-
print(result['retriever']['documents'][0])
144+
print(result["retriever"]["documents"][0])
123145
```
124146

125-
## Additional References
147+
## Related
126148

127-
🧑‍🍳 Cookbook: [Haystack RAG Pipeline with Self-Deployed AI models using NVIDIA NIMs](https://haystack.deepset.ai/cookbook/rag-with-nims)
149+
- Cookbook: [Haystack RAG Pipeline with Self-Deployed AI models using NVIDIA NIMs](https://haystack.deepset.ai/cookbook/rag-with-nims)

docs-website/docs/pipeline-components/embedders/nvidiatextembedder.mdx

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,22 @@
22
title: "NvidiaTextEmbedder"
33
id: nvidiatextembedder
44
slug: "/nvidiatextembedder"
5-
description: "This component transforms a string into a vector that captures its semantics using Nvidia-hosted models."
5+
description: "This component transforms a string into a vector that captures its semantics using NVIDIA-hosted models."
66
---
77

88
# NvidiaTextEmbedder
99

10-
This component transforms a string into a vector that captures its semantics using Nvidia-hosted models.
10+
This component transforms a string into a vector that captures its semantics using NVIDIA-hosted models.
1111

1212
<div className="key-value-table">
1313

1414
| | |
1515
| --- | --- |
16-
| **Most common position in a pipeline** | Before an embedding [Retriever](../retrievers.mdx) in a query/RAG pipeline |
16+
| **Most common position in a pipeline** | Before an embedding [Retriever](../retrievers.mdx) in a query/RAG pipeline |
1717
| **Mandatory init variables** | `api_key`: API key for the NVIDIA NIM. Can be set with `NVIDIA_API_KEY` env var. |
1818
| **Mandatory run variables** | `text`: A string |
1919
| **Output variables** | `embedding`: A list of float numbers (vectors) <br /> <br />`meta`: A dictionary of metadata strings |
20-
| **API reference** | [Nvidia](/reference/integrations-nvidia) |
20+
| **API reference** | [NVIDIA](/reference/integrations-nvidia) |
2121
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/nvidia |
2222

2323
</div>
@@ -26,25 +26,25 @@ This component transforms a string into a vector that captures its semantics usi
2626

2727
`NvidiaTextEmbedder` embeds a simple string (such as a query) into a vector.
2828

29-
It can be used with self-hosted models with NVIDIA NIM or models hosted on the [NVIDIA API catalog](https://build.nvidia.com/explore/discover).
29+
You can use this component with self-hosted models using NVIDIA NIM or models hosted on the [NVIDIA API Catalog](https://build.nvidia.com/explore/discover).
3030

31-
To embed a list of documents, use the [`NvidiaDocumentEmbedder`](nvidiadocumentembedder.mdx), which enriches the document with the computed embedding, also known as vector.
31+
To embed a list of documents, use [`NvidiaDocumentEmbedder`](nvidiadocumentembedder.mdx), which enriches each document with the computed embedding.
3232

3333
## Usage
3434

35-
To start using `NvidiaTextEmbedder`, first, install the `nvidia-haystack` package:
35+
To start using `NvidiaTextEmbedder`, install the `nvidia-haystack` package:
3636

3737
```shell
3838
pip install nvidia-haystack
3939
```
4040

41-
You can use the `NvidiaTextEmbedder` with all the embedder models available on the [NVIDIA API catalog](https://docs.api.nvidia.com/nim/reference) or using a model deployed with NVIDIA NIM. Follow the [Deploying Text Embedding Models](https://developer.nvidia.com/docs/nemo-microservices/embedding/source/deploy.html) guide to learn how to deploy the model you want on your infrastructure.
41+
You can use `NvidiaTextEmbedder` with all the embedding models available on the [NVIDIA API Catalog](https://docs.api.nvidia.com/nim/reference) or with a model deployed using NVIDIA NIM. For more information, refer to [Deploying Text Embedding Models](https://developer.nvidia.com/docs/nemo-microservices/embedding/source/deploy.html).
4242

4343
### On its own
4444

45-
To use LLMs from the NVIDIA API catalog, you need to specify the correct `api_url` and your API key. You can get your API key directly from the [catalog website](https://build.nvidia.com/explore/discover).
45+
To use models from the NVIDIA API Catalog, you need to specify the `api_url` and your API key. You can get your API key from the [NVIDIA API Catalog](https://build.nvidia.com/explore/discover).
4646

47-
The `NvidiaTextEmbedder` needs an Nvidia API key to work. It uses the `NVIDIA_API_KEY` environment variable by default. Otherwise, you can pass an API key at initialization with `api_key`, as in the following example.
47+
`NvidiaTextEmbedder` uses the `NVIDIA_API_KEY` environment variable by default. Otherwise, you can pass an API key at initialization with the `api_key` parameter:
4848

4949
```python
5050
from haystack.utils.auth import Secret
@@ -62,14 +62,14 @@ print(result["embedding"])
6262
print(result["meta"])
6363
```
6464

65-
To use a locally deployed model, you need to set the `api_url` to your localhost and unset your `api_key`.
65+
To use a locally deployed model, set the `api_url` to your localhost and set `api_key` to `None`:
6666

6767
```python
6868
from haystack_integrations.components.embedders.nvidia import NvidiaTextEmbedder
6969

7070
embedder = NvidiaTextEmbedder(
7171
model="nvidia/nv-embedqa-e5-v5",
72-
api_url="http://0.0.0.0:9999/v1",
72+
api_url="http://localhost:9999/v1",
7373
api_key=None,
7474
)
7575
embedder.warm_up()
@@ -81,47 +81,57 @@ print(result["meta"])
8181

8282
### In a pipeline
8383

84-
Here's an example of a RAG pipeline:
84+
The following example shows how to use `NvidiaTextEmbedder` in a RAG pipeline:
8585

8686
```python
8787
from haystack import Pipeline, Document
8888
from haystack.document_stores.in_memory import InMemoryDocumentStore
89-
from haystack_integrations.components.embedders.nvidia import NvidiaTextEmbedder, NvidiaDocumentEmbedder
89+
from haystack.components.writers import DocumentWriter
9090
from haystack.components.retrievers.in_memory import InMemoryEmbeddingRetriever
91+
from haystack.utils.auth import Secret
92+
from haystack_integrations.components.embedders.nvidia import NvidiaTextEmbedder, NvidiaDocumentEmbedder
9193

9294
document_store = InMemoryDocumentStore(embedding_similarity_function="cosine")
9395

94-
documents = [Document(content="My name is Wolfgang and I live in Berlin"),
95-
Document(content="I saw a black horse running"),
96-
Document(content="Germany has many big cities")]
96+
documents = [
97+
Document(content="My name is Wolfgang and I live in Berlin"),
98+
Document(content="I saw a black horse running"),
99+
Document(content="Germany has many big cities"),
100+
]
97101

98102
indexing_pipeline = Pipeline()
99-
indexing_pipeline.add_component("embedder", NvidiaDocumentEmbedder(
100-
model="nvidia/nv-embedqa-e5-v5",
101-
api_url="https://integrate.api.nvidia.com/v1",
102-
api_key=Secret.from_token("<your-api-key>"),
103-
))
103+
indexing_pipeline.add_component(
104+
"embedder",
105+
NvidiaDocumentEmbedder(
106+
model="nvidia/nv-embedqa-e5-v5",
107+
api_url="https://integrate.api.nvidia.com/v1",
108+
api_key=Secret.from_token("<your-api-key>"),
109+
),
110+
)
104111
indexing_pipeline.add_component("writer", DocumentWriter(document_store=document_store))
105112
indexing_pipeline.connect("embedder", "writer")
106113

107114
indexing_pipeline.run({"embedder": {"documents": documents}})
108115

109116
query_pipeline = Pipeline()
110-
query_pipeline.add_component("text_embedder", NvidiaTextEmbedder(
111-
model="nvidia/nv-embedqa-e5-v5",
112-
api_url="https://integrate.api.nvidia.com/v1",
113-
api_key=Secret.from_token("<your-api-key>"),
114-
))
117+
query_pipeline.add_component(
118+
"text_embedder",
119+
NvidiaTextEmbedder(
120+
model="nvidia/nv-embedqa-e5-v5",
121+
api_url="https://integrate.api.nvidia.com/v1",
122+
api_key=Secret.from_token("<your-api-key>"),
123+
),
124+
)
115125
query_pipeline.add_component("retriever", InMemoryEmbeddingRetriever(document_store=document_store))
116126
query_pipeline.connect("text_embedder.embedding", "retriever.query_embedding")
117127

118128
query = "Who lives in Berlin?"
119129

120-
result = query_pipeline.run({"text_embedder":{"text": query}})
130+
result = query_pipeline.run({"text_embedder": {"text": query}})
121131

122-
print(result['retriever']['documents'][0])
132+
print(result["retriever"]["documents"][0])
123133
```
124134

125-
## Additional References
135+
## Related
126136

127-
🧑‍🍳 Cookbook: [Haystack RAG Pipeline with Self-Deployed AI models using NVIDIA NIMs](https://haystack.deepset.ai/cookbook/rag-with-nims)
137+
- Cookbook: [Haystack RAG Pipeline with Self-Deployed AI models using NVIDIA NIMs](https://haystack.deepset.ai/cookbook/rag-with-nims)

0 commit comments

Comments
 (0)