RAG with Gemini and other Open AI Alternatives
In this module, we’ll cover how to build a RAG project using alternate APIs by Gemini, Replicate, and 300+ LLMs apart from OpenAI.
Here you'll use Google Gemini Pro for chat completions/generation and Sentence Transformer for embeddings.
If you've already built a pipeline using OpenAI, you can jump to Step 4.
Introduction
We’ll walk you through setting up a RAG project using Gemini Pro and Pathway.
Key Features:
Create an in-memory persistent vector store with real-time document indexing using Pathway that can easily work with documents in your Google Drive, Microsoft 365 SharePoint, Databases, Local directory, etc.
Connect an LLM model of choice (https://docs.litellm.ai/docs/providers) to your knowledge base.
Get quality, accurate, and precise responses to your questions.
Ask questions about folders, files, or all your documents easily, with the help of filtering options.
Get an executive outlook for a question on different files to easily access available knowledge in your documents.
Prerequisites
Before we begin, ensure you have the following requirements we shared earlier:
Docker Desktop: This tool allows you to run applications in isolated containers. Download Docker Desktop. (Note: Your antivirus software might block the installation, so temporarily disable it if needed.)
If you’re using VS Code, consider installing the Docker extension to manage containers directly from the editor.
Step-by-Step Process
Step 1: Verify Docker Installation
First, let’s verify that Docker is properly installed and open in your system. Open your terminal (Command Prompt on Windows) and run:
You should see the Docker version information if it's installed correctly.
Step 2: Clone the LLM App Templates Repository
Next, clone the llm-app
repository from GitHub. This repository contains all the files you’ll need.
If you get an error because you have previously cloned an older version of the llm-app
repository, ensure you're in the correct repository directory and update it using:
This will update your local repository with the latest changes from the remote repository.
Step 3: Navigate to the Project Directory
Change to the directory where the relevant example of your current project is located.
Step 4: Create a .env
File and Put Your Gemini API Key
.env
File and Put Your Gemini API KeyIf you've already built a pipeline with Open AI, this is where things get slightly different. Configure your key in a .env
file by providing it as follows:
Replace *******
with your actual Gemini API key. Save the file as .env
in the demo-question-answering
folder.
Step 5: Update requirements.txt
File
requirements.txt
FileAdd the following dependencies to the requirements.txt
file that enable us to use Pathway LiteLLM wrapper, Google's APIs, and Sentence Transformers (a.k.a. SBERT) for embeddings:
Step 6: Update app.py
Code
app.py
CodeReplace the existing app.py
code with the following:
Key Changes:
Embedding Model Selection: Chose
avsolatorio/GIST-small-Embedding-v0
for embedding chunked texts. This model is compact and performed well in tests. Other options includemixedbread-ai/mxbai-embed-large-v1
andavsolatorio/GIST-Embedding-v0
.LLM Initialization: Integrated the Gemini Pro model by updating the configuration and initialization script to use
LLM_MODEL
instead ofGPT_MODEL
.
Step 7: Update config.yaml
File
config.yaml
FileUpdate the model specification in the config.yaml
file to use Gemini Pro and keep rest of the items as is:
Step 8: Build the Docker Image
Build the Docker image. This step might take a few minutes depending on your machine. Ensure you have enough space (approximately 8 GB).
Step 9: Run the Docker Container
Run the Docker container, mounting the data folder and exposing port 8000. For Windows:
For Linux/Mac:
Handling Port Conflicts: If port 8000 is already in use, specify a different port. For example, to use port 8080:
For Windows:
For Linux/Mac:
Step 10: Check the List of Files
To see the list of files in the data folder, use the curl command. While doing this ensure that you'll need to update the port here as well if you changed it in the previous step while managing port conflicts:
This will return the list of files that are ingested as an external data source for your RAG project.
Step 11: Run the RAG Service
Start the RAG service by asking a simple question. For example:
The response should be something like:
Conclusion
This will help you set up a powerful RAG pipeline with Gemini Pro.
If you get stuck, you should explore the Pathway documentation here and try to find the issue yourself once. It will also help you understand the code better, and many of your queries can actually be figured out via LLMs as well.
Last updated