Quick Start โข Features โข Architecture โข API Docs
RAG Chatbot is a cutting-edge Retrieval-Augmented Generation (RAG) application that transforms how you interact with your documents. Upload any PDF, and engage in intelligent, context-aware conversations powered by Google's Gemini AI.
Unlike traditional chatbots, RAG Chatbot doesn't hallucinate โ it answers based strictly on the content of your uploaded documents, combining the power of semantic search with advanced language models.
- โ 100% Context-Grounded: Answers derived exclusively from your documents
- โก Lightning Fast: Optimized retrieval with FAISS vector database
- ๐จ Premium UI/UX: Glassmorphism design with smooth animations
- ๐ Privacy-First: Process documents locally with no data persistence on restart
Get up and running in 3 minutes!
- Python 3.9+ โ Download
- Node.js 18+ โ Download
- Google API Key โ Get one here
git clone https://github.com/yugam23/RAG-Chatbot.git
cd RAG-Chatbotcd backend
python -m venv venv
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate
pip install -r requirements.txtConfigure Environment:
Create a .env file in backend/:
GOOGLE_API_KEY=your_actual_api_key_here
ALLOWED_ORIGINS=http://localhost:5173Run the Backend:
python main.py
# ๐ Server running at http://localhost:8000Open a new terminal:
cd frontend
npm install
npm run dev
# โจ App running at http://localhost:5173| Feature | Description |
|---|---|
| ๐ค Google Gemini Integration | Powered by gemini-flash-latest for ultra-fast, accurate responses |
| ๐ Advanced RAG Pipeline | Semantic chunking (800 chars, 400 overlap) + Gecko embeddings |
| ๐พ Vector Search | FAISS CPU-optimized indexing with k=7 retrieval |
| ๐ Robust PDF Processing | Magic byte validation, 50MB limit, secure temp storage |
| ๐ฌ Session Management | SQLite-based chat history with full persistence |
| ๐ Auto-Reset | Session and index auto-clear on server restart |
| Feature | Description |
|---|---|
| โจ Glassmorphism Design | Modern blur effects, gradients, and depth |
| ๐ฌ Startup Animation | Smooth logo intro with motion transitions |
| ๐ฌ Real-Time Streaming | Server-Sent Events (SSE) for live response rendering |
| ๐ Markdown Support | Full syntax highlighting with react-markdown + remark-gfm |
| ๐ฑ Fully Responsive | Optimized for desktop, tablet, and mobile |
| โก Optimized Caching | TanStack Query for efficient data fetching |
RAG Chatbot follows a modern client-server architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ USER INTERFACE โ
โ React + Vite + Tailwind CSS + Framer Motion + TanStack Query โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ HTTP/SSE
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ FASTAPI BACKEND โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Routers โ โ Middleware โ โ State Manager โ โ
โ โ /upload โ โ - Rate Limit โ โ - Session State โ โ
โ โ /chat โ โ - Request ID โ โ - Vector Store Ref โ โ
โ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ RAG PIPELINE (LangChain) โ โ
โ โ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ โ
โ โ โ PDF โโโโถโ Chunk โโโโถโ Embed โโโโถโ FAISS โ โ โ
โ โ โ Loader โ โ (800) โ โ (Gecko) โ โ Index โ โ โ
โ โ โโโโโโโโโโ โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- ๐ค Document Ingestion: PDF Upload โ Magic Byte Validation โ Text Extraction โ Recursive Chunking (800/400).
- ๐งฎ Embedding & Indexing: Google Gecko Embeddings โ FAISS Vector Store.
- ๐ฌ Query Processing: User Query โ Embedding โ Similarity Search (Top-k) โ Prompt Construction.
- ๐ค Response Generation: Context + Query โ Gemini Flash โ Streaming Response.
RAG-Chatbot/
โโโ ๐ backend/ # FastAPI Python Backend
โ โโโ ๐ routers/ # API Route Handlers
โ โ โโโ upload.py # PDF upload & indexing endpoint
โ โ โโโ chat.py # Chat streaming & history endpoints
โ โโโ ๐ tests/ # Pytest Test Suite
โ โโโ ๐ temp/ # Temporary PDF storage
โ โโโ ๐ faiss_index/ # Vector database (generated)
โ โโโ config.py # Centralized configuration
โ โโโ database.py # SQLite async operations
โ โโโ ingestion.py # Document processing pipeline
โ โโโ rag.py # RAG chain implementation
โ โโโ state.py # Application state management
โ โโโ vector_store.py # Vector store logic
โ โโโ middleware.py # Rate limiting & request tracking
โ โโโ logging_config.py # Structured logging setup
โ โโโ models.py # Pydantic models
โ โโโ main.py # FastAPI app entry point
โ โโโ requirements.txt # Python dependencies
โ
โโโ ๐ frontend/ # React + Vite Frontend
โ โโโ ๐ src/
โ โ โโโ ๐ components/ # React Components (Header, ChatArea, etc.)
โ โ โโโ ๐ hooks/ # Custom React Hooks (useChat, useApiQueries)
โ โ โโโ ๐ services/ # API Communication
โ โ โโโ ๐ context/ # React Context Providers
โ โ โโโ App.jsx # Main App component
โ โ โโโ main.jsx # React entry point
โ โ โโโ index.css # Global styles & theme
โ โโโ ๐ public/ # Static Assets
โ โโโ vite.config.js # Vite configuration
โ
โโโ ๐ README.md # This file!
| Variable | Required | Default | Description |
|---|---|---|---|
GOOGLE_API_KEY |
โ Yes | โ | Google AI API key for Gemini & Gecko |
ALLOWED_ORIGINS |
โ No | http://localhost:5173 |
Comma-separated CORS origins |
# Document Processing
CHUNK_SIZE = 800 # Characters per chunk
CHUNK_OVERLAP = 400 # Overlap between chunks
# Retrieval
RETRIEVER_K = 7 # Number of chunks to retrieve
# Models
EMBEDDING_MODEL = "models/text-embedding-004"
LLM_MODEL = "gemini-flash-latest"Full interactive documentation available at http://localhost:8000/docs.
POST /upload: Upload and index a PDF. Validates magic bytes and size.POST /chat: Stream chat response via SSE. Requires active session.GET /history: Retrieve stored chat history.POST /clear-chat: Clear history but keep document index.POST /reset: Full session reset (wipes history + index).
cd backend
pytest -v # Run all tests
pytest tests/test_ingestion.py # Test specific moduleValidationError: GOOGLE_API_KEY field required: Add your API key tobackend/.env.Failed to fetch: Ensure backend is running on port 8000.Invalid file type: Ensure the file is a valid PDF.
Made with โค๏ธ by Yugam
