생성 AI(GenAI)

CodeLab: Building a RAG Application With Couchbase Capella Model Services and LangChain

In this tutorial, you will learn how to build a 검색 증강 생성(RAG) 애플리케이션을 사용하여 Couchbase AI Services to store data, generate embedding using embedding models, and LLM inference. We will create a RAG system that:

  1. Ingests news articles from the BBC News dataset.
  2. Generates vector embeddings using the NVIDIA NeMo Retriever model via Capella Model Services.
  3. Stores and indexes these vectors in 카우치베이스 카펠라.
  4. Performs semantic search to retrieve relevant context.
  5. Generates answers using the Mistral-7B LLM hosted on Capella.

You can find the notebook source code for this CodeLab 여기.

Why Couchbase AI Services?

Couchbase AI Services provide:

  • LLM inference and embeddings API: Access popular LLMs (i.e., Llama 3) and embedding models directly through Capella, without managing external API keys or infrastructure.
  • Unified platform: Leverage the database, vectorization, search, and model in one place.
  • Integrated vector search: Perform semantic search directly on your JSON data with millisecond latency.

Setting Up Couchbase AI Services

Create a Cluster in Capella

  1. 로그인 카우치베이스 카펠라.
  2. Create a new cluster or use an existing one. Note that the cluster needs to run the latest version of Couchbase Server 8.0 that includes the Data, Query, Index, and Eventing services.
  3. Create a bucket.
  4. Create a scope and collection for the data.

AI 서비스 사용

  1. Navigate to Capella’s AI Services section on the UI.
  2. Deploy the embeddings and LLM models.
    • You need to launch an embedding and an LLM for this demo in the same region as the Capella cluster where the data will be stored.
    • For this demo to work well, you need to deploy an LLM that has tool calling capabilities such as 미스트랄라이/미스트랄-7b-인스트럭트-v0.3. 임베딩의 경우 다음과 같은 모델을 선택할 수 있습니다. 엔비디아/라마-3.2-NV-EMBEDQA-1B-V2.
  3. Write down the endpoint URL and generate API keys.

For more details on launching AI models, you can read the 공식 문서.

전제 조건

Before we begin, ensure you have Python 3.10+ installed.

Step 1: Install Dependencies

We need the Couchbase SDK, LangChain integrations, and the datasets library.

Step 2: Configuration & Connection

We’ll start by connecting to our Couchbase cluster. We also need to configure the endpoints for Capella Model Services.

참고: Capella Model Services are compatible with the OpenAI API format, so we can use the standard langchain-openai library by pointing it to our Capella endpoint.

Step 3: Set Up the Database Structure

We need to ensure our bucket, scope, and collection exist to store the news data.

Step 4: Loading Couchbase Vector Search Index

Semantic search requires an efficient way to retrieve relevant documents based on a user’s query. This is where Couchbase Vector Search, formerly known as Full-Text Search (FTS) service, comes into play. In this step, we load the Vector Search Index definition from a JSON file, which specifies how the index should be structured. This includes the fields to be indexed, the dimensions of the vectors, and other parameters that determine how the search engine processes queries based on vector similarity.

Step 5: Initialize AI Models

Here is the magic: we initialize the embedding model using OpenAIE임베딩 but point it to Capella. Couchbase AI Services provide OpenAI-compatible endpoints that are used by the agents. For embeddings, we’re using the LangChain OpenAI package as it is used in association with the LangChain Couchbase integration.

Step 6: Ingest Data

We load the BBC News dataset and ingest it into Couchbase. The 카우치베이스검색벡터스토어 automatically handles generating embeddings using our defined model and storing them.

Step 7: Build the RAG Chain

Now we create the RAG pipeline. We initialize the LLM (again pointing to Capella) and connect it to our vector store retriever.

Step 8: Run Queries

Let’s test our RAG.

Example Output:

답변: Pep Guardiola has expressed concern and frustration about Manchester City’s recent form. He stated, “I am not good enough. I am the boss… I have to find solutions.” He acknowledged the team’s defensive issues and lack of confidence.

결론

이 튜토리얼에서는 방법을 배웠습니다:

  1. Vectorize data using Couchbase.
  2. Use Couchbase AI Services for embeddings and LLM.
  3. Implement RAG with Couchbase Vector Search.

Couchbase’s unified database platform creates powerful AI applications that can generate high-quality, contextually-aware content.

이 문서 공유하기
받은 편지함에서 카우치베이스 블로그 업데이트 받기
이 필드는 필수 입력 사항입니다.

Author

Posted by 로랑 도귄

Laurent는 파리에 사는 괴짜 금속공학도입니다. 주로 Java로 코드를 작성하고 AsciiDoc으로 구조화된 텍스트를 작성하며 데이터, 리액티브 프로그래밍 및 기타 유행어에 대해 자주 이야기합니다. 또한 Clever Cloud와 Nuxeo의 개발자 옹호자로 활동하며 해당 커뮤니티가 더 크고 강력하게 성장할 수 있도록 자신의 시간과 전문성을 바쳤습니다. 현재 Couchbase에서 개발자 관계를 운영하고 있습니다.

댓글 남기기

카우치베이스 카펠라를 시작할 준비가 되셨나요?

구축 시작

개발자 포털에서 NoSQL을 살펴보고, 리소스를 찾아보고, 튜토리얼을 시작하세요.

카펠라 무료 사용

클릭 몇 번으로 Couchbase를 직접 체험해 보세요. Capella DBaaS는 가장 쉽고 빠르게 시작할 수 있는 방법입니다.

연락하기

카우치베이스 제품에 대해 자세히 알고 싶으신가요? 저희가 도와드리겠습니다.