Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RAG-BOT

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.


How It Works

┌─────────────┐     /ask or /compare     ┌─────────────────────┐
│  Browser UI │ ───────────────────────► │  FastAPI Backend     │
└─────────────┘                          └────────┬────────────┘
                                                  │
                          ┌───────────────────────┼───────────────────────┐
                          ▼                       ▼                       ▼
                   ┌─────────────┐      ┌──────────────────┐    ┌──────────────┐
                   │  ChromaDB   │      │ Gemini Embedding  │    │ Gemini Flash │
                   │ (vector DB) │      │      API          │    │  (LLM chat)  │
                   └─────────────┘      └──────────────────┘    └──────────────┘
  1. On startup — the backend scans the data/ folder and indexes every .txt, .pdf, and image file into ChromaDB using Gemini embeddings.
  2. 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.
  3. 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.

Project Structure

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

Prerequisites


Setup & Run

Step 1 — Clone the repository

git clone https://github.com/FarzamKMP/Simple-RagBot.git
cd RAG-BOT

Step 2 — Create a virtual environment

python3 -m venv venv
source venv/bin/activate        # macOS / Linux
# venv\Scripts\activate         # Windows

Step 3 — Install dependencies

pip install -r backend/requirements.txt

Step 4 — Configure environment variables

cp backend/.env.example backend/.env

Open backend/.env and fill in your values:

GEMINI_API_KEY=your_gemini_api_key_here

The other variables (DATABASENAME, DATABASEUSER, etc.) are optional and not required to run the core RAG features.

Step 5 — Add your documents

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

Step 6 — Start the backend

cd backend
uvicorn main:app --reload

The 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

Step 7 — Open the frontend

Open frontend/index.html directly in your browser — no build step needed.

Tip: If you use VS Code, right-click index.htmlOpen with Live Server for a smoother experience.


Usage

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

API Reference

POST /ask

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].


POST /compare

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..."
}

Supported File Types

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

Tech Stack

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

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages