An Explainable Retrieval-Augmented Generation (RAG) system that allows users to upload a PDF, ask questions about its content, and receive:
- π A grounded answer
- π§ An explanation of why specific context was used
- π Source pages with relevance scores
Built using Gradio, LangChain, ChromaDB, and Hugging Face models.
- π Upload and index any PDF
- π Semantic search using embeddings (MiniLM)
- π€ Question answering using FLAN-T5
- π§ Explainability layer: why this answer?
- π Source attribution with relevance scores
- π» Runs fully on CPU (Colab / low-resource friendly)
-
PDF Loader
UsesPyPDFLoaderto extract text from PDFs. -
Text Chunking
Splits text into overlapping chunks usingRecursiveCharacterTextSplitter. -
Embeddings
- Model:
sentence-transformers/all-MiniLM-L6-v2 - Normalized embeddings for accurate similarity scoring.
- Model:
-
Vector Store
ChromaDBfor fast semantic retrieval- Persistent storage
-
LLM
google/flan-t5-base- Used twice:
- Answer generation
- Explanation generation
-
UI
- Built with Gradio Blocks
- Simple and interactive interface
- Python
- Gradio
- LangChain
- ChromaDB
- Hugging Face Transformers
- PyTorch
pip install gradio torch transformers langchain langchain-community chromadb sentence-transformers pypdf