Skip to main content
This guide demonstrates how to build a scalable Retrieval-Augmented Generation (RAG) application leveraging Cloudflare Vectorize as your managed vector database, integrated with Neosantara AI for embeddings and large language model (LLM) calls. Cloudflare Vectorize offers a serverless and highly scalable solution for storing and querying vector embeddings, making it an excellent choice for RAG applications that need to handle large datasets.

Overview

You will learn to:
  1. Set up your Neosantara AI API client and Cloudflare API credentials.
  2. Create and manage a Vectorize index.
  3. Use Neosantara AI’s embedding model (nusa-embedding-0001) to vectorize your documents.
  4. Store these embeddings in Cloudflare Vectorize.
  5. Retrieve relevant documents from Vectorize based on a user query.
  6. Use Neosantara AI’s chat model (nusantara-base) to generate a grounded answer using the retrieved context.

Prerequisites

  • A Cloudflare account with API Token access (with permissions for Vectorize).
  • Your Cloudflare Account ID.
  • A Neosantara AI API Key.

Setup

First, install the necessary Python library:

Configure your API Keys and Client

Step 1: Indexing Documents in Vectorize (Ingestion)

First, let’s define our documents and create a Vectorize index.

Create Vectorize Index

You need to create an index in Cloudflare Vectorize. The dimension should match the output dimension of your embedding model (e.g., 768 for nusa-embedding-0001).

Your Data

Generate Embeddings and Upsert to Vectorize

Now, we’ll embed each document and send it to your Cloudflare Vectorize index.

Step 2: Querying Vectorize (Retrieval)

When a user asks a question, we embed their query and use Vectorize to find the most relevant document embeddings.

Step 3: Generate Answer (Generation)

Finally, construct the prompt with the retrieved context and send it to a Neosantara AI chat model.

Full Example Execution

Expected Output Example