An intelligent PDF chat application that allows you to upload PDF documents and have conversations about their content using AI. Built with Next.js 14, Google Gemini AI, and RAG (Retrieval-Augmented Generation) technology.
- PDF Upload & Processing: Upload PDFs with drag-and-drop interface
- AI-Powered Chat: Ask questions about your PDF content using Google Gemini
- Smart Citations: Get clickable page references that navigate directly to relevant PDF sections
- PDF Viewer: Built-in PDF viewer with zoom, rotation, and smooth page navigation
- Multi-Document Support: Manage and switch between multiple uploaded PDFs
- Persistent Storage: Documents and chat history survive server restarts
- Real-time Processing: Live progress updates during PDF ingestion
- Frontend: Next.js 14 (App Router), TypeScript, Tailwind CSS
- AI: Google Gemini (gemini-2.5-flash), Vercel AI SDK
- Vector Store: Pinecone for embeddings and similarity search
- Database: NeonDB (PostgreSQL) for metadata persistence
- File Storage: Vercel Blob for PDF file storage
- PDF Processing: LlamaParse for advanced text extraction
- PDF Viewing: react-pdf for in-browser PDF rendering
Before you begin, ensure you have:
- Node.js 18+ installed
- npm or yarn package manager
- The following API keys and services:
- Google AI Studio API key (for Gemini)
- LlamaCloud API key (for PDF parsing)
- Pinecone API key and index
- NeonDB database URL
- Vercel Blob store token
-
Clone the repository
git clone <your-repo-url> cd chat-pdf
-
Install dependencies
npm install
-
Set up environment variables
Create a
.env.localfile in the root directory:# Google AI (Gemini) GOOGLE_GENERATIVE_AI_API_KEY=your_google_ai_api_key_here # LlamaCloud (PDF Parsing) LLAMA_CLOUD_API_KEY=your_llamacloud_api_key_here # Pinecone (Vector Storage) PINECONE_API_KEY=your_pinecone_api_key_here PINECONE_INDEX=your_pinecone_index_name # NeonDB (PostgreSQL Database) DATABASE_URL=your_neondb_connection_string # Vercel Blob (File Storage) BLOB_READ_WRITE_TOKEN=your_vercel_blob_token
-
Set up the database
The application will automatically create the required tables on first run. The schema includes:
documentstable for PDF metadata- Automatic indexing for efficient queries
-
Configure Pinecone Index
Create a Pinecone index with these specifications:
- Dimension: 768 (matches Google's gemini-embedding-001 model)
- Metric: cosine
- Cloud: Any (AWS/GCP/Azure)
-
Start the development server
npm run dev
-
Open your browser
Navigate to http://localhost:3000
-
Upload your first PDF
- Click "Upload PDF" or drag and drop a PDF file
- Wait for processing to complete (parsing, embedding, indexing)
- Start chatting about your document!
- Single Upload: Click "Upload PDF" button or drag-drop a file
- Multiple Documents: Upload additional PDFs using the "+" button
- Processing Stages:
- Uploading (file transfer)
- Parsing (text extraction with LlamaParse)
- Embedding (converting text to vectors)
- Indexing (storing in Pinecone)
- Ask Questions: Type natural language questions about your PDF content
- Get Responses: Receive AI-generated answers with relevant context
- Follow Citations: Click citation buttons (e.g., "p.3") to jump to specific PDF pages
- Switch Documents: Use the dropdown to chat with different uploaded PDFs
- View All PDFs: Use the dropdown menu in the header
- Switch Active PDF: Select any PDF from the dropdown
- Delete PDFs: Click the "×" icon next to any PDF in the dropdown
- PDF Viewer Controls: Zoom in/out, rotate, and scroll through pages
| Variable | Description | Required |
|---|---|---|
GOOGLE_GENERATIVE_AI_API_KEY |
Google AI Studio API key for Gemini | ✅ |
LLAMA_CLOUD_API_KEY |
LlamaCloud API key for PDF parsing | ✅ |
PINECONE_API_KEY |
Pinecone API key for vector storage | ✅ |
PINECONE_INDEX |
Name of your Pinecone index | ✅ |
DATABASE_URL |
NeonDB PostgreSQL connection string | ✅ |
BLOB_READ_WRITE_TOKEN |
Vercel Blob storage token | ✅ |
The application includes built-in retry logic for:
- Google Gemini API (handles overload errors)
- LlamaCloud parsing (network timeouts)
- Pinecone operations (rate limiting)
POST /api/upload- Upload and process PDF filesGET /api/pdfs- List all uploaded PDFsDELETE /api/pdfs/[id]- Delete a specific PDFGET /api/doc/[id]/file- Serve PDF file contentGET /api/doc/[id]/status- Check processing statusPOST /api/chat- Handle chat interactionsGET /api/health- System health check
This project is licensed under the MIT License - see the LICENSE file for details.
- Vercel AI SDK for seamless AI integration
- LlamaIndex for PDF parsing capabilities
- Pinecone for vector database services
- Google AI for Gemini language model
- react-pdf for PDF viewing