rag-doc-qa / README.md
ShubhamAC's picture
Update README.md
abbe39d verified
|
Raw
History Blame Contribute Delete
3.21 kB

A newer version of the Gradio SDK is available: 6.20.0

Upgrade
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

Upload

πŸ’¬ Question Answering

QA

πŸ“š Retrieved Sources (Grounded Answers)

Sources


🧠 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

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!