Spaces:
Runtime error
Runtime error
| 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 | |
|  | |
| ### π¬ Question Answering | |
|  | |
| ### π Retrieved Sources (Grounded Answers) | |
|  | |
| --- | |
| ## π§ 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! |