VOOZH about

URL: https://thenewstack.io/build-a-rag-app-with-nvidia-nim-and-milvus-running-locally/

⇱ Build a RAG App With Nvidia NIM and Milvus Running Locally - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2024-08-26 07:21:23
Build a RAG App With Nvidia NIM and Milvus Running Locally
tutorial,
AI / Databases / Large Language Models

Build a RAG App With Nvidia NIM and Milvus Running Locally

How to build a RAG-based LLM application with Nvidia NIM and Milvus running locally on a GPU-boosted machine.
Aug 26th, 2024 7:21am by Janakiram MSV
👁 Featued image for: Build a RAG App With Nvidia NIM and Milvus Running Locally
Image via Unsplash+. 

In the previous post, we built an application that consumes Nvidia NIM APIs and a hosted Zilliz vector database. In this tutorial, we will switch to self-hosted local deployments of the same components while maintaining the same codebase.

Nvidia NIM is available as both APIs hosted within Nvidia’s infrastructure and as containers that can be deployed in an on-premises environment. Similarly, we can deploy Milvus as a stand-alone vector database running in containers. Since Milvus is one of the first open source vector databases to take advantage of GPU acceleration, we can leverage the available GPUs to run the entire stack on an accelerated computing infrastructure.

Let’s start by exploring the environment where we deploy this stack. For my generative AI testbed, I installed two Nvidia GeForce RTX 4090 GPUs. Having two GPUs helps us dedicate one for the LLM while scheduling the embeddings model and the vector database on the other.

👁 Image

I also installed Docker and the Nvidia Container Toolkit to enable the containers to access the underlying GPUs. The Nvidia container runtime is configured as the default runtime environment for Docker.

👁 Image

Let us begin deploying the building blocks — the LLM, embeddings model and vector database — on the GPU machine.

Step 1: Deploy the Llama3 8B Parameter LLM

Let’s start by setting the environment variables.

export CONTAINER_NAME=llama-3-8b-instruct
export IMG_NAME="nvcr.io/nim/meta/llama3-8b-instruct:1.0.3"
export NGC_API_KEY=”YOUR_API_Key”

You can use the same key generated in the last tutorial or by logging into NGC.

Run the command below to deploy meta/llama3-8b-instruct as a container.

docker run \
 -d \
 --rm \
 --name=$CONTAINER_NAME \
 --gpus device=0 \
 --shm-size=16GB \
 -e NGC_API_KEY=$NGC_API_KEY \
 -v "$LOCAL_NIM_CACHE:/opt/nim/.cache" \
 -u $(id -u) \
 -p 8000:8000 \
 $IMG_NAME

The model will be downloaded to the /opt/nim/.cache directory. This will help in caching the model weights rather than downloading them each time the container is started. Notice that we are setting the --gpus device parameter to 0, which will dedicate the first GPU to the LLM.

Wait for the model weights to be downloaded. In a few minutes, the container will be ready for inference. You can check the status by running the docker logs -f $CONTAINER_NAME command.

If we run the nvidia-smi command again, we will see that the first GPU (device 0) is 100% utilized.

👁 Image

Let’s perform a test to check if the model is ready for inference.

👁 Image

The above output confirms that the LLM is ready to serve.

Step 2: Deploy the Text Embeddings Model

In this step, we will deploy the same model that we used in the last tutorial: nvidia/nv-embedqa-e5-v5.

Similar to the steps mentioned above, we will run the model within the container.

export CONTAINER_NAME=nv-embedqa-e5-v5
export IMG_NAME="nvcr.io/nim/nvidia/nv-embedqa-e5-v5:1.0.0"
export NGC_API_KEY=”YOUR_API_Key”

Let’s deploy the container.

docker run -it --rm --name=$CONTAINER_NAME \
 -d \
 --rm \
 --runtime=nvidia \
 --gpus device=1 \
 --shm-size=16GB \
 -e NGC_API_KEY=$NGC_API_KEY \
 -v "$LOCAL_NIM_CACHE:/opt/nim/.cache" \
 -u $(id -u) \
 -p 8001:8000 \
 $IMG_NAME

We are using the second GPU for the embeddings model by setting the --gpus device parameter to 1. Wait for the container to get initialized.

Running nvidia-smi confirms that the embeddings model is loaded on the second GPU.

👁 Image

Since the model is not as heavy as the LLM, it only takes 1.4 GiB of the GPU VRAM.

Let’s test by generating the embeddings for a phrase through curl. The output in the screenshot is truncated for brevity.

👁 Image

We now have both the LLM and the embeddings model running locally. In the next step, we will deploy Milvus, the vector database.

Step 3: Deploy the GPU-Accelerated Vector Database

Milvus is an open source vector database that was created and primarily developed by Zilliz. Zilliz is the company behind Milvus, with its founders and engineers being the main contributors to the Milvus project.

Follow the below steps to deploy Milvus.

mkdir milvus && cd milvus
wget https://raw.githubusercontent.com/milvus-io/milvus/master/deployments/docker/standalone/docker-compose.yml

This downloads the Docker Compose file, which has the definitions and dependencies for running Milvus as a stand-alone vector database on GPU.

….
environment:
 CUDA_VISIBLE_DEVICES: 1
 ETCD_ENDPOINTS: etcd:2379
 MINIO_ADDRESS: minio:9000
 volumes:
 - ${DOCKER_VOLUME_DIRECTORY:-.}/volumes/milvus:/var/lib/milvus
 ports:
 - "19530:19530"
 - "9091:9091"
 deploy:
 resources:
 reservations:
 devices:
 - driver: nvidia
 capabilities: ["gpu"]
 device_ids: ["1"]
….

I changed the CUDA_VISIBLE_DEVICES and device_ids to 1. This will collocate the container on the second GPU, which has room even after running the embeddings model.

Launch Milvus by running docker compose up -d command.

At this point, we have the below API endpoints running each of the required building blocks.

LLM – http://0.0.0.0:8000
Embeddings Model – http://0.0.0.0:8000
Vector Database – http://0.0.0.0:19530

Step 4: Run the RAG Notebook With Updated API Endpoints

We will use exactly the same Jupyter Notebook that we used in the last tutorial. The only change we need to make is to the .env file. Update it to reflect the new endpoints.

IP=”Your_GPU_MACHINE_IP”
LLM_URI="http://$IP:8000/v1"
EMBED_URI="http://$IP:8001/v1"
VECTORDB_URI="http://$IP:19530"

👁 Image

The complete code is shown below. You can also download the Notebook from GitHub.

TRENDING STORIES
Janakiram MSV (Jani) is a practicing architect, research analyst, and advisor to Silicon Valley startups. He focuses on the convergence of modern infrastructure powered by cloud-native technology and machine intelligence driven by generative AI. Before becoming an entrepreneur, he spent...
Read more from Janakiram MSV
SHARE THIS STORY
TRENDING STORIES
TNS owner Insight Partners is an investor in: Docker.
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.