ChatPDF Backend
AI-powered PDF chat backend built with Node.js, Express.js, Gemini AI, Qdrant Vector DB, Prisma, PostgreSQL, and Cloudinary.
This backend allows users to:
- Upload PDFs
- Parse and chunk PDF content
- Generate embeddings using Gemini
- Store vectors in Qdrant
- Perform semantic search (RAG)
- Chat with PDFs using AI
- Persist chat history
- Authenticate users using Clerk
---
Tech Stack
- Node.js
- Express.js
- PostgreSQL
- Prisma ORM
- Google Gemini AI
- Qdrant Vector Database
- Cloudinary
- Clerk Authentication
- Multer
- pdf-parse-new
- Rate Limiting + Security Middleware
---
Features
Authentication
- Clerk JWT authentication
- Protected API routes
- User-specific PDFs and chats
PDF Upload Pipeline
- Upload PDF files
- Store files in Cloudinary
- Extract PDF text
- Chunk text intelligently
- Generate embeddings
- Store vectors in Qdrant
AI Chat System
- Retrieval-Augmented Generation (RAG)
- Semantic search over PDF chunks
- Gemini-powered responses
- Citation support
- Persistent chat history
Security
- Helmet
- Rate limiting
- CORS protection
- Secure cookies
- Request validation
---
Project Structure
```bash
src
├── config
├── controllers
├── middlewares
├── routes
├── services
├── scripts
├── utils
├── app.js
└── server.jsCreate a .env file:
PORT=8000
DATABASE_URL=
FRONTEND_URL=
CLERK_SECRET_KEY=
CLERK_PUBLISHABLE_KEY=
GEMINI_API_KEY=
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
QDRANT_URL=
QDRANT_API_KEY=git clone <repo-url>
cd chatpdf-backend
npm installnpx prisma generate
npx prisma migrate devnpm run devnpm startGET /GET /test-dbPOST /api/v1/upload/pdfpdf: FilePOST /api/v1/chat/ask{
"pdfId": "pdf_id",
"question": "Explain this PDF"
}PDF Upload
↓
PDF Parsing
↓
Chunking
↓
Embedding Generation
↓
Store Vectors in Qdrant
↓
Semantic Retrieval
↓
Gemini AI Response- Streaming AI responses
- Multi-PDF chat
- PDF page preview
- OCR support
- LangChain integration
- Background processing queues
- Redis caching
- Conversation memory
Saptarshi Dey


