Home

Awesome

Table of Contents

NVIDIA AI Workbench: Introduction Open In AI Workbench

<!-- Banner Image --> <img src="https://developer-blogs.nvidia.com/wp-content/uploads/2024/07/rag-representation.jpg" width="100%"> <!-- Links --> <p align="center"> <a href="https://www.nvidia.com/en-us/deep-learning-ai/solutions/data-science/workbench/" style="color: #76B900;">:arrow_down: Download AI Workbench</a> • <a href="https://docs.nvidia.com/ai-workbench/" style="color: #76B900;">:book: Read the Docs</a> • <a href="https://docs.nvidia.com/ai-workbench/user-guide/latest/quickstart/example-projects.html" style="color: #76B900;">:open_file_folder: Explore Example Projects</a> • <a href="https://forums.developer.nvidia.com/t/support-workbench-example-project-agentic-rag/303414" style="color: #76B900;">:rotating_light: Facing Issues? Let Us Know!</a> </p>

Note: NVIDIA AI Workbench is the easiest way to get this RAG app running.

Project Description

This is an NVIDIA AI Workbench project for developing a Retrieval Augmented Generation application with a customizable Gradio Chat app. It lets you:

Table 1 Default Supported Models by Inference Mode

<details> <summary> <b>Expand this section for a full table on all supported models by inference mode.</b> </summary>
ModelLocal (TGI)Cloud (NVIDIA API Catalog)Microservices (NVIDIA NIMs)
Llama3-ChatQA-1.5-8BYY*
Llama3-ChatQA-1.5-70BY*
Nemotron-Mini-4BY*
Nemotron-4-340B-InstructY*
Mistral-NeMo 12B InstructY*
Mistral-7B-Instruct-v0.1Y (gated)*
Mistral-7B-Instruct-v0.2Y (gated)Y*
Mistral-7B-Instruct-v0.3YY
Mistral-LargeY*
Mixtral-8x7B-Instruct-v0.1YY
Mixtral-8x22B-Instruct-v0.1YY
Mamba Codestral 7B v0.1Y*
Codestral-22B-Instruct-v0.1Y*
Llama-2-7B-ChatY (gated)*
Llama-2-13B-Chat*
Llama-2-70B-ChatY*
Llama-3-8B-InstructY (gated)YY (default) *
Llama-3-70B-InstructYY
Llama-3.1-8B-InstructY*
Llama-3.1-70B-InstructY*
Llama-3.1-405B-InstructY*
Gemma-2BY*
Gemma-7BY*
CodeGemma-7BY*
Phi-3-Mini-4k-InstructY*
Phi-3-Mini-128k-InstructYY*
Phi-3-Small-8k-InstructY*
Phi-3-Small-128k-InstructY*
Phi-3-Medium-4k-InstructY*
Phi-3-Medium-128k-InstructY*
Phi-3.5-Mini-InstructY*
Phi-3.5-MoE-InstructY*
ArcticY*
Granite-8B-Code-InstructY*
Granite-34B-Code-InstructY*
Solar-10.7B-InstructY*
Jamba-1.5-Mini-InstructY*
Jamba-1.5-Large-InstructY*
</details>

*NIM containers for LLMs are starting to roll out under General Availability (GA). If you set up any accessible language model NIM running on another system, it is supported under Remote NIM inference inside this project. For Local NIM inference, this project provides a flow for setting up the default meta/llama3-8b-instruct NIM locally as an example. Advanced users may choose to swap this NIM Container Image out with other NIMs as they are released.

Quickstart

This section demonstrates how to use this project to run RAG via NVIDIA Inference Endpoints hosted on the NVIDIA API Catalog. For other inference options, including local inference, see the Advanced Tutorials section for set up and instructions.

Prerequisites

Tutorial: Using a Cloud Endpoint

<img src="./code/chatui/static/cloud.gif" width="85%" height="auto">
  1. Install and configure AI Workbench locally and open up AI Workbench. Select a location of your choice.
  2. Fork this repo into your own GitHub account.
  3. Inside AI Workbench:
    • Click Clone Project and enter the repo URL of your newly-forked repo.
    • AI Workbench will automatically clone the repo and build out the project environment, which can take several minutes to complete.
    • Upon Build Complete, navigate to Environment > Secrets > NVCF_RUN_KEY > Configure and paste in your NVCF run key as a project secret.
    • Select Open Chat on the top right of the AI Workbench window, and the Gradio app will open in a browser.
  4. In the Gradio Chat app:
    • Click Set up RAG Backend. This triggers a one-time backend build which can take a few moments to initialize.
    • Select the Cloud option, select a model family and model name, and submit a query.
    • To perform RAG, select Upload Documents Here from the right hand panel of the chat UI.
      • You may see a warning that the vector database is not ready yet. If so wait a moment and try again.
    • When the database starts, select Click to Upload and choose the text files to upload.
    • Once the files upload, the Toggle to Use Vector Database next to the text input box will turn on.
    • Now query your documents! What are they telling you?
    • To change the endpoint, choose a different model from the dropdown on the right-hand settings panel and continue querying.

