Spaces:
Runtime error
Runtime error
A newer version of the Gradio SDK is available: 6.20.0
metadata
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
Document Ingestion
- Text extraction
- Cleaning and chunking
- Embedding generation
Retrieval
- Query converted to embedding
- Top-K relevant chunks retrieved via FAISS
Re-ranking
- CrossEncoder improves relevance ordering
Generation
- LLM generates answer using retrieved context
Source Attribution
- Displays ranked document chunks used
π¦ Installation
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
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!


