--- license: mit title: RAG Document QA sdk: gradio emoji: 💻 colorFrom: blue colorTo: purple pinned: false --- # 📄 Document Q&A System with RAG (LLM Pipeline) 🚀 A Retrieval-Augmented Generation (RAG) system that enables natural language question answering over custom documents with source-grounded responses. --- ## 🔥 Demo ### 📂 Upload & Ingestion ![Upload](screenshots/upload.png) ### 💬 Question Answering ![QA](screenshots/qa.png) ### 📚 Retrieved Sources (Grounded Answers) ![Sources](screenshots/sources.png) --- ## 🧠 Overview This project implements a **Retrieval-Augmented Generation (RAG)** pipeline that allows users to: - Upload documents (PDF/TXT) - Ask natural language questions - Receive context-aware answers - View source passages used to generate the answer The system ensures **low hallucination** by grounding responses strictly in retrieved document context. --- ## ⚙️ Architecture User Query ↓ Embedding (Sentence Transformers) ↓ FAISS Vector Search (Top-K Retrieval) ↓ Re-ranking (CrossEncoder) ↓ Context Selection ↓ LLM (FLAN-T5) ↓ Final Answer + Source Attribution --- ## ✨ Features - 📂 Document upload (PDF & TXT) - 🔍 Semantic search using FAISS - 🧠 Context-aware answer generation using LLM - 📊 Re-ranking for improved retrieval quality - 📚 Source attribution (transparent answers) - ⚡ Fast inference (<2s latency on CPU) - 🎯 No hallucination — answers strictly from document --- ## 🛠️ Tech Stack - **Language:** Python - **LLM:** FLAN-T5 (Hugging Face) - **Embeddings:** sentence-transformers - **Vector DB:** FAISS - **Re-ranking:** CrossEncoder (ms-marco) - **Framework:** Gradio - **Deployment:** Hugging Face Spaces (optional) --- ## 🚀 How It Works 1. **Document Ingestion** - Text extraction - Cleaning and chunking - Embedding generation 2. **Retrieval** - Query converted to embedding - Top-K relevant chunks retrieved via FAISS 3. **Re-ranking** - CrossEncoder improves relevance ordering 4. **Generation** - LLM generates answer using retrieved context 5. **Source Attribution** - Displays ranked document chunks used --- ## 📦 Installation ```bash git clone https://github.com/your-username/rag-doc-qa.git cd rag-doc-qa python -m venv venv venv\Scripts\activate # Windows pip install -r requirements.txt ``` --- ## ▶️ Run Locally ```bash python app.py ``` Open: ``` http://127.0.0.1:7860 ``` --- ## 📊 Example Queries - What is the main topic of the document? - Summarize the key points. - What conclusions are drawn? - Explain machine learning mentioned in the document. --- ## 🎯 Key Highlights - Combines **retrieval + generation** for accurate answers - Reduces hallucination via grounded context - Implements **real-world RAG pipeline used in industry** - Includes **re-ranking for improved precision** --- ## 📌 Future Improvements - Multi-document support - Chat history memory - Streaming responses - Hybrid search (BM25 + dense retrieval) --- ## 👨‍💻 Author **Shubham** --- ## ⭐ If you like this project Give it a ⭐ on GitHub and feel free to connect!