카우치베이스 서버

코드랩: Couchbase Capella 모델 서비스와 LangChain을 활용한 RAG 애플리케이션 구축

8 분 읽기

In this tutorial, you will learn how to build a retrieval-augmented generation (RAG) application using 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. Log into 카우치베이스 카펠라.
  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.

Enable AI Services

  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 mistralai/mistral-7b-instruct-v0.3. For embeddings, you can choose a model like the nvidia/llama-3.2-nv-embedqa-1b-v2.
  • 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 OpenAIEmbeddings 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 CouchbaseSearchVectorStore 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:

    Answer: 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.

    결론

    In this tutorial, you learned how to:

    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.

    이 기사 공유하기

    작가

    로랑은 파리에 사는 찌질한 매니아 기질이 있는 헤비메탈 마니아입니다. 그는 주로 자바(Java)로 코드를 작성하고 AsciiDoc으로 구조화된 텍스트를 작성하며, 데이터, 리액티브 프로그래밍 및 기타 유행어 같은 주제에 대해 자주 이야기합니다. 그는 또한 Clever Cloud와 Nuxeo의 전직 개발자 애드보케이트로 활동하며 해당 커뮤니티가 더 크고 강하게 성장하도록 시간과 전문 지식을 쏟아부었습니다. 현재는 카우치베이스(Couchbase)에서 개발자 관계(Developer Relations)를 총괄하고 있습니다.

    댓글 남기기

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

    개발 시작하기

    NoSQL을 탐색하고, 리소스를 찾아보고, 튜토리얼을 시작하려면 개발자 포털을 확인하세요.

    카펠라 프리 사용하기

    단 몇 번의 클릭으로 카우치베이스(Couchbase)를 직접 체험해 보세요. Capella DBaaS는 시작하기 가장 쉽고 빠른 방법입니다.

    연락해

    Couchbase 제품군에 대해 더 알고 싶으신가요? 저희가 도와드리겠습니다.