Skip to content

RAG-powered document analysis system with React frontend and FastAPI backend

Notifications You must be signed in to change notification settings

Emart29/rag-document-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ RAG Document Analyzer

A production-ready Retrieval-Augmented Generation (RAG) system for intelligent document question-answering, powered by Groq’s ultra-fast LLM inference.

πŸŽ₯ Live Demo: https://rag-document-analyzer.vercel.app
πŸ“– API Docs (Swagger): https://rag-document-analyzer.onrender.com/docs
πŸ› Report Bug: https://github.com/Emart29/rag-document-analyzer/issues

Live Demo API Docs License


✨ Overview

RAG Document Analyzer allows users to upload PDF documents and ask natural-language questions while receiving accurate, source-cited answers.
It combines semantic search + LLM reasoning for fast, reliable document intelligence.

Built with:

  • React + Vite (Frontend)
  • FastAPI (Backend)
  • Groq (Llama 3.1 70B) for lightning-fast inference
  • ChromaDB for vector similarity search

✨ Features

🎯 Core Capabilities

  • πŸ“„ PDF Document Processing: Upload and process PDFs with intelligent text chunking
  • 🧠 AI-Powered Q&A: Ask natural language questions and get accurate answers
  • πŸ” Semantic Search: Vector-based similarity search using ChromaDB
  • πŸ“š Source Citations: Every answer includes relevant document excerpts with page numbers
  • πŸ’¬ Conversation History: Maintains context across multiple questions
  • ⚑ Lightning Fast: Powered by Groq's ultra-fast LLM inference (500+ tokens/sec)

🎨 Modern UI/UX

  • Beautiful React Interface: Built with Vite, TailwindCSS, and shadcn/ui
  • Responsive Design: Works seamlessly across devices
  • Real-time Updates: Live upload progress and query processing
  • Dark Mode Support: Eye-friendly interface (if implemented)
  • Drag & Drop: Intuitive document upload experience

πŸ› οΈ Technical Excellence

  • Production-Ready: Comprehensive error handling and validation
  • Scalable Architecture: Modular, maintainable codebase
  • API Documentation: Auto-generated Swagger/OpenAPI docs
  • Type Safety: Pydantic models for request/response validation
  • Performance Optimized: Efficient chunking, batching, and caching

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                     React Frontend (Vite)                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚
β”‚  β”‚  Document    β”‚  β”‚     Chat     β”‚  β”‚   Source     β”‚      β”‚
β”‚  β”‚   Upload     β”‚  β”‚  Interface   β”‚  β”‚  Citations   β”‚      β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚ REST API (Axios)
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    FastAPI Backend                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚              RAG Engine (Orchestrator)                β”‚   β”‚
β”‚  β””β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β”‚     β”‚            β”‚            β”‚            β”‚                β”‚
β”‚  β”Œβ”€β”€β–Όβ”€β”€β”€β”   β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”   β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”   β”Œβ”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”         β”‚
β”‚  β”‚ PDF  β”‚   β”‚ Groq  β”‚   β”‚Sentenceβ”‚   β”‚ Chroma  β”‚         β”‚
β”‚  β”‚Procesβ”‚   β”‚ API   β”‚   β”‚Transformβ”‚   β”‚   DB    β”‚         β”‚
β”‚  β”‚sor   β”‚   β”‚(LLM)  β”‚   β”‚ (Embed)β”‚   β”‚(Vector) β”‚         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸš€ Quick Start

Prerequisites

  • Python 3.8+
  • Node.js 18+
  • Groq API Key (Get free key)
  • 8GB RAM minimum
  • 2GB free disk space

Installation

1️⃣ Clone Repository

git clone https://github.com/Emart29/rag-document-analyzer.git
cd rag-document-analyzer

2️⃣ Setup Backend

# Navigate to backend
cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure environment
cp .env.example .env
# Edit .env and add your GROQ_API_KEY

# Start backend server
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000

Backend will start on: http://localhost:8000

API Documentation: http://localhost:8000/docs

3️⃣ Setup Frontend

# Open new terminal, navigate to frontend
cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

Frontend will start on: http://localhost:5173


πŸ“– Usage

Upload Documents

  1. Click the Upload tab in the sidebar
  2. Drag & drop a PDF or click Browse
  3. Wait for processing (10-30 seconds)
  4. Document appears in the Documents list

Ask Questions

  1. Select documents (optional - searches all if none selected)
  2. Type your question in the chat input
  3. Press Enter or click Send
  4. Get AI-generated answer with source citations in 2-3 seconds

Example Questions

"What are the main findings of this research?"
"Summarize the key points from page 5"
"Compare the methodologies discussed in the documents"
"What does the author say about machine learning?"

πŸ› οΈ Technology Stack

Frontend

Technology Purpose
React 18 UI framework
Vite Build tool & dev server
TailwindCSS Styling
shadcn/ui UI components
Tanstack Query Server state management
Axios HTTP client
React Markdown Answer rendering
Lucide React Icons

Backend

Technology Purpose
FastAPI REST API framework
Groq API LLM inference (Llama 3.1 70B)
ChromaDB Vector database
Sentence Transformers Text embeddings
PyPDF2 & pdfplumber PDF text extraction
Pydantic Data validation
Uvicorn ASGI server

πŸ“Š Performance Metrics

Tested on: Dell Latitude 5400 (i5-8th gen, 8GB RAM)

