This project implements a Retrieval-Augmented Generation (RAG) chatbot that answers questions based on user-provided PDF documents.
- 📄 Dynamic knowledge base — user uploads PDFs which are split into paragraphs
- ⚙️ Embeddings using Sentence Transformers — converts text into vectors
- 🧱 FAISS-based retrieval — efficiently finds the most relevant paragraphs
- 🤖 Text generation using Flan-T5 — generates answers using retrieved context
- 💻 Local inference — runs on CPU, Apple MPS, or NVIDIA CUDA GPU
- 🖥️ Gradio UI — web interface for uploading PDFs and asking questions
- 🛠️ Lazy model loading — model loads only on first query for faster startup
Below is a preview of the Gradio Interface used for real-time classification:
- PyTorch – model and inference
- Transformers – Flan-T5 text generation
- sentence-transformers – embeddings
- faiss – vector retrieval
- numpy – numerical operations
- PyPDF2 – PDF parsing
- gradio – UI interface
- Python 3.13+
- Recommended editor: VS Code
- Clone the repository
git clone https://github.com/hurkanugur/RAG-Based-ChatBot.git- Navigate to the
RAG-Based-ChatBotdirectory
cd RAG-Based-ChatBot- Install dependencies
pip install -r requirements.txtView → Command Palette → Python: Create Environment- Choose Venv and your Python version
- Select requirements.txt to install dependencies
- Click OK
assets/
└── app_screenshot.png # Application screenshot
src/
├── config.py # Paths, model settings...
├── device_manager.py # Selects and manages compute device
├── embeddings.py # Local embedding model
├── retriever.py # FAISS-based retrieval
├── generator.py # Text generation model
├── pdf_loader.py # PDF parsing
└── ui.py # Gradio UI
main/
└── main.py # Entry point for chatbot
requirements.txt # Python dependenciesUser PDF Upload
↓
PDF Loader (split into paragraphs)
↓
Sentence Transformer Embeddings
↓
FAISS Retriever (top-k relevant paragraphs)
↓
Flan-T5 Generator (with retrieved context)
↓
Answer displayed in Gradio UINavigate to the project directory:
cd RAG-Based-ChatBotRun the app:
python -m main.mainor
python3 -m main.main
