Accelerate Couchbase-Powered RAG AI Application With NVIDIA NIM/NeMo and LangChain
Tags: couchbase, rag, nvidia, langchain
Published: 2024-07-11 10:32:29

---
title: Accelerate Couchbase-Powered RAG AI Application With NVIDIA NIM/NeMo and LangChain
published: true
date: 2024-07-04 16:49:03 UTC
tags: Couchbase,RAG,NVIDIA,Langchain
canonical_url: https://www.couchbase.com/blog/accelerate-rag-ai-couchbase-nvidia/
---

Today, we’re excited to announce our new integration with NVIDIA NIM/NeMo. In this blog post, we present a solution concept of an interactive chatbot based on a _Retrieval Augmented Generation_ (RAG) architecture with Couchbase Capella as a Vector database. The retrieval and generation phases of the RAG pipeline are accelerated by NVIDIA NIM/NeMo with just a few lines of code. 

Enterprises across various verticals strive to offer the best customer service to their customers. To achieve this, they are arming their frontline workers such as ER nurses, store sales associates, and help desk representatives, with AI-powered interactive question-and-answer (QA) chatbots to retrieve relevant and up-to-date information quickly.

Chatbots are usually based on [RAG](https://www.couchbase.com/blog/an-overview-of-retrieval-augmented-generation/), an AI framework used for retrieving facts from the enterprise’s knowledge base to ground LLM responses in the most accurate and recent information. It involves three distinct phases, which starts with the retrieval of the most relevant context using [vector search](https://www.couchbase.com/products/vector-search/), augmentation of the user’s query with the context, and, finally, generating relevant responses using an LLM.

The problem with existing RAG pipelines is that calls to the embedding service in the retrieval phase for converting user prompts into vectors can add significant latency, slowing down applications that require interactivity. Vectorizing a document corpus consisting of millions of PDFs, docs, and other knowledge bases can take a long time to vectorize, increasing the likelihood of using stale data for RAG. Further, users find it challenging to accelerate inference (tokens/sec) cost-efficiently to reduce the response time of their chatbot applications.

Figure 1 depicts a performant stack that will enable you to easily develop an interactive customer service chatbot. It consists of the StreamLit application framework, LangChain for orchestration, Couchbase Capella for indexing and searching vectors, and NVIDIA NIM/NeMo for accelerating the retrieval and generation stages.

[![NVIDIA NIM/NeMo and LangChain](https://www.couchbase.com/blog/wp-content/uploads/2024/07/image1-1-1024x518.png)](https://www.couchbase.com/blog/wp-content/uploads/2024/07/image1-1.png)

Figure 1: Conceptual Architecture of a QA Chatbot built using Capella and NVIDIA NIM/NeMo

Couchbase Capella, a high-performance database-as-a-service (DBaaS), allows you to get started quickly with storing, indexing, and querying operational, vector, text, time series, and geospatial data while leveraging the flexibility of JSON. You can easily integrate Capella for [vector search](https://www.couchbase.com/products/vector-search/) or semantic search without the need for a separate vector database by integrating an orchestration framework such as [LangChain](https://www.langchain.com/) or [LlamaIndex](https://www.llamaindex.ai/) into your production RAG pipeline. It offers the [hybrid search](https://www.couchbase.com/blog/hybrid-search/) capability, which blends vector search with traditional search to improve search performance significantly. Further, you can extend vector search to the edge using Couchbase mobile for edge AI use cases.

Once you have configured Capella Vector Search, you can proceed to choose a performant model from the [NVIDIA API Catalog](https://build.nvidia.com/explore/discover), which offers a broad spectrum of foundation models that span open-source, NVIDIA AI foundation, and custom models, optimized to deliver the best performance on NVIDIA accelerated infrastructure. These models are deployed as [NVIDIA NIM](https://developer.nvidia.com/blog/nvidia-nim-offers-optimized-inference-microservices-for-deploying-ai-models-at-scale/?ref=blog.langchain.dev) either on-prem or in the cloud using easy-to-use prebuilt containers via a single command. NeMo Retriever, a part of NVIDIA NeMo, offers information retrieval with the lowest latency, highest throughput, and maximum data privacy. 

The chatbot that we have developed using the aforementioned stack will allow you to upload your PDF documents and ask questions interactively. It uses _NV-QA-Embed_, a GPU-accelerated text embedding model used for question-answer retrieval, and [Llama 3 – 70B](https://build.nvidia.com/meta/llama3-70b), which is packaged as a NIM and accelerated on NVIDIA infrastructure. The [langchain-nvidia-ai-endpoints](https://python.langchain.com/v0.2/docs/integrations/chat/nvidia_ai_endpoints/) package contains LangChain integrations for building applications with models on NVIDIA NIM. Although we have used NVIDIA-hosted endpoints for prototyping purposes, we recommend that you consider using self-hosted NIM by referring to the [NIM documentation](https://docs.nvidia.com/nim/large-language-models/latest/introduction.html?nvid=nv-int-tblg-432774) for production deployments. 

You can use this solution to support use cases that require quick information retrieval such as:

- 
  - Enabling ER nurses to speed up triaging by quick access to relevant healthcare information for alleviating overcrowding, long waits for care, and poor patient satisfaction.
  - Helping customer service agents discover relevant knowledge quickly via an internal knowledge-base chatbot to reduce caller wait times. This will not only help boost CSAT scores but also allow for managing high call volumes.
  - Helping sales associates inside a store to quickly discover and recommend items in a product catalog similar to the picture or description of the item requested by a shopper but is currently out of stock (stockout), to improve the shopping experience.

In conclusion, you can develop an interactive GenAI application, like a chatbot, with grounded and relevant responses using Couchbase Capella-based RAG and accelerate it using NVIDIA NIM/NeMo. This combination provides scalability, reliability, and ease of use. In addition to deploying alongside Capella for a DBaaS experience, NIM/NeMo can be deployed with on-prem or self-managed Couchbase in public clouds within your VPC for use cases that have stricter requirements for security and privacy. Additionally, you can use [NeMo Guardrails](https://developer.nvidia.com/blog/building-safer-llm-apps-with-langchain-templates-and-nvidia-nemo-guardrails/) to control the output of your LLM for content that your company deems objectionable.

The details of the chatbot application can be found in the Couchbase [Developer Portal](https://github.com/couchbase-examples/couchbase-tutorials/blob/141424e68c18233c4ed47cc6321d38540ab4ca54/tutorial/markdown/python/nvidia-nim-llama3-pdf-chat/nvidia-nim-llama3-pdf-chat.md) along with the [complete code](https://github.com/couchbase-examples/nvidia-rag-demo/blob/main/chat_with_pdf.py). Please sign up for a [Capella trial account](https://cloud.couchbase.com/sign-up), free [NVIDIA NIM account](https://build.nvidia.com/explore/discover?signin_corporate=false&signin=false), and start developing your GenAI application. 

The post [Accelerate Couchbase-Powered RAG AI Application With NVIDIA NIM/NeMo and LangChain](https://www.couchbase.com/blog/accelerate-rag-ai-couchbase-nvidia/) appeared first on [The Couchbase Blog](https://www.couchbase.com/blog).