Skip to content

Navigation Menu

Sign in
Sign up

Latest commit

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

πŸ€– PDF RAG Chatbot

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 ---

✨ Features

  • πŸ“„ 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

πŸ—οΈ Architecture

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)
image

πŸ› οΈ Tech Stack

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)

πŸ“ Project Structure

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

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • Pinecone account (free tier)
  • OpenRouter account (free tier)

1️⃣ Clone the Repository

git clone https://github.com/razazaheer12/pdf-rag-chatbot.git
cd pdf-rag-chatbot

2️⃣ Backend Setup

cd backend
npm install

Create .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

3️⃣ Frontend Setup

cd frontend
npm install

Create .env.local file in frontend/ folder:

NEXT_PUBLIC_API_URL=http://localhost:5000
npm run dev

4️⃣ Open in Browser

http://localhost:3000

πŸ”„ How It Works

  1. Upload β€” User uploads a PDF on /upload page
  2. Processing β€” Backend parses, chunks, and embeds the PDF into Pinecone
  3. Chat β€” User is redirected to /chat/[namespace] page
  4. Model Selection β€” User picks an LLM model from the dropdown (switchable anytime)
  5. Query β€” User asks a question; backend retrieves top 4 relevant chunks
  6. Answer β€” Selected LLM generates a context-aware answer, streamed in real-time

πŸ“Έ Screenshots

🏠 Home Page

image

πŸ“€ Upload Page

image

πŸ’¬ Chat Page

image

βš™οΈ Environment Variables

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

🧠 RAG Pipeline Details

  • 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:free
    • openai/gpt-oss-20b:free
    • nvidia/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

πŸ‘¨β€πŸ’» Author

Raza Zaheer


πŸ“„ License

This project is open source and available under the MIT License.


⭐ If you found this project helpful, please give it a star on GitHub!

About

An AI-powered chatbot that lets you upload any PDF and ask questions about it in natural language. Built with NestJS, Next.js, and a RAG pipeline using Pinecone vector database featuring real-time streaming responses, dynamic switching between multiple LLM models, and context-aware answers.

Topics

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

AltStyle γ«γ‚ˆγ£γ¦ε€‰ζ›γ•γ‚ŒγŸγƒšγƒΌγ‚Έ (->γ‚ͺγƒͺγ‚ΈγƒŠγƒ«) /