A Retrieval-Augmented Generation (RAG) chatbot powered by Google Gemini. Drop documents into a folder, ask questions about them, and see the difference RAG makes with a side-by-side comparison mode.
┌─────────────┐ /ask or /compare ┌─────────────────────┐
│ Browser UI │ ───────────────────────► │ FastAPI Backend │
└─────────────┘ └────────┬────────────┘
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
┌─────────────┐ ┌──────────────────┐ ┌──────────────┐
│ ChromaDB │ │ Gemini Embedding │ │ Gemini Flash │
│ (vector DB) │ │ API │ │ (LLM chat) │
└─────────────┘ └──────────────────┘ └──────────────┘
- On startup — the backend scans the
data/folder and indexes every.txt,.pdf, and image file into ChromaDB using Gemini embeddings. - On
/ask— the user's question is embedded, the most relevant chunks are retrieved from ChromaDB, and Gemini generates a streamed answer grounded in those chunks. - On
/compare— the same question is answered twice in parallel: once without context (raw LLM) and once with RAG context, displayed side-by-side so you can see the difference.
RAG-BOT/
├── backend/
│ ├── main.py # FastAPI app — routes: /ask, /compare
│ ├── RagEngine.py # Indexing, retrieval, and Gemini generation
│ ├── requirements.txt
│ ├── .env # Your secrets (not committed)
│ └── .env.example # Template for environment variables
├── frontend/
│ ├── index.html # Chat UI
│ ├── main.js # Streaming fetch + compare logic
│ └── main.css # Styles
├── data/ # Drop your documents here (.txt, .pdf, .png, .jpg)
└── README.md
- Python 3.10+
- A Google AI Studio account to get a Gemini API key
git clone https://github.com/FarzamKMP/Simple-RagBot.git
cd RAG-BOTpython3 -m venv venv
source venv/bin/activate # macOS / Linux
# venv\Scripts\activate # Windowspip install -r backend/requirements.txtcp backend/.env.example backend/.envOpen backend/.env and fill in your values:
GEMINI_API_KEY=your_gemini_api_key_hereThe other variables (
DATABASENAME,DATABASEUSER, etc.) are optional and not required to run the core RAG features.
Place any .txt, .pdf, .png, or .jpg files into the data/ folder. These will be automatically indexed when the server starts.
data/
├── your-document.pdf
├── notes.txt
└── screenshot.png
cd backend
uvicorn main:app --reloadThe API will be available at http://localhost:8000.
You should see log lines like:
INFO: Indexed your-document.pdf → 42 chunks
INFO: Ready. Chunks: 42
Open frontend/index.html directly in your browser — no build step needed.
Tip: If you use VS Code, right-click
index.html→ Open with Live Server for a smoother experience.
| Action | How |
|---|---|
| Ask a question | Type your question and press Enter or click Send |
| New line in input | Press Shift + Enter |
| Compare RAG vs no RAG | Type a question and click ⚡ Compare |
The Compare mode shows two answers side by side:
- ❌ Without RAG — the LLM answers from its general training data only
- ✅ With RAG — the LLM answers using relevant chunks retrieved from your documents
Stream an answer grounded in your documents.
Request:
{ "question": "What is the return policy?" }Response: Server-Sent Events stream of { "text": "..." } chunks, terminated by [DONE].
Get two answers in a single request.
Request:
{ "question": "What is the return policy?" }Response:
{
"without_rag": "I don't have specific information about...",
"with_rag": "According to the document, the return policy is...",
"context": "...retrieved chunks used..."
}| Type | How it's indexed |
|---|---|
.txt |
Raw text chunked and embedded |
.pdf |
Text extracted page by page, then chunked |
.png / .jpg / .jpeg |
Described and OCR'd by Gemini Vision, then embedded |
| Layer | Technology |
|---|---|
| LLM & Embeddings | Google Gemini 2.5 Flash + Gemini Embedding 001 |
| Vector Database | ChromaDB (in-memory) |
| Backend | FastAPI + Uvicorn |
| Frontend | Vanilla HTML / CSS / JS |