Spaces:
Runtime error
Runtime error
File size: 2,741 Bytes
66dedca e80959b 66dedca e80959b 66dedca e80959b 66dedca e80959b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
---
title: RAG Document Q&A System
emoji: π
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
license: mit
---
# π RAG Document Q&A System
A Retrieval-Augmented Generation (RAG) system that answers questions about uploaded PDF documents.
## π― What This Does
1. **Upload** a PDF document
2. **Process** the document (chunks it and creates embeddings)
3. **Ask** questions about the document
4. **Get** accurate answers with source citations
## ποΈ Architecture
```
User Question β Embedding β Vector Search β Retrieved Chunks β LLM β Answer
```
| Component | Technology |
|-----------|------------|
| Embeddings | sentence-transformers/all-MiniLM-L6-v2 (384 dimensions) |
| Vector Store | FAISS (Facebook AI Similarity Search) |
| Text Splitter | RecursiveCharacterTextSplitter (1000 chars, 200 overlap) |
| LLM | HuggingFaceH4/zephyr-7b-beta via Inference API |
| Framework | LangChain + Gradio |
## π οΈ Development Challenges
This project encountered several technical challenges during development:
### Challenge 1: LangChain API Changes
**Problem:** Import errors due to LangChain's package restructuring.
```python
# Old (broken)
from langchain.document_loaders import PyPDFLoader
from langchain.chains import RetrievalQA
# New (working)
from langchain_community.document_loaders import PyPDFLoader
# RetrievalQA deprecated β use LCEL chains instead
```
**Lesson:** Fast-evolving libraries require checking current documentation.
### Challenge 2: PDF Download Issues
**Problem:** `PdfStreamError: Stream has ended unexpectedly`
**Cause:** Incomplete download due to missing User-Agent header.
**Solution:** Added proper headers to HTTP request.
### Challenge 3: LLM Response Quality
**Problem:** FLAN-T5-Large produced fragment-like responses instead of complete answers.
**Attempted Solutions:**
1. Adjusted generation parameters β minimal improvement
2. Modified prompt format β slight improvement
3. Switched to FLAN-T5-XL β OOM error
**Final Solution:** Switched to Zephyr-7B-beta, which produces comprehensive answers.
## π Limitations
- Only processes PDF documents
- English language only
- Free Inference API has rate limits
## π€ Author
[Nav772](https://huggingface.co/Nav772) - Built as part of AI Engineering portfolio
## π Related Projects
- [Movie Sentiment Analyzer](https://huggingface.co/spaces/Nav772/movie-sentiment-analyzer)
- [Amazon Review Rating Predictor](https://huggingface.co/spaces/Nav772/amazon-review-rating-predictor)
- [Food Image Classifier](https://huggingface.co/spaces/Nav772/food-image-classifier)
- [Sentiment Model Comparison](https://huggingface.co/spaces/Nav772/sentiment-model-comparison)
|