|
1 | | -# NVIDIA NIMs |
| 1 | +# LlamaIndex Embeddings Integration: NVIDIA NIM Microservices |
2 | 2 |
|
3 | | -The `llama-index-embeddings-nvidia` package contains LlamaIndex integrations building applications with models on |
4 | | -NVIDIA NIM inference microservice. NIM supports models across domains like chat, embedding, and re-ranking models |
5 | | -from the community as well as NVIDIA. These models are optimized by NVIDIA to deliver the best performance on NVIDIA |
6 | | -accelerated infrastructure and deployed as a NIM, an easy-to-use, prebuilt containers that deploy anywhere using a single |
7 | | -command on NVIDIA accelerated infrastructure. |
| 3 | +The `llama-index-embeddings-nvidia` package contains LlamaIndex integrations for building applications with [NVIDIA NIM microservices](https://developer.nvidia.com/nim). |
| 4 | +With the NVIDIA embeddings connector, you can connect to, and generate content from, compatible models. |
8 | 5 |
|
9 | | -NVIDIA hosted deployments of NIMs are available to test on the [NVIDIA API catalog](https://build.nvidia.com/). After testing, |
10 | | -NIMs can be exported from NVIDIA’s API catalog using the NVIDIA AI Enterprise license and run on-premises or in the cloud, |
11 | | -giving enterprises ownership and full control of their IP and AI application. |
| 6 | +NVIDIA NIM supports models across domains like chat, embedding, and re-ranking, from the community as well as from NVIDIA. |
| 7 | +Each model is optimized by NVIDIA to deliver the best performance on NVIDIA-accelerated infrastructure and is packaged as a NIM, |
| 8 | +an easy-to-use, prebuilt container that deploys anywhere using a single command on NVIDIA accelerated infrastructure. |
| 9 | +At their core, NIM microservices are containers that provide interactive APIs for running inference on an AI Model. |
12 | 10 |
|
13 | | -NIMs are packaged as container images on a per model basis and are distributed as NGC container images through the NVIDIA NGC Catalog. |
14 | | -At their core, NIMs provide easy, consistent, and familiar APIs for running inference on an AI model. |
| 11 | +NVIDIA-hosted deployments are available on the [NVIDIA API catalog](https://build.nvidia.com/) to test each NIM. |
| 12 | +After you explore, you can download NIM microservices from the API catalog, which is included with the NVIDIA AI Enterprise license. |
| 13 | +The ability to run models on-premises or in your own cloud gives your enterprise ownership of your customizations and full control of your IP and AI application. |
15 | 14 |
|
16 | | -# NVIDIA's Embeddings connector |
| 15 | +Use this documentation to learn how to install the `llama-index-embeddings-nvidia` package and use it to connect to a model. |
| 16 | +The following example connects to the NVIDIA Retrieval QA E5 Embedding Model. |
17 | 17 |
|
18 | | -With this connector, you'll be able to connect to and generate from compatible models available and hosted on [NVIDIA API Catalog](https://build.nvidia.com/), such as: |
| 18 | +<!-- Don't link to the model yet because until the reader signs in at a following step, the link might 404 --> |
19 | 19 |
|
20 | | -- NVIDIA's Retrieval QA Embedding Model [embed-qa-4](https://build.nvidia.com/nvidia/embed-qa-4) |
| 20 | +## Install the Package |
21 | 21 |
|
22 | | -## Installation |
| 22 | +To install the `llama-index-embeddings-nvidia` package, run the following code. |
23 | 23 |
|
24 | 24 | ```bash |
25 | 25 | pip install llama-index-embeddings-nvidia |
26 | 26 | ``` |
27 | 27 |
|
28 | | -## Setup |
| 28 | +## Access the NVIDIA API Catalog |
29 | 29 |
|
30 | | -**To get started:** |
| 30 | +To get access to the NVIDIA API Catalog, do the following: |
31 | 31 |
|
32 | | -1. Create a free account with [NVIDIA](https://build.nvidia.com/), which hosts NVIDIA AI Foundation models. |
| 32 | +1. Create a free account on the [NVIDIA API Catalog](https://build.nvidia.com/) and log in. |
| 33 | +2. Click your profile icon, and then click **API Keys**. The **API Keys** page appears. |
| 34 | +3. Click **Generate API Key**. The **Generate API Key** window appears. |
| 35 | +4. Click **Generate Key**. You should see **API Key Granted**, and your key appears. |
| 36 | +5. Copy and save the key as `NVIDIA_API_KEY`. |
| 37 | +6. To verify your key, use the following code. |
33 | 38 |
|
34 | | -2. Select the `Retrieval` tab, then select your model of choice. |
| 39 | + ```python |
| 40 | + import getpass |
| 41 | + import os |
35 | 42 |
|
36 | | -3. Under `Input` select the `Python` tab, and click `Get API Key`. Then click `Generate Key`. |
| 43 | + if os.environ.get("NVIDIA_API_KEY", "").startswith("nvapi-"): |
| 44 | + print("Valid NVIDIA_API_KEY already in environment. Delete to reset") |
| 45 | + else: |
| 46 | + nvapi_key = getpass.getpass("NVAPI Key (starts with nvapi-): ") |
| 47 | + assert nvapi_key.startswith( |
| 48 | + "nvapi-" |
| 49 | + ), f"{nvapi_key[:5]}... is not a valid key" |
| 50 | + os.environ["NVIDIA_API_KEY"] = nvapi_key |
| 51 | + ``` |
37 | 52 |
|
38 | | -4. Copy and save the generated key as `NVIDIA_API_KEY`. From there, you should have access to the endpoints. |
| 53 | +You can now use your key to access endpoints on the NVIDIA API Catalog. |
39 | 54 |
|
40 | | -```python |
41 | | -import getpass |
42 | | -import os |
43 | | - |
44 | | -if os.environ.get("NVIDIA_API_KEY", "").startswith("nvapi-"): |
45 | | - print("Valid NVIDIA_API_KEY already in environment. Delete to reset") |
46 | | -else: |
47 | | - nvapi_key = getpass.getpass("NVAPI Key (starts with nvapi-): ") |
48 | | - assert nvapi_key.startswith( |
49 | | - "nvapi-" |
50 | | - ), f"{nvapi_key[:5]}... is not a valid key" |
51 | | - os.environ["NVIDIA_API_KEY"] = nvapi_key |
52 | | -``` |
| 55 | +## Work with the API Catalog |
53 | 56 |
|
54 | | -## Working with API Catalog |
| 57 | +To submit a query to the [nv-embedqa-e5-v5](https://build.nvidia.com/nvidia/nv-embedqa-e5-v5/modelcard) model, |
| 58 | +run the following code. |
55 | 59 |
|
56 | 60 | ```python |
57 | 61 | from llama_index.embeddings.nvidia import NVIDIAEmbedding |
58 | 62 |
|
59 | | -embedder = NVIDIAEmbedding() |
| 63 | +embedder = NVIDIAEmbedding(model="nv-embedqa-e5-v5") |
60 | 64 | embedder.get_query_embedding("What's the weather like in Komchatka?") |
61 | 65 | ``` |
62 | 66 |
|
63 | | -## Working with NVIDIA NIMs |
| 67 | +## Self-host with NVIDIA NIM Microservices |
64 | 68 |
|
65 | | -When ready to deploy, you can self-host models with NVIDIA NIM—which is included with the NVIDIA AI Enterprise software license—and run them anywhere, giving you ownership of your customizations and full control of your intellectual property (IP) and AI applications. |
| 69 | +When you are ready to deploy your AI application, you can self-host models with NVIDIA NIM. |
| 70 | +For more information, refer to [NVIDIA AI Enterprise](https://www.nvidia.com/en-us/data-center/products/ai-enterprise/). |
66 | 71 |
|
67 | | -[Learn more about NIMs](https://developer.nvidia.com/blog/nvidia-nim-offers-optimized-inference-microservices-for-deploying-ai-models-at-scale/) |
| 72 | +The following example code connects to a locally-hosted NIM Microservice. |
68 | 73 |
|
69 | 74 | ```python |
70 | 75 | from llama_index.embeddings.nvidia import NVIDIAEmbedding |
71 | 76 |
|
72 | 77 | # connect to an embedding NIM running at localhost:8080 |
73 | 78 | embedder = NVIDIAEmbeddings(base_url="http://localhost:8080/v1") |
74 | 79 | ``` |
| 80 | + |
| 81 | +## Related Topics |
| 82 | + |
| 83 | +- [Overview of NeMo Retriever Text Embedding NIM](https://docs.nvidia.com/nim/nemo-retriever/text-embedding/latest/overview.html) |
0 commit comments