An intelligent chatbot that lets you upload any PDF and have a real conversation with it β powered by RAG (Retrieval-Augmented Generation), Pinecone Vector DB, and multiple switchable LLM models via OpenRouter.
Tech Stack NestJS Pinecone OpenRouter
image ---- π PDF Upload β Drag & drop any PDF (up to 20MB)
- π§ RAG Pipeline β PDF is chunked, embedded, and stored in Pinecone vector database
- π¬ Real-time Streaming β Answers stream token by token like ChatGPT
- π Dynamic Model Switching β Choose between multiple free LLM models (Nemotron, Gemma, GPT-OSS) directly from the chat UI in real-time
- π― Context-Aware β Answers strictly based on uploaded document
- π« Out-of-Scope Detection β Politely rejects questions unrelated to the PDF
- π± Fully Responsive β Works on mobile, tablet, and desktop
- π Premium Dark UI β Clean, modern interface built with Tailwind CSS
User uploads PDF
β
NestJS Backend receives file
β
pdf-parse extracts text
β
Text split into chunks (1000 tokens, 200 overlap)
β
multilingual-e5-large embeds each chunk (1024-dim)
β
Pinecone stores all vectors (unique namespace per PDF)
β
User asks a question
β
Question embedded β Pinecone similarity search (Top 4 chunks)
β
Context + Question sent to selected LLM via OpenRouter
β
Answer streams back to frontend in real-time (SSE)
| Layer | Technology |
|---|---|
| Frontend | Next.js 14, TypeScript, Tailwind CSS |
| Backend | NestJS, TypeScript |
| AI / LLM | Google Gemma (via OpenRouter) |
| Embeddings | multilingual-e5-large (Xenova/Transformers.js) |
| Vector DB | Pinecone |
| PDF Parsing | pdf-parse |
| Streaming | Server-Sent Events (SSE) |
pdf-rag-chatbot/
βββ frontend/ # Next.js App
β βββ app/
β β βββ page.tsx # Home "/"
β β βββ upload/page.tsx # Upload PDF "/upload"
β β βββ chat/[namespace]/ # Chat "/chat/:id"
β βββ components/
β β βββ chat/ # ChatWindow, MessageBubble, Input
β β βββ pdf/ # PDFUploader
β β βββ ui/ # Sidebar
β βββ hooks/ # useChat, usePDFUpload
β
βββ backend/ # NestJS API
βββ src/
βββ modules/
β βββ pdf/ # PDF upload & processing
β βββ chat/ # RAG query & SSE streaming
βββ services/
βββ langchain/ # RAG pipeline & embeddings
βββ pinecone/ # Vector DB operations
βββ gemini/ # LLM integration
- Node.js 18+
- Pinecone account (free tier)
- OpenRouter account (free tier)
git clone https://github.com/razazaheer12/pdf-rag-chatbot.git
cd pdf-rag-chatbotcd backend
npm installCreate .env file in backend/ folder:
PORT=5000 GEMINI_API_KEY=your_openrouter_api_key PINECONE_API_KEY=your_pinecone_api_key PINECONE_INDEX_NAME=pdf-rag-index-v2 PINECONE_DIMENSION=1024 NODE_ENV=development
npm run start:dev
cd frontend
npm installCreate .env.local file in frontend/ folder:
NEXT_PUBLIC_API_URL=http://localhost:5000
npm run dev
http://localhost:3000
- Upload β User uploads a PDF on
/uploadpage - Processing β Backend parses, chunks, and embeds the PDF into Pinecone
- Chat β User is redirected to
/chat/[namespace]page - Model Selection β User picks an LLM model from the dropdown (switchable anytime)
- Query β User asks a question; backend retrieves top 4 relevant chunks
- Answer β Selected LLM generates a context-aware answer, streamed in real-time
imageπ Home Page
imageπ€ Upload Page
image㪠Chat Page
| Variable | Description |
|---|---|
PORT |
Backend server port (default: 5000) |
GEMINI_API_KEY |
OpenRouter API key |
PINECONE_API_KEY |
Pinecone database API key |
PINECONE_INDEX_NAME |
Pinecone index name |
PINECONE_DIMENSION |
Embedding dimensions (1024) |
NEXT_PUBLIC_API_URL |
Backend URL for frontend |
- Chunk Size: 1000 characters with 200 overlap
- Embedding Model:
multilingual-e5-large(1024 dimensions) - Similarity Search: Top-4 chunks retrieved per query
- Similarity Threshold: Score > 0.4 filtered
- LLM Models (switchable via UI):
nvidia/nemotron-3-nano-30b-a3b:free(Fast)google/gemma-4-31b-it:freeopenai/gpt-oss-20b:freenvidia/nemotron-3-super-120b-a12b:free(Large)nvidia/nemotron-3-ultra-550b-a55b:free(Most Powerful)
- Streaming: Server-Sent Events (SSE) for real-time token streaming
Raza Zaheer
- π Portfolio: raza-zaheer-portfolio-web-developer.vercel.app
- πΌ GitHub: @razazaheer12
This project is open source and available under the MIT License.
β If you found this project helpful, please give it a star on GitHub!