A full-stack AI-powered PDF document assistant with semantic search, question answering, and document summarization.
- 📄 PDF Upload & Processing: Upload PDFs and automatically extract text
- 🔍 OCR Support: Automatic fallback to Tesseract OCR for scanned documents
- 🧠 Semantic Search: Find relevant information using AI embeddings
- 💬 Question Answering: Ask questions and get accurate answers with citations
- 📋 Document Summarization: Automatic generation of summaries and key points
- 🎯 Source Citations: Every answer includes page references and source information
- 🚀 Production-Ready: Clean architecture, proper error handling, and scalable design
- FastAPI: Modern Python web framework
- PyMuPDF: PDF text extraction
- Tesseract OCR: Scanned document processing
- Sentence Transformers: Embedding generation
- ChromaDB: Vector database for semantic search
- LangChain: LLM integration
- Groq API: Large language model (Mixtral 8x7B)
- Next.js: React framework
- TailwindCSS: Styling
- Axios: API client
- Lucide React: Icons
pdf-assistant/
├── backend/
│ ├── app.py # FastAPI application
│ ├── requirements.txt # Python dependencies
│ ├── .env.example # Environment variables template
│ ├── uploads/ # Uploaded PDFs
│ ├── chroma_db/ # Vector database
│ └── modules/
│ ├── parser.py # PDF text extraction
│ ├── chunker.py # Text chunking
│ ├── embeddings.py # Embedding generation
│ ├── qa.py # Question answering
│ └── summarizer.py # Document summarization
└── frontend/
├── package.json
├── pages/
│ └── index.tsx # Main application
├── components/
│ ├── FileUpload.tsx
│ ├── Summary.tsx
│ └── ChatInterface.tsx
├── lib/
│ └── api.ts # API client
└── styles/
└── globals.css
- Python 3.9+
- Node.js 16+
- Tesseract OCR (for scanned PDF support)
macOS:
brew install tesseractUbuntu/Debian:
sudo apt-get install tesseract-ocrWindows: Download from: https://github.com/UB-Mannheim/tesseract/wiki
- Navigate to backend directory:
cd pdf-assistant/backend- Create virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create
.envfile:
cp .env.example .env- Configure environment variables in
.env:
For Google Gemini:
GEMINI_API_KEY=your_gemini_api_key_here
LLM_PROVIDER=gemini
For OpenAI:
OPENAI_API_KEY=your_openai_api_key_here
LLM_PROVIDER=openai
- Run the backend:
python app.pyThe API will be available at http://localhost:8000
- Navigate to frontend directory:
cd pdf-assistant/frontend- Install dependencies:
npm install- Create
.env.localfile:
cp .env.example .env.local- Run the development server:
npm run devThe application will be available at http://localhost:3000
POST /upload
Content-Type: multipart/form-data
Response:
{
"document_id": "string",
"filename": "string",
"pages": number,
"chunks": number,
"summary": {
"summary": "string",
"key_points": ["string"],
"main_topics": ["string"],
"success": boolean
},
"success": boolean
}
POST /ask
Content-Type: application/json
Request:
{
"document_id": "string",
"question": "string"
}
Response:
{
"answer": "string",
"citations": [
{
"source_id": number,
"page_number": number,
"chunk_id": "string"
}
],
"success": boolean
}
GET /summary/{document_id}
Response:
{
"summary": "string",
"key_points": ["string"],
"main_topics": ["string"],
"success": boolean
}
GET /documents
Response:
{
"documents": [
{
"document_id": "string",
"filename": "string",
"pages": number,
"chunks": number
}
]
}
DELETE /documents/{document_id}
Response:
{
"success": boolean,
"message": "string"
}
GET /health
Response:
{
"status": "healthy",
"llm_provider": "string",
"documents_loaded": number
}
- Upload: User uploads a PDF file
- Text Extraction: PyMuPDF extracts text from each page
- Scanned Detection: System detects if pages are scanned (low text content)
- OCR Fallback: Tesseract OCR processes scanned pages
- Text Cleaning: Extracted text is cleaned and normalized
- Chunking: Text is split into 500-character chunks with 100-character overlap
- Embedding: Chunks are converted to embeddings using sentence-transformers
- Storage: Embeddings are stored in ChromaDB for semantic search
- Summarization: LLM generates document summary and key points
- Query Embedding: User question is converted to embedding
- Semantic Search: Top 5 similar chunks are retrieved from ChromaDB
- Context Building: Retrieved chunks are formatted with citations
- LLM Processing: Question and context are sent to LLM
- Answer Generation: LLM generates grounded answer with source references
- Response: Answer with citations is returned to user
- Chunk Size: 500 characters
- Overlap: 100 characters
- Preserves page numbers and chunk IDs in metadata
- Model:
all-MiniLM-L6-v2(384-dimensional embeddings) - Provider: Sentence Transformers
- Storage: ChromaDB with cosine similarity
- Temperature: 0.3 (for consistent, grounded answers)
- Max Tokens: Default (varies by model)
- Providers: Google Gemini or OpenAI
- Only OCR pages with minimal extracted text (< 50 characters)
- Skips OCR for text-based PDFs to save processing time
- Embeddings are cached in ChromaDB
- Summaries are cached after generation
- Document metadata is stored in memory
- ChromaDB can be migrated to Pinecone for cloud deployment
- FastAPI supports async operations
- Frontend uses efficient React patterns
"GEMINI_API_KEY not set"
- Ensure
.envfile exists in backend directory - Check that
GEMINI_API_KEYis set correctly
"Tesseract not found"
- Install Tesseract OCR for your OS
- On macOS:
brew install tesseract
"ChromaDB connection error"
- Ensure
chroma_db/directory has write permissions - Check disk space availability
"Cannot connect to backend API"
- Ensure backend is running on
http://localhost:8000 - Check
NEXT_PUBLIC_API_URLin.env.local - Verify CORS is enabled in FastAPI
"PDF upload fails"
- Check file size (max 50MB)
- Ensure file is valid PDF
- Check backend logs for detailed error
- Support for multiple PDFs in single session
- Streaming responses for faster feedback
- Advanced filtering and search options
- User authentication and document management
- Export answers and summaries to PDF
- Multi-language support
- Custom embedding models
- Fine-tuned LLM models
- Document comparison features
- Batch processing
MIT
For issues and questions, please open an issue on GitHub.