Skip to main content
This guide demonstrates how to build a complete Retrieval-Augmented Generation (RAG) application using Neosantara AI for embeddings and large language model (LLM) calls, integrated with ChromaDB as your vector database.

Overview

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

Setup

First, ensure you have Python installed. Then, install the necessary libraries:

Configure your Neosantara AI API Key

You’ll need a Neosantara AI API Key. If you don’t have one, get it from your Neosantara Dashboard. Set your API key and Neosantara AI base URL as environment variables or directly in your script:

Creating the Embedding Database with ChromaDB

ChromaDB is a lightweight vector database that runs locally (or can be scaled up). You’ll create a Chroma collection and populate it with your document embeddings.

Custom Embedding Function for ChromaDB

ChromaDB allows you to define a custom embedding function. We’ll wrap the Neosantara AI embedding API call within this function.

Your Data

Here is a small set of documents you will use to create an embedding database. In a real application, these would come from your knowledge base, internal wikis, etc.

Create and Populate ChromaDB

Now, create a ChromaDB client, define a collection, and add your documents to it using the custom embedding function.

Getting the Relevant Document (Retrieval)

With ChromaDB populated, you can now query it to find documents relevant to a user’s question.

Generating a Grounded Answer (Generation)

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

Full Example Execution

Let’s put it all together and test with some queries:

Expected Output Example