Next Steps:


Troubleshooting

Need help? Submit any questions, bugs, feature requests, and feedback at the Developer Forum for AI Workbench. The dedicated thread for this Hybrid RAG example project is located here.

How do I open AI Workbench?

How do I clone this repo with AI Workbench?

I've cloned the project, but now nothing seems to be happening?

How do I start the Chat application?

Something went wrong, how do I debug the Chat application?

How can I customize this project with AI Workbench?

Advanced Tutorials

This section shows you how to use different inference modes with this RAG project. For these tutorials, a GPU of at least 12 GB of vRAM is recommended. If you don't have one, go back to the Quickstart Tutorial that shows how to use Cloud Endpoints.

Tutorial 1: Using a local GPU

This tutorial assumes you already cloned this Hybrid RAG project to your AI Workbench. If not, please follow the beginning of the Quickstart Tutorial.

<img src="./code/chatui/static/local.gif" width="85%" height="auto">

Additional Configurations

Ungated Models

The following models are ungated. These can be accessed, downloaded, and run locally inside the project with no additional configurations required:

Gated models

Some additional configurations in AI Workbench are required to run certain listed models. Unlike the previous tutorials, these configs are not added to the project by default, so please follow the following instructions closely to ensure a proper setup. Namely, a Hugging Face API token is required for running gated models locally. See how to create a token here.

The following models are gated. Verify that You have been granted access to this model appears on the model cards for any models you are interested in running locally:

Then, complete the following steps:

  1. If the project is already running, shut down the project environment under Environment > Stop Environment. This will ensure restarting the environment will incorporate all the below configurations.
  2. In AI Workbench, add the following entries under Environment > Secrets.
    • <ins>Your Hugging Face Token</ins>: This is used to clone the model weights locally from Hugging Face.
      • Name: HUGGING_FACE_HUB_TOKEN
      • Value: (Your HF API Key)
      • Description: HF Token for cloning model weights locally
  3. Rebuild the project if needed to incorporate changes.

Note: All subsequent tutorials will assume both NVCF_RUN_KEY and HUGGING_FACE_HUB_TOKEN are already configured with your credentials.

Inference

  1. Select the green Open Chat button on the top right the AI Workbench project window.
  2. Once the UI opens, click Set up RAG Backend. This triggers a one-time backend build which can take a few moments to initialize.
  3. Select the Local System inference mode under Inference Settings > Inference Mode.
  4. Select a model from the dropdown on the right hand settings panel. You can filter by gated vs ungated models for convenience.
    • Ensure you have proper access permissions for the model; instructions are here.
    • You can also input a custom model from Hugging Face, following the same format. Careful, as not all models and quantization levels may be supported in the current TGI version!
  5. Select a quantization level. The recommended precision for your system will be pre-selected for you, but full, 8-bit, and 4-bit bitsandbytes precision levels are currently supported.
Table 2 System Resources vs Model Size and Quantization
vRAMSystem RAMDisk StorageModel Size & Quantization
>=12 GB32 GB40 GB7B & int4
>=24 GB64 GB40 GB7B & int8
>=40 GB64 GB40 GB7B & none
  1. Select Load Model to pre-fetch the model. This will take up to several minutes to perform an initial download of the model to the project cache. Subsequent loads will detect this cached model.
  2. Select Start Server to start the inference server with your current local GPU. This may take a moment to warm up.
  3. Now, start chatting! Queries will be made to the model running on your local system whenever this inference mode is selected.

Using RAG

  1. In the right hand panel of the Chat UI select Upload Documents Here. Click to upload or drag and drop the desired text files to upload.
    • You may see a warning that the vector database is not ready yet. If so wait a moment and try again.
  2. Once the files upload, the Toggle to Use Vector Database next to the text input box will turn on by default.
  3. Now query your documents! To use a different model, stop the server, make your selections, and restart the inference server.

Tutorial 2: Using a Remote Microservice

This tutorial assumes you already cloned this Hybrid RAG project to your AI Workbench. If not, please follow the beginning of the Quickstart Tutorial.

<img src="./code/chatui/static/remote-ms.gif" width="85%" height="auto">

Additional Configurations

Inference

  1. Select the green Open Chat button on the top right the AI Workbench project window.
  2. Once the UI opens, click Set up RAG Backend. This triggers a one-time backend build which can take a few moments to initialize.
  3. Select the Self-hosted Microservice inference mode under Inference Settings > Inference Mode.
  4. Select the Remote tab in the right hand settings panel. Input the IP address of the accessible system running the microservice, Port if different from the 8000 default for NIMs, as well as the model name to run if different from the meta/llama3-8b-instruct default.
  5. Now start chatting! Queries will be made to the microservice running on a remote system whenever this inference mode is selected.

Using RAG

  1. In the right hand panel of the Chat UI select Upload Documents Here. Click to upload or drag and drop the desired text files to upload.
    • You may see a warning that the vector database is not ready yet. If so wait a moment and try again.
  2. Once uploaded successfully, the Toggle to Use Vector Database should turn on by default next to your text input box.
  3. Now you may query your documents!

Tutorial 3: Using a Local Microservice

This tutorial assumes you already cloned this Hybrid RAG project to your AI Workbench. If not, please follow the beginning of the Quickstart Tutorial.

<img src="./code/chatui/static/local-ms.gif" width="85%" height="auto">

Here are some important PREREQUISITES:

Additional Configurations

Some additional configurations in AI Workbench are required to run this tutorial. Unlike the previous tutorials, these configs are not added to the project by default, so please follow the following instructions closely to ensure a proper setup.

  1. If running, shut down the project environment under Environment > Stop Environment. This will ensure restarting the environment will incorporate all the below configurations.
  2. In AI Workbench, add the following entries under Environment > Secrets:
    • <ins>Your NGC API Key</ins>: This is used to authenticate when pulling the NIM container from NGC. Remember, you must be in the General Availability Program to access this container.
      • Name: NGC_CLI_API_KEY
      • Value: (Your NGC API Key)
      • Description: NGC API Key for NIM authentication
  3. Add and/or modify the following under Environment > Variables:
    • DOCKER_HOST: location of your docker socket, eg. unix:///var/host-run/docker.sock
    • LOCAL_NIM_HOME: location of where your NIM files will be stored, for example /mnt/c/Users/<my-user> for Windows or /home/<my-user> for Linux
  4. Add the following under Environment > Mounts:
    • <ins>A Docker Socket Mount</ins>: This is a mount for the docker socket for the container to properly interact with the host Docker Engine.
      • Type: Host Mount
      • Target: /var/host-run
      • Source: /var/run
      • Description: Docker socket Host Mount
    • <ins>A Filesystem Mount</ins>: This is a mount to properly run and manage your LOCAL_NIM_HOME on the host from inside the project container for generating the model repo.
      • Type: Host Mount
      • Target: /mnt/host-home
      • Source: (Your LOCAL_NIM_HOME location) , for example /mnt/c/Users/<my-user> for Windows or /home/<my-user> for Linux
      • Description: Host mount for LOCAL_NIM_HOME
  5. Rebuild the project if needed.

Inference

  1. Select the green Open Chat button on the top right the AI Workbench project window.
  2. Once the UI opens, click Set up RAG Backend. This triggers a one-time backend build which can take a few moments to initialize.
  3. Select the Self-hosted Microservice inference mode under Inference Settings > Inference Mode.
  4. Select the Local sub-tab in the right hand settings panel.
  5. Bring your NIM Container Image (placeholder can be used as the default flow), and select Prefetch NIM. This one-time process can take a few moments to pull down the NIM container.
  6. Select Start Microservice. This may take a few moments to complete.
  7. Now, you can start chatting! Queries will be made to your microservice running on the local system whenever this inference mode is selected.

Using RAG

  1. In the right hand panel of the Chat UI select Upload Documents Here. Click to upload or drag and drop the desired text files to upload.
    • You may see a warning that the vector database is not ready yet. If so wait a moment and try again.
  2. Once uploaded successfully, the Toggle to Use Vector Database should turn on by default next to your text input box.
  3. Now you may query your documents!

Tutorial 4: Customizing the Gradio App

By default, you may customize Gradio app using the jupyterlab container application. Alternatively, you may configure VSCode support here.

  1. In AI Workbench, select the green dropdown from the top right and select Open JupyterLab.
  2. Go into the code/chatui/ folder and start editing the files.
  3. Save the files.
  4. To see your changes, stop the Chat UI and restart it.
  5. To version your changes, commit them in the Workbench project window and push to your GitHub repo.

In addition to modifying the Gradio frontend, you can also use the Jupyterlab or another IDE to customize other aspects of the project, eg. custom chains, backend server, scripts, configs, etc.

License

This NVIDIA AI Workbench example project is under the Apache 2.0 License

This project may download and install additional third-party open source software projects. Review the license terms of these open source projects before use. Third party components used as part of this project are subject to their separate legal notices or terms that accompany the components. You are responsible for confirming compliance with third-party component license terms and requirements.