Operation Time Notes
Document Upload 10-30s 5-page PDF
Question Answering 1-3s Including retrieval & generation
Semantic Search <100ms ChromaDB query
Memory Usage ~600MB Backend runtime
LLM Inference 500+ tokens/sec Via Groq

🚒 Deployment

Frontend Deployment (Vercel) - FREE βœ…

# Install Vercel CLI
npm i -g vercel

# Navigate to frontend folder
cd frontend

# Deploy
vercel

# Follow prompts, set environment variable:
# VITE_API_URL=https://your-backend-url.onrender.com

Backend Deployment (Render.com) - FREE βœ…

  1. Create render.yaml in project root:
services:
  - type: web
    name: rag-backend
    env: python
    region: oregon
    plan: free
    buildCommand: |
      cd backend
      pip install -r requirements.txt
    startCommand: cd backend && uvicorn app.main:app --host 0.0.0.0 --port $PORT
    envVars:
      - key: GROQ_API_KEY
        sync: false
      - key: PYTHON_VERSION
        value: 3.11.0
  1. Push to GitHub
  2. Connect repo to Render.com
  3. Add GROQ_API_KEY environment variable
  4. Deploy!

Your app will be live at:

  • Frontend: https://your-app.vercel.app
  • Backend API: https://your-api.onrender.com

πŸ“ Project Structure

rag-document-analyzer/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ main.py              # FastAPI application
β”‚   β”‚   β”œβ”€β”€ models.py            # Pydantic models
β”‚   β”‚   β”œβ”€β”€ routers/             # API endpoints
β”‚   β”‚   β”‚   β”œβ”€β”€ documents.py     # Document operations
β”‚   β”‚   β”‚   β”œβ”€β”€ query.py         # Q&A endpoints
β”‚   β”‚   β”‚   └── system.py        # Health & stats
β”‚   β”‚   β”œβ”€β”€ services/            # Business logic
β”‚   β”‚   β”‚   β”œβ”€β”€ rag_engine.py    # RAG orchestration
β”‚   β”‚   β”‚   β”œβ”€β”€ groq_client.py   # LLM interface
β”‚   β”‚   β”‚   β”œβ”€β”€ embeddings.py    # Vector generation
β”‚   β”‚   β”‚   └── pdf_processor.py # Document processing
β”‚   β”‚   └── database/
β”‚   β”‚       └── chroma_db.py     # Vector database
β”‚   β”œβ”€β”€ requirements.txt
β”‚   β”œβ”€β”€ .env
β”‚   └── README.md
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/          # React components
β”‚   β”‚   β”‚   β”œβ”€β”€ Header.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ Sidebar.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ ChatInterface.jsx
β”‚   β”‚   β”‚   β”œβ”€β”€ DocumentList.jsx
β”‚   β”‚   β”‚   └── ui/              # shadcn components
β”‚   β”‚   β”œβ”€β”€ services/
β”‚   β”‚   β”‚   └── api.js           # API client
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   └── main.jsx
β”‚   β”œβ”€β”€ package.json
β”‚   β”œβ”€β”€ tailwind.config.js
β”‚   └── README.md
β”œβ”€β”€ README.md                    # This file
└── LICENSE

πŸ§ͺ Testing

Backend Tests

cd backend

# Test individual components
python app/services/groq_client.py
python app/services/embeddings.py
python app/database/chroma_db.py
python app/services/rag_engine.py

# API documentation
# Visit: http://localhost:8000/docs

Frontend Tests

cd frontend

# Run development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

πŸ”’ Security & Best Practices

  • βœ… Environment variables for sensitive data
  • βœ… Input validation with Pydantic
  • βœ… CORS configuration for frontend
  • βœ… File size and type validation
  • βœ… Error handling and logging
  • βœ… API rate limiting (recommended for production)
  • ⚠️ Add authentication for production use
  • ⚠️ Implement user management for multi-tenant

πŸ› Troubleshooting

Backend Issues

Issue: "GROQ_API_KEY not found"

# Solution: Check .env file
cat backend/.env  # Should show GROQ_API_KEY=gsk_...

Issue: ChromaDB errors

# Solution: Clear database and restart
rm -rf backend/chroma_db/
# Restart backend

Issue: PDF processing fails

# Solution: Install additional dependencies
pip install python-magic-bin  # Windows
pip install python-magic       # Mac/Linux

Frontend Issues

Issue: API connection refused

# Solution: Check VITE_API_URL in .env
# Verify backend is running on correct port

Issue: Build errors

# Solution: Clear cache and reinstall
rm -rf node_modules package-lock.json
npm install

🎯 Future Enhancements

  • Multi-format Support: Add .docx, .txt, .md support
  • User Authentication: JWT-based auth system
  • Multi-tenancy: Per-user document isolation
  • Advanced Filters: Filter by date, size, type
  • Export Conversations: Download chat history
  • Streaming Responses: Real-time token streaming
  • Voice Input: Speech-to-text for questions
  • Document Summarization: Auto-generate summaries
  • Collaborative Sharing: Share documents between users
  • Analytics Dashboard: Usage statistics and insights

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

Your Name


πŸ™ Acknowledgments


πŸ“Š Project Stats

GitHub stars GitHub forks GitHub issues GitHub pull requests


⭐ If this project helped you, please give it a star! ⭐

Made with ❀️ by Emmanuel Nwanguma

⬆ Back to Top

About

RAG-powered document analysis system with React frontend and FastAPI backend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published