A backend API that lets you upload PDF documents and chat with them using AI. Built with Retrieval-Augmented Generation (RAG), it extracts content from your PDFs, stores vector embeddings in Weaviate, and uses GPT-4o-mini via OpenRouter to answer your questions — strictly grounded in the document's content.
- 📤 PDF Upload & Storage — Upload PDFs directly to Supabase Storage with signed URL generation
- 🔍 Intelligent Text Extraction — Extracts and parses text from every page of the uploaded PDF using
pdfjs-dist - ✂️ Automatic Text Chunking — Splits extracted text into manageable chunks for accurate retrieval
- 🧠 Vector Embeddings — Generates semantic embeddings for each chunk using
openai/text-embedding-3-smallvia OpenRouter - 🗄️ Dual Storage — Stores embeddings and chunks in both Weaviate (vector search) and Supabase (relational metadata)
- 💬 Context-Aware Chat — Answers questions using only the retrieved context from the document; never hallucinates
- ⚡ Fast Similarity Search — Performs
nearVectorsearch in Weaviate filtered by document ID for precise, scoped retrieval
| Layer | Technology |
|---|---|
| Runtime | Node.js (ESM) |
| Framework | Express.js v5 |
| LLM & Embeddings | OpenRouter (GPT-4o-mini + text-embedding-3-small) |
| Vector Database | Weaviate Cloud |
| Storage & DB | Supabase (Storage + PostgreSQL) |
| PDF Parsing | pdfjs-dist, pdf-parse |
| File Upload | Multer (in-memory) |
- Node.js v18+
- A Supabase project with:
- A storage bucket named
pdfs - A
pdf_documentstable (for metadata) - A
pdf_chunkstable (for chunk storage)
- A storage bucket named
- A Weaviate Cloud instance with a
Documentcollection - An OpenRouter API key
git clone https://github.com/vardaansinghal17/RAG-CHAT-MODEL.git
cd rag-chat-model
npm installCreate a .env file in the root directory:
SUPABASE_URL=your_supabase_project_url
SUPABASE_SERVICE_ROLE_KEY=your_supabase_service_role_key
OPENROUTER_API_KEY=your_openrouter_api_key
WEAVIATE_API_KEY=your_weaviate_api_key
WEAVIATE_URL=your_weaviate_cluster_url# Development (with hot reload)
npm run dev
# Production
npm startServer starts on http://localhost:3000
Uploads a PDF, extracts its text, generates embeddings, and indexes it for chat.
POST /upload
Content-Type: multipart/form-data
pdf: <your-pdf-file>Response:
{
"message": "PDF uploaded & indexed successfully",
"pdfId": "uuid-of-the-document"
}Ask a question about a previously uploaded PDF.
POST /chat
Content-Type: application/json
{
"question": "What is the main topic of this document?",
"pdfId": "uuid-of-the-document"
}Response:
{
"answer": "The document discusses..."
}Note: The model will only answer based on the document's content. If the answer is not found in the context, it will say so.
Upload Flow:
PDF File → Supabase Storage → Text Extraction (pdfjs-dist)
→ Chunking (500 chars) → Embeddings (OpenRouter)
→ Weaviate (vector store) + Supabase (chunk metadata)
Chat Flow:
Question → Embedding → Weaviate nearVector Search (top 3 chunks)
→ Context Assembly → GPT-4o-mini → Answer
| Command | Description |
|---|---|
npm run dev |
Start development server with nodemon |
npm start |
Start production server |
This project is licensed under the ISC License.