A Retrieval-Augmented Generation (RAG) powered WhatsApp AI Assistant
An AI-powered WhatsApp customer support assistant built with NestJS and RAG. It maintains a persistent WhatsApp Web session, ingests your knowledge base into vector embeddings, and uses context-aware generation to answer customer queries intelligently via WhatsApp.
Retrieval-Augmented Generation (RAG) is an AI architecture that combines information retrieval with text generation to produce accurate, grounded responses. Instead of relying solely on the LLM's training data, RAG retrieves relevant documents from your knowledge base at query time and feeds them as context to the model.
βββββββββββββββββββ RAG Pipeline βββββββββββββββββββ
β β
β 1. RETRIEVE β
β User query β Embed β Vector search β
β Find the most relevant knowledge chunks β
β β
β 2. AUGMENT β
β Inject retrieved context into the prompt β
β "Answer using ONLY this information..." β
β β
β 3. GENERATE β
β LLM produces a grounded, cited response β
β based on actual knowledge base data β
β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββ
Why RAG over fine-tuning?
- No model retraining needed β just upload documents
- Always up-to-date β add/remove knowledge at any time
- Transparent β responses cite exact sources
- Cost-effective β works with any LLM (GPT-4o-mini, Claude, etc.)
Built for SetNGo Holidays β adaptable to any business.
Disclaimer: This project uses only publicly available data from the SetNGo Holidays website as a demonstration example. It is not an official product of SetNGo Holidays. The system prompt and knowledge base can be replaced with any business's data to build a similar AI assistant.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β WhatsApp (Customer) β
ββββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β
ββββββββββββββΌβββββββββββββ
β WA Channel Module β
β (whatsapp-web.js) β
ββββββββββββββ¬βββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββ
β RAG Pipeline β
β β
β ββββββββββββ βββββββββββββββββ β
β β Embedding ββ β Vector Search β β
β β (OpenAI) β β (MongoDB) β β
β ββββββββββββ βββββββββ¬ββββββββ β
β β β
β βββββββββββββββββββββββΌββββββββ β
β β LLM (GPT-4o-mini) β β
β β + Retrieved Context β β
β βββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββΌβββββββββββββββββββ
β MongoDB Atlas β
β ββββββββββββββ βββββββββββββββββ β
β β Chunks + β β Conversations β β
β β Embeddings β β & Tickets β β
β ββββββββββββββ βββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββ
- RAG-powered responses β answers grounded in your uploaded knowledge base with source citations
- WhatsApp integration β persistent headless session via Puppeteer, QR-based auth, typing indicators
- Document ingestion β upload PDF, TXT, CSV, or Markdown; auto-chunked and embedded
- MongoDB Atlas Vector Search β native similarity search with cosine fallback for local dev
- Automated ticket system β AI creates support tickets when it can't resolve issues
- Conversation logging β full audit trail of every exchange with retrieved context and token usage
- Greets first-time customers automatically
- Answers from knowledge base with source citations
- Raises tickets: complaints, cancellations, update requests, callback requests
- Deduplicates tickets β checks existing open tickets before creating new ones
- Enforced boundaries β only responds to business-related queries
- Web chat interface β test the AI via browser at
/chat - 3D vector space visualization β explore embeddings at
/embedding/visualize-3d - 2D vector space visualization β scatter plot at
/embedding/visualize - Swagger API docs β full REST documentation at
/api/docs - Real-time dashboard β connection status + QR code at
/
| Layer | Technology |
|---|---|
| Framework | NestJS 11, TypeScript |
| LLM | OpenAI GPT-4o-mini via LangChain |
| Embeddings | OpenAI text-embedding-3-small (1536 dims) |
| Vector Search | MongoDB Atlas $vectorSearch |
| Database | MongoDB 7 / Mongoose |
| whatsapp-web.js + Puppeteer | |
| API Docs | Swagger UI |
| Containerization | Docker (multi-stage build) |
- Node.js 20+
- MongoDB (local Docker or Atlas free tier)
- OpenAI API key
- A machine where Chromium can run (for WhatsApp Web)
git clone https://github.com/your-username/wa-support-ai.git
cd wa-support-ai
npm installdocker compose -f infra-setup/docker-compose.yml up -dThis starts MongoDB 7 on localhost:27017 with Mongo Express GUI on localhost:8081.
cp .env.example .envFill in your values:
PORT=3000
OPENAI_API_KEY=sk-...
OPENAI_MODEL=gpt-4o-mini
OPENAI_EMBEDDING_MODEL=text-embedding-3-small
MONGODB_URI=mongodb://localhost:27017/wa_support_ai
WA_SEND_API_USER=your-api-user
WA_SEND_API_PASS=your-api-passnpm run start:devOpen http://localhost:3000 and scan the QR code with your phone.
Upload documents via the API or Swagger UI:
curl -X POST http://localhost:3000/document/upload \
-F "file=@your-document.pdf"Embeddings are generated automatically after upload.
In MongoDB Atlas β Search β Create Index:
{
"type": "vectorSearch",
"fields": [{
"path": "embedding",
"numDimensions": 1536,
"similarity": "cosine",
"type": "vector"
}]
}Index name: autoembed_index on collection document_chunks.
| Method | Endpoint | Description |
|---|---|---|
| GET | /wa-channel/status |
Connection status |
| GET | /wa-channel/qr |
QR code as PNG |
| GET | /wa-channel/events |
SSE stream (status + QR) |
| POST | /wa-channel/send-message |
Send outbound message (auth required) |
| GET | /wa-channel/users |
List unique users |
| GET | /wa-channel/conversations/:phone |
Conversation history |
| GET | /wa-channel/tickets |
List all tickets |
| Method | Endpoint | Description |
|---|---|---|
| POST | /document/upload |
Upload and ingest a document |
| GET | /document |
List all documents |
| GET | /document/:id/chunks |
View chunks |
| DELETE | /document/:id |
Delete a document |
| Method | Endpoint | Description |
|---|---|---|
| POST | /embedding/process |
Embed all unprocessed chunks |
| POST | /embedding/query |
Embed text (for testing) |
| GET | /embedding/visualize |
2D visualization |
| GET | /embedding/visualize-3d |
3D visualization |
| Method | Endpoint | Description |
|---|---|---|
| GET | /chat |
Chat UI |
| POST | /chat/send |
Send message (full response) |
| POST | /chat/stream |
Send message (SSE stream) |
Full Swagger documentation available at /api/docs.
src/
βββ main.ts # Bootstrap + Swagger
βββ app.module.ts # Root module
βββ database/
β βββ database.module.ts # MongoDB connection
β βββ schemas/ # Mongoose schemas
β βββ document-chunk.schema.ts
β βββ document-metadata.schema.ts
β βββ conversation-log.schema.ts
β βββ ticket.schema.ts
βββ wa-channel/ # WhatsApp transport + AI handler
β βββ wa-channel.module.ts
β βββ wa-channel.service.ts # Message handling, RAG integration, tickets
β βββ wa-channel.controller.ts # REST + SSE endpoints
βββ rag/ # RAG orchestration
β βββ rag.module.ts
β βββ rag.service.ts # Query β Embed β Search β Generate
βββ llm/ # LLM provider (OpenAI via LangChain)
β βββ llm.module.ts
β βββ llm.service.ts
βββ embedding/ # Vector embedding generation
β βββ embedding.module.ts
β βββ embedding.service.ts
β βββ embedding.controller.ts
β βββ pages/ # Visualization UIs
βββ document/ # Document ingestion pipeline
β βββ document.module.ts
β βββ document.service.ts
β βββ document.controller.ts
β βββ chunking/ # Text splitting
β βββ loaders/ # PDF, TXT, CSV parsers
βββ chat/ # Web chat interface
β βββ chat.module.ts
β βββ chat.service.ts
β βββ chat.controller.ts
β βββ pages/
βββ frontend/
βββ dashboard.controller.ts # Main dashboard UI
| Collection | Purpose |
|---|---|
document_chunks |
Chunked text with embedding vectors |
documents |
Document metadata (filename, size, status) |
conversation_logs |
Full message logs with RAG context |
tickets |
Support tickets (complaints, cancellations, etc.) |
docker compose up -d --buildThe app image uses a multi-stage build with Alpine + Chromium. WhatsApp sessions persist via Docker volumes.
For production, use MongoDB Atlas for vector search and set NODE_ENV=production.
| Command | Description |
|---|---|
npm run start:dev |
Development mode with hot reload |
npm run build |
Compile TypeScript |
npm run start:prod |
Run compiled build |
npm run lint |
ESLint with auto-fix |
npm run test |
Run unit tests |
Customer sends WhatsApp message
β Typing indicator shown
β Load conversation history (last 10 messages)
β Check existing open tickets (dedup)
β Embed user query (OpenAI)
β Vector search for relevant chunks (MongoDB Atlas)
β Build augmented prompt (system prompt + context + history)
β LLM generates response (GPT-4o-mini)
β If response contains ticket JSON β create ticket in DB
β Log conversation (user msg + AI response + sources + tokens)
β Send response to customer
UNLICENSED β private project.


