--- title: VDoc-RAG emoji: ๐Ÿ“„ colorFrom: blue colorTo: purple sdk: docker pinned: false --- # ๐Ÿ“„ VDoc-RAG (Visually-Rich Document Retrieval-Augmented Generation) VDoc-RAG is an intelligent document Q&A system that answers questions from PDFs, resumes, reports, and other visually-rich documents using RAG (Retrieval-Augmented Generation) technology. ๐Ÿ”— **Live Demo**: [https://huggingface.co/spaces/adi9128/vdoc_rag](https://huggingface.co/spaces/adi9128/vdoc_rag) --- ## โœจ Key Features | Feature | Description | |---------|-------------| | ๐Ÿ“ค **Document Upload** | Upload PDF files for instant processing | | ๐Ÿ” **Smart Q&A** | Ask natural language questions about your documents | | ๐Ÿง  **RAG Pipeline** | Retrieval-Augmented Generation with ChromaDB vector store | | ๐Ÿ“Š **OCR + Table/Chart Extraction** | Tesseract OCR with visual element detection | | ๐Ÿ’ฏ **Confidence Scoring** | Cosine similarity scores for retrieved chunks | | ๐Ÿ“ **Feedback System** | Mark answers as correct/incorrect for improvement | | ๐Ÿ”„ **Document Isolation** | Each upload clears previous data for privacy | | ๐ŸŽจ **Modern UI** | Clean gradient design with responsive layout | --- ## ๐Ÿš€ Live Deployment The app is deployed on **HuggingFace Spaces** using Docker: - **URL**: https://huggingface.co/spaces/adi9128/vdoc_rag - **SDK**: Docker (Python 3.11) - **Port**: 7860 --- ## ๐Ÿ’ป Local Development ### Prerequisites Install these tools and add them to PATH: - **Python 3.11+** - **Tesseract OCR** โ†’ [Download](https://github.com/UB-Mannheim/tesseract/wiki) - **Poppler** โ†’ [Download](https://github.com/oschwartz10612/poppler-windows/releases) ### Setup ```bash # Clone the repository git clone https://github.com/YOUR_USERNAME/vdoc-rag.git cd vdoc-rag # Create virtual environment python -m venv venv venv\Scripts\activate # Windows # source venv/bin/activate # Linux/Mac # Install dependencies pip install -r requirements.txt # Set environment variables # Create .env file with: GEMINI_API_KEY=your_gemini_api_key_here # Run the server uvicorn app.main:app --host 127.0.0.1 --port 8000 ``` Open โ†’ [http://127.0.0.1:8000](http://127.0.0.1:8000) --- ## ๐Ÿ–ฅ๏ธ Web Interface | Route | Description | |-------|-------------| | `/` | Main interface - Upload documents & ask questions | | `/feedback_dashboard` | View feedback statistics | | `/benchmark_dashboard` | Embedding model evaluation metrics | --- ## ๐Ÿ“ Project Structure ``` vdoc-rag/ โ”œโ”€โ”€ app/ โ”‚ โ”œโ”€โ”€ main.py # FastAPI server & routes โ”‚ โ”œโ”€โ”€ indexer.py # ChromaDB vector store wrapper โ”‚ โ”œโ”€โ”€ embeddings.py # Sentence-transformer embeddings โ”‚ โ”œโ”€โ”€ ingest.py # PDF processing & OCR โ”‚ โ”œโ”€โ”€ reader.py # LLM (Gemini) integration โ”‚ โ”œโ”€โ”€ chart_reasoner.py # Chart/graph understanding โ”‚ โ”œโ”€โ”€ feedback_manager.py # User feedback collection โ”‚ โ”œโ”€โ”€ visual_highlight.py # PDF region highlighting โ”‚ โ”œโ”€โ”€ cache_manager.py # Response caching โ”‚ โ””โ”€โ”€ templates/ # HTML templates โ”‚ โ”œโ”€โ”€ index.html โ”‚ โ”œโ”€โ”€ feedback_dashboard.html โ”‚ โ””โ”€โ”€ benchmark_dashboard.html โ”œโ”€โ”€ Dockerfile # HuggingFace Spaces deployment โ”œโ”€โ”€ requirements.txt # Python dependencies โ”œโ”€โ”€ TESTING_GUIDE.md # Step-by-step testing guide โ””โ”€โ”€ README.md ``` --- ## ๐Ÿง  Technology Stack | Component | Technology | |-----------|------------| | **Backend** | FastAPI + Uvicorn | | **Vector Database** | ChromaDB (persistent) | | **Embeddings** | Sentence-Transformers (all-MiniLM-L6-v2) | | **LLM** | Google Gemini API | | **OCR** | Tesseract + Poppler | | **PDF Processing** | pdf2image + PyMuPDF | | **Frontend** | Jinja2 + TailwindCSS | | **Deployment** | Docker on HuggingFace Spaces | --- ## ๐Ÿ”’ Privacy & Document Isolation - **Stateless Design**: Each page refresh shows a clean interface - **Document Isolation**: Uploading a new document clears all previous data - **No Persistent User Tracking**: Documents are processed in-memory per session - **Shared Instance Note**: HuggingFace free tier uses a single server instance --- ## ๐Ÿ“ˆ How It Works 1. **Upload**: PDF is processed with OCR and chunked into text segments 2. **Embed**: Chunks are converted to vectors using Sentence-Transformers 3. **Index**: Vectors are stored in ChromaDB for semantic search 4. **Query**: User questions are embedded and matched against stored chunks 5. **Generate**: Top matching chunks are sent to Gemini LLM for answer generation 6. **Display**: Answer with confidence scores and source attribution --- ## ๐Ÿงช Testing See [TESTING_GUIDE.md](TESTING_GUIDE.md) for step-by-step instructions. --- ## ๐Ÿ‘จโ€๐Ÿ’ป Author **Made with โค๏ธ by Aditya** --- ## ๐Ÿ“„ License This project is open source and available for educational and research purposes.