A full-stack Retrieval-Augmented Generation (RAG) chatbot application built with modern web technologies. This project combines a powerful Express backend with vector search capabilities and a beautiful Progressive Web App (PWA) frontend for an intelligent chat experience.
- Overview
- Architecture
- Backend Technologies
- Frontend Technologies
- Features
- Project Structure
- Getting Started
- Environment Setup
- API Documentation
- Deployment
- Contributing
This RAG chatbot uses vector embeddings and semantic search to retrieve relevant information from a knowledge base (news articles) and provide intelligent responses. The system combines:
- Vector Search: Qdrant vector database for semantic similarity search
- Embeddings: HuggingFace models for text-to-vector conversion
- LLM Integration: Google Gemini AI for response generation
- Session Management: Redis for persistent chat sessions
- Modern UI: React PWA with smooth animations and offline support
โโโโโโโโโโโโโโโโโโโ
โ React Frontend โ
โ (PWA + TS) โ
โโโโโโโโโโฌโโโโโโโโโ
โ HTTP/REST
โผ
โโโโโโโโโโโโโโโโโโโ
โ Express Server โ
โ (Node.js) โ
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโดโโโโโฌโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โผ โผ โผ โผ
โโโโโโโโโ โโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ Redis โ โQdrant โ โHuggingFaceโ โ Gemini โ
โSessionโ โVector โ โEmbeddings โ โ LLM โ
โ DB โ โ DB โ โ Service โ โ API โ
โโโโโโโโโ โโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
Flow:
- User sends message โ Frontend
- Frontend โ Backend API
- Backend generates embedding (HuggingFace)
- Backend queries Qdrant for relevant chunks
- Backend uses Gemini to generate response with context
- Backend stores conversation in Redis
- Response โ Frontend โ User
- Node.js - JavaScript runtime
- Express.js 5.2.1 - Web application framework
- JavaScript (ES Modules) - Modern JavaScript syntax
- @google/generative-ai (0.24.1) - Google Gemini LLM integration
- @huggingface/inference (4.13.7) - Text embedding generation
- @qdrant/js-client-rest (1.16.2) - Vector database client
- Redis (5.10.0) - Session management and caching
- Qdrant Cloud - Vector database (cloud-hosted)
- Axios (1.13.2) - HTTP client for API requests
- Cheerio (1.1.2) - Web scraping (for news ingestion)
- dotenv (17.2.3) - Environment variable management
- CORS (2.8.5) - Cross-Origin Resource Sharing
- body-parser (2.2.2) - Request body parsing
rag-backend/
โโโ src/
โ โโโ routes/ # API route handlers
โ โโโ services/ # Business logic (Redis, Qdrant, HuggingFace, Gemini)
โ โโโ scripts/ # One-time scripts (data ingestion)
โ โโโ utils/ # Helper functions
โ โโโ server.js # Main server entry point
โโโ data/ # Ingested data (news articles)
โโโ package.json
- React 19.2.0 - UI library with latest features
- TypeScript 5.9.3 - Type-safe JavaScript
- Vite 7.2.4 - Lightning-fast build tool and dev server
- SCSS/Sass (1.97.2) - Enhanced CSS with variables and nesting
- Framer Motion (12.26.2) - Smooth animations and transitions
- CSS Modules - Scoped component styling
- Axios (1.13.2) - HTTP client with interceptors
- UUID (13.0.0) - Session ID generation
- Custom Hooks - React hooks for chat history, auto-scroll, sessions
- vite-plugin-pwa (1.2.0) - Progressive Web App capabilities
- Service Workers - Offline support and caching
- Web Manifest - Installable app configuration
- ESLint (9.39.1) - Code linting
- TypeScript ESLint (8.46.4) - TypeScript-specific linting
- @vitejs/plugin-react-swc (4.2.2) - Fast React refresh
rag-frontend/
โโโ src/
โ โโโ api/ # API client and endpoints
โ โโโ components/ # Reusable UI components
โ โโโ hooks/ # Custom React hooks
โ โโโ pages/ # Page-level components
โ โโโ styles/ # Global styles and variables
โ โโโ types/ # TypeScript definitions
โ โโโ utils/ # Helper functions
โ โโโ App.tsx # Main app component
โ โโโ main.tsx # Entry point
โโโ public/ # Static assets (PWA icons)
โโโ package.json
- โ Vector Search - Semantic similarity search using embeddings
- โ Session Management - Persistent chat sessions with Redis
- โ Context Retrieval - Top 3 relevant chunks for each query
- โ AI Response Generation - LLM-powered answers with context
- โ RESTful API - Clean, documented endpoints
- โ Error Handling - Comprehensive error responses
- โ Data Ingestion - Scripts for loading knowledge base
- โ Health Checks - Server and service status monitoring
- ๐ฌ Real-time Chat - Smooth, responsive messaging interface
- ๐ Session Persistence - Chat history across page refreshes
- ๐ฑ Progressive Web App - Installable on mobile and desktop
- ๐จ Modern UI/UX - Dark theme with glassmorphism effects
- โก Smooth Animations - Framer Motion powered transitions
- ๐ Offline Support - Service worker with offline fallback
- ๐ฑ Fully Responsive - Mobile, tablet, and desktop optimized
- ๐ฏ Type Safety - End-to-end TypeScript coverage
- ๐ Session Reset - Clear chat with confirmation dialog
rag-project-chat-bot/
โโโ rag-backend/ # Backend server
โ โโโ src/
โ โ โโโ routes/ # API endpoints
โ โ โ โโโ chat.js # Chat routes
โ โ โโโ services/
โ โ โ โโโ redis.js # Session management
โ โ โ โโโ qdrant.js # Vector DB operations
โ โ โ โโโ embedding.js # HuggingFace integration
โ โ โ โโโ gemini.js # Google Gemini LLM
โ โ โโโ scripts/
โ โ โ โโโ fetchNews.js # News scraping
โ โ โ โโโ ingestVectors.js # Vector ingestion
โ โ โโโ utils/
โ โ โ โโโ chunking.js # Text chunking utility
โ โ โโโ server.js # Express server
โ โโโ data/ # Knowledge base
โ โโโ .env # Environment variables
โ โโโ package.json
โ
โโโ rag-frontend/ # React frontend
โ โโโ src/
โ โ โโโ api/ # API integration
โ โ โ โโโ client.ts # Axios instance
โ โ โ โโโ chat.ts # Chat API methods
โ โ โโโ components/ # UI components
โ โ โ โโโ ChatInput/
โ โ โ โโโ ChatMessage/
โ โ โ โโโ EmptyState/
โ โ โ โโโ ErrorBoundary/
โ โ โ โโโ Header/
โ โ โ โโโ TypingIndicator/
โ โ โโโ hooks/ # Custom hooks
โ โ โ โโโ useAutoScroll.ts
โ โ โ โโโ useChatHistory.ts
โ โ โ โโโ useSession.ts
โ โ โโโ pages/
โ โ โ โโโ Chat/ # Main chat page
โ โ โโโ styles/ # Global styles
โ โ โโโ types/ # TypeScript types
โ โ โโโ utils/ # Utilities
โ โ โโโ App.tsx
โ โ โโโ main.tsx
โ โโโ public/ # PWA assets
โ โโโ .env # Frontend config
โ โโโ package.json
โ
โโโ README.md # This file
- Node.js 18+ and npm
- Redis instance (local or cloud)
- Qdrant Cloud account (or local Qdrant)
- API Keys:
- HuggingFace API token
- Google Gemini API key
git clone <repository-url>
cd rag-project-chat-botcd rag-backend
npm installCreate .env file:
# Server
PORT=3000
# Redis
REDIS_URL=redis://default:password@redis-cloud-url:port
# Qdrant Vector DB
QDRANT_URL=https://your-cluster.qdrant.io
QDRANT_API_KEY=your_qdrant_api_key
# HuggingFace
HUGGINGFACE_API_TOKEN=your_huggingface_token
# Google Gemini
GEMINI_API_KEY=your_gemini_api_key
# Session
REDIS_SESSION_TTL=1800 # 30 minutesIngest Data:
# Optional: Fetch news articles (one-time)
node src/scripts/fetchNews.js
# Ingest vectors into Qdrant
node src/scripts/ingestVectors.jsStart Backend:
npm start # Production
npm run dev # Development (auto-reload)Server runs at http://localhost:3000
cd rag-frontend
npm installCreate .env file:
VITE_API_BASE_URL=http://localhost:3000Start Frontend:
npm run dev # Development serverApp runs at http://localhost:5173
| Variable | Required | Description |
|---|---|---|
PORT |
No | Server port (default: 3000) |
REDIS_URL |
Yes | Redis connection string |
QDRANT_URL |
Yes | Qdrant cloud/local URL |
QDRANT_API_KEY |
Yes | Qdrant authentication key |
HUGGINGFACE_API_TOKEN |
Yes | HuggingFace API token |
GEMINI_API_KEY |
Yes | Google Gemini API key |
REDIS_SESSION_TTL |
No | Session expiry in seconds (def: 1800) |
| Variable | Required | Description |
|---|---|---|
VITE_API_BASE_URL |
No | Backend URL (def: localhost:3000) |
GET /healthResponse:
{
"status": "ok",
"timestamp": "2026-01-15T12:00:00.000Z",
"service": "RAG Chat API",
"redis": "connected"
}POST /api/chat
Content-Type: application/jsonRequest Body:
{
"sessionId": "uuid-string",
"message": "What are the latest news about AI?"
}Response:
{
"success": true,
"sessionId": "uuid-string",
"userMessage": "What are the latest news about AI?",
"retrievedChunks": [
{
"score": 0.85,
"text": "Article content...",
"title": "Article Title",
"url": "https://...",
"metadata": { ... }
}
],
"message": "Query processed successfully"
}GET /api/history/:sessionIdResponse:
{
"success": true,
"sessionId": "uuid-string",
"messages": [
{
"role": "user",
"content": "Your question",
"timestamp": "2026-01-15T12:00:00.000Z"
},
{
"role": "assistant",
"content": "{\"retrievedChunks\": [...]}",
"timestamp": "2026-01-15T12:00:01.000Z"
}
],
"messageCount": 2,
"ttl": 1799,
"ttlMinutes": 30
}DELETE /api/session/:sessionIdResponse:
{
"success": true,
"sessionId": "uuid-string",
"message": "Session cleared successfully"
}cd rag-backend
# Health check
curl http://localhost:3000/health
# Send message
curl -X POST http://localhost:3000/api/chat \
-H "Content-Type: application/json" \
-d '{"sessionId": "test-123", "message": "Tell me about AI"}'
# Get history
curl http://localhost:3000/api/history/test-123
# Clear session
curl -X DELETE http://localhost:3000/api/session/test-123See API_TESTING.md for detailed testing guide.
cd rag-frontend
# Development
npm run dev
# Production build test
npm run build
npm run previewDesktop (Chrome/Edge):
- Click install icon in address bar
- Or browser menu โ "Install RAG Chatbot"
Mobile (iOS/Android):
- Open share menu
- Select "Add to Home Screen"
- ๐ฆ Offline asset caching
- ๐ Background sync
- ๐ฒ Installable app
- ๐จ Themed splash screen
- โก Fast loading
Redis connection failed:
- Verify
REDIS_URLin.env - Check Redis Cloud dashboard
- Test connection:
redis-cli ping
Qdrant query failed:
- Confirm vectors are ingested:
node src/scripts/ingestVectors.js - Verify
QDRANT_URLandQDRANT_API_KEY
HuggingFace 429 errors:
- Rate limit exceeded
- Wait or upgrade HuggingFace plan
Cannot connect to server:
- Ensure backend is running
- Check
VITE_API_BASE_URLin.env - Verify CORS is enabled
Session not persisting:
- Check browser localStorage
- Disable blocking extensions
- Clear browser cache
Recommended Platforms:
- Railway
- Render
- Heroku
- DigitalOcean App Platform
Environment:
- Set all
.envvariables - Use Redis cloud (not local)
- Qdrant Cloud recommended
Recommended Platforms:
- Vercel
- Netlify
- Cloudflare Pages
Build Command: npm run build
Output Directory: dist
Update .env for production:
VITE_API_BASE_URL=https://your-backend-url.com- User authentication & authorization
- Multi-user chat rooms
- File upload for knowledge base
- Voice input/output
- Conversation export (PDF/JSON)
- Admin dashboard for analytics
- Multi-language support
- Dark/light theme toggle
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
This project is part of a Full Stack RAG Chatbot assignment.
- Google Gemini - LLM API
- HuggingFace - Embedding models
- Qdrant - Vector database
- Redis Labs - Session storage
- Vite - Fast build tooling
- Framer Motion - Animation library
For questions or support, please open an issue in the repository.
Built with โค๏ธ using Node.js, Express, React, TypeScript, and bleeding-edge AI technologies