📚 RAG Document-Based Chatbot
A powerful Retrieval-Augmented Generation (RAG) chatbot that allows users to upload PDF documents and ask intelligent questions about their content. Built with modern technologies for seamless document processing and conversational AI.
🚀 Features
- 📄 PDF Upload & Processing: Upload PDF documents for intelligent analysis
- 🤖 AI-Powered Chat: Ask questions and get accurate answers from your documents
- 🔍 Semantic Search: Advanced vector-based document retrieval using Qdrant
- 📚 Document Chunking: Smart text splitting for optimal context understanding
- 🎯 Source Citations: See exactly which pages and documents your answers come from
- ⚡ Real-time Processing: Background job processing with Redis and BullMQ
- 🎨 Modern UI: Clean, responsive interface built with Next.js and Tailwind CSS
🏗️ Architecture
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Next.js UI │ -> │ Express API │ -> │ Vector DB │
│ (Frontend) │ │ (Backend) │ │ (Qdrant) │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ Job Queue │
│ (Redis+BullMQ) │
└─────────────────┘
🛠️ Tech Stack
Frontend
- Next.js 15.4.3 - React framework with Turbopack
- TypeScript - Type-safe development
- Tailwind CSS - Utility-first CSS framework
- shadcn/ui - Modern UI components
- Clerk - Authentication (optional)
Backend
- Express.js 5.1.0 - Web framework
- Multer - File upload handling
- LangChain - Document processing and AI orchestration
- Qdrant - Vector database for embeddings
- Redis + BullMQ - Job queue for background processing
AI & ML
- HuggingFace Transformers - Text embeddings (all-MiniLM-L6-v2)
- OpenAI Embeddings - Alternative embedding model
- PDF Loader - Document parsing and text extraction
📦 Installation
Prerequisites
- Node.js 18+ and npm
- Redis server
- Qdrant vector database
1. Clone the Repository
git clone <repository-url>
cd "Document Based Chatbot"
2. Setup Backend
cd server
npm install
# Create environment file
echo "QDRANT_URL=http://localhost:6333" > .env
echo "OPENAI_API_KEY=your_openai_api_key" >> .env
3. Setup Frontend
cd ../client
npm install
4. Start Services
Start Redis:
# Windows (if using Redis on Windows)
redis-server
# MacOS/Linux
brew services start redis
# or
sudo systemctl start redis
Start Qdrant:
# Using Docker
docker run -p 6333:6333 qdrant/qdrant
# Or visit: http://localhost:6333/dashboard
5. Run the Application
Backend:
cd server
npm run dev
Frontend:
cd client
npm run dev
Visit http://localhost:3000 to access the application!
🎯 Usage
1. Upload Documents
- Navigate to the upload page
- Select PDF files to upload
- Files are automatically processed in the background
2. Chat with Your Documents
- Go to the chat interface
- Ask questions about your uploaded documents
- Get AI-powered answers with source citations
Example Queries:
- "What are the main themes in this book?"
- "Summarize chapter 3"
- "What does the author say about habit formation?"
🔧 Configuration
Environment Variables
Server (.env):
QDRANT_URL=http://localhost:6333
OPENAI_API_KEY=your_openai_api_key_here
REDIS_HOST=localhost
REDIS_PORT=6379
Embedding Models
The project supports multiple embedding models:
// HuggingFace (Local, Free)
const embeddings = new HuggingFaceTransformersEmbeddings({
modelName: "Xenova/all-MiniLM-L6-v2",
});
// OpenAI (API-based, Paid)
const embeddings = new OpenAIEmbeddings({
apiKey: process.env.OPENAI_API_KEY,
model: "text-embedding-3-small",
});
📁 Project Structure
Document Based Chatbot/
├── client/ # Next.js frontend
│ ├── app/
│ │ ├── components/ # React components
│ │ │ ├── chat.tsx # Chat interface
│ │ │ └── file-upload.tsx
│ │ ├── globals.css # Global styles
│ │ ├── layout.tsx # App layout
│ │ └── page.tsx # Home page
│ ├── package.json
│ └── tailwind.config.js
├── server/ # Express.js backend
│ ├── uploads/ # Uploaded files storage
│ ├── index.js # Main server file
│ ├── worker.js # Background job processor
│ └── package.json
└── README.md
🔄 How It Works
- Document Upload: User uploads PDF files via the frontend
- File Processing: Multer saves files to
/uploadsdirectory - Background Processing: BullMQ queues the document for processing
- Text Extraction: PDF content is extracted using LangChain's PDFLoader
- Text Chunking: Documents are split into smaller, manageable chunks
- Embedding Generation: Each chunk is converted to vector embeddings
- Vector Storage: Embeddings are stored in Qdrant vector database
- Query Processing: User questions are embedded and matched against stored vectors
- Response Generation: Relevant chunks are retrieved and used to generate contextual answers
🐛 Troubleshooting
Common Issues
1. "Collection doesn't exist" error:
// Use fromDocuments instead of fromExistingCollection
const vectorStore = await QdrantVectorStore.fromDocuments(
texts,
embeddings,
config
);
2. ES Module warnings: Add to server/package.json:
{
"type": "module"
}
3. Redis connection issues:
# Check if Redis is running
redis-cli ping
# Should return: PONG
4. Qdrant connection issues:
# Check Qdrant dashboard
curl http://localhost:6333/collections
🚀 Deployment
Using Docker Compose
version: "3.8"
services:
redis:
image: redis:alpine
ports:
- "6379:6379"
qdrant:
image: qdrant/qdrant
ports:
- "6333:6333"
app:
build: .
ports:
- "3000:3000"
- "8000:8000"
depends_on:
- redis
- qdrant
🤝 Contributing
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🙏 Acknowledgments
- LangChain for document processing utilities
- Qdrant for vector database capabilities
- HuggingFace for transformer models
- shadcn/ui for beautiful UI components
📞 Support
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Search existing Issues
- Create a new issue with detailed information
Happy chatting with your documents! 📚🤖
Log in or sign up for Devpost to join the conversation.