A fullstack chatbot application built with Flask, React, MongoDB, and RAG (Retrieval-Augmented Generation) technology.
This project implements a RAG (Retrieval-Augmented Generation) chatbot that:
βββββββββββββββββββ HTTP βββββββββββββββββββ Query βββββββββββββββββββ
β β Requests β β MongoDB β β
β React Frontend β ββββββββββββΊ β Flask Backend β βββββββββββββΊ β MongoDB β
β (Port 3000) β ββββββββββββ β (Port 5000) β β (Port 27017) β
β β Responses β β β β
βββββββββββββββββββ ββββββββββ¬βββββββββ βββββββββββββββββββ
β
β RAG Pipeline
βΌ
βββββββββββββββββββ
β RAG Model β
β βββββββββββββ β
β β Retrieval β β βββ FAISS + SentenceTransformer
β βββββββ¬ββββββ β
β β β
β βββββββΌββββββ β
β βGeneration β β βββ Flan-T5
β βββββββββββββ β
βββββββββββββββββββ
Before running this project, make sure you have the following installed:
| Software | Version | Download Link |
|---|---|---|
| Python | 3.10+ | https://www.python.org/downloads/ |
| Node.js | 18+ | https://nodejs.org/ |
| MongoDB | 6.0+ | https://www.mongodb.com/try/download/community |
| Git | Latest | https://git-scm.com/ |
| Component | Minimum | Recommended |
|---|---|---|
| RAM | 8 GB | 16 GB |
| Storage | 5 GB free | 10 GB free |
| CPU | 4 cores | 8 cores |
cd d:\rag-chatbot-app
cd backend
python -m venv venv
Windows (PowerShell):
.\venv\Scripts\Activate
Windows (CMD):
venv\Scripts\activate.bat
Linux/Mac:
source venv/bin/activate
pip install flask flask-restful pymongo flask-cors
pip install langchain transformers torch faiss-cpu
pip install sentence-transformers numpy
Or install from requirements (if available):
pip install -r requirements.txt
cd ..\frontend
npm install
Make sure MongoDB service is running:
Windows:
# Check if MongoDB is running
Get-Service MongoDB
# Start MongoDB if not running
Start-Service MongoDB
Linux/Mac:
sudo systemctl start mongod
cd d:\rag-chatbot-app\backend
.\venv\Scripts\Activate
python app.py
Expected output:
Loading knowledge base...
Loading embedding model for retrieval...
Creating FAISS index...
Loading generation model... This may take a while on first run.
RAG model loaded successfully!
Starting Flask server...
* Serving Flask app 'app'
* Running on http://127.0.0.1:5000
cd d:\rag-chatbot-app\frontend
npm start
Expected output:
Compiled successfully!
You can now view frontend in the browser.
Local: http://localhost:3000
Create a file start.bat in the root folder:
@echo off
echo Starting RAG Chatbot...
echo Starting Backend...
start cmd /k "cd /d d:\rag-chatbot-app\backend && venv\Scripts\activate && python app.py"
timeout /t 10
echo Starting Frontend...
start cmd /k "cd /d d:\rag-chatbot-app\frontend && npm start"
echo Done! Backend: http://localhost:5000 | Frontend: http://localhost:3000
| Service | URL |
|---|---|
| Frontend (Chat UI) | http://localhost:3000 |
| Backend API | http://localhost:5000 |
| MongoDB | mongodb://localhost:27017 |
rag-chatbot-app/
β
βββ backend/
β βββ venv/ # Python virtual environment
β βββ app.py # Flask API server
β βββ rag_model.py # RAG model implementation
β βββ __pycache__/ # Python cache
β
βββ frontend/
β βββ node_modules/ # Node.js dependencies
β βββ public/ # Static files
β βββ src/
β β βββ App.js # Main React component
β β βββ App.css # Styling
β β βββ index.js # Entry point
β βββ package.json # Node.js config
β
βββ data/
β βββ knowledge_base.json # Knowledge base for RAG
β
βββ README.md # This file
User Question: "What is RAG?"
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 1. EMBEDDING β
β Convert question to vector β
β Model: all-MiniLM-L6-v2 β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 2. RETRIEVAL β
β Search similar documents in FAISS β
β Return top-k relevant documents β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 3. AUGMENTATION β
β Combine: Context + Question β
β Create prompt for generation β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 4. GENERATION β
β Generate answer using Flan-T5 β
β Model: google/flan-t5-base β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Answer: "RAG is Retrieval-Augmented Generation..."
| Component | Model | Size | Purpose |
|---|---|---|---|
| Embedding | all-MiniLM-L6-v2 | ~90 MB | Convert text to vectors |
| Generation | google/flan-t5-base | ~990 MB | Generate responses |
| Vector DB | FAISS | In-memory | Similarity search |
Retrieve all messages from database.
Request:
curl http://localhost:5000/message
Response:
{
"messages": [
{"message": "Hello", "sender": "user"},
{"message": "Hi! How can I help?", "sender": "bot"}
]
}
Send a message and get bot response.
Request:
curl -X POST http://localhost:5000/message \
-H "Content-Type: application/json" \
-d '{"message": "What is RAG?"}'
Response:
{
"message": "RAG is Retrieval-Augmented Generation, a technique that combines retrieval and generation for more accurate responses."
}
Edit data/knowledge_base.json:
[
{
"title": "Topic Title",
"text": "Detailed information about the topic that the bot should know."
},
{
"title": "Another Topic",
"text": "More information here..."
}
]
After editing, restart the backend to reload the knowledge base.
Edit backend/rag_model.py:
# For better quality (requires more RAM)
gen_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
gen_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
# For Indonesian language
gen_tokenizer = AutoTokenizer.from_pretrained("Wikidepia/IndoT5-base")
gen_model = AutoModelForSeq2SeqLM.from_pretrained("Wikidepia/IndoT5-base")
pip install <missing-module>
Make sure MongoDB is running:
Get-Service MongoDB
Start-Service MongoDB
Backend (5000):
netstat -ano | findstr :5000
taskkill /PID <PID> /F
Frontend (3000):
netstat -ano | findstr :3000
taskkill /PID <PID> /F
gen_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
Make sure Flask-CORS is installed and backend is running:
pip install flask-cors
Check internet connection. Models are downloaded from HuggingFace (~1GB total for first run).
Jika backend stuck saat start, matikan Flask debug/reloader di app.py:
if __name__ == '__main__':
app.run(debug=False, use_reloader=False)
| Layer | Technology |
|---|---|
| Frontend | React.js, Axios |
| Backend | Flask, Flask-RESTful, Flask-CORS |
| Database | MongoDB |
| AI/ML | Transformers, SentenceTransformers, FAISS |
| Language Model | Google Flan-T5 |
This project is for educational purposes, following the tutorial from fullstack-chatbot-with-langchain-and-rag.
Feel free to fork, modify, and improve this project!
Happy Coding! π npm install
## Running the Application
### Start the Backend
```bash
cd backend
python app.py
The backend will run on http://localhost:5000
cd frontend
npm start
The frontend will run on http://localhost:3000
http://localhost:3000Edit the data/knowledge_base.json file to add your own documents:
[
{"title": "Document Title", "text": "Document content..."},
{"title": "Another Document", "text": "More content..."}
]
The first time you run the backend, it will download the RAG model (~3GB), which may take some time.
1 commits
Python
34.2%
JavaScript
32.7%
CSS
16.8%
HTML
16.2%
A fullstack chatbot application built with Flask, React, MongoDB, and RAG (Retrieval-Augmented Generation) technology.
This project implements a RAG (Retrieval-Augmented Generation) chatbot that:
βββββββββββββββββββ HTTP βββββββββββββββββββ Query βββββββββββββββββββ
β β Requests β β MongoDB β β
β React Frontend β ββββββββββββΊ β Flask Backend β βββββββββββββΊ β MongoDB β
β (Port 3000) β ββββββββββββ β (Port 5000) β β (Port 27017) β
β β Responses β β β β
βββββββββββββββββββ ββββββββββ¬βββββββββ βββββββββββββββββββ
β
β RAG Pipeline
βΌ
βββββββββββββββββββ
β RAG Model β
β βββββββββββββ β
β β Retrieval β β βββ FAISS + SentenceTransformer
β βββββββ¬ββββββ β
β β β
β βββββββΌββββββ β
β βGeneration β β βββ Flan-T5
β βββββββββββββ β
βββββββββββββββββββ
Before running this project, make sure you have the following installed:
| Software | Version | Download Link |
|---|---|---|
| Python | 3.10+ | https://www.python.org/downloads/ |
| Node.js | 18+ | https://nodejs.org/ |
| MongoDB | 6.0+ | https://www.mongodb.com/try/download/community |
| Git | Latest | https://git-scm.com/ |
| Component | Minimum | Recommended |
|---|---|---|
| RAM | 8 GB | 16 GB |
| Storage | 5 GB free | 10 GB free |
| CPU | 4 cores | 8 cores |
cd d:\rag-chatbot-app
cd backend
python -m venv venv
Windows (PowerShell):
.\venv\Scripts\Activate
Windows (CMD):
venv\Scripts\activate.bat
Linux/Mac:
source venv/bin/activate
pip install flask flask-restful pymongo flask-cors
pip install langchain transformers torch faiss-cpu
pip install sentence-transformers numpy
Or install from requirements (if available):
pip install -r requirements.txt
cd ..\frontend
npm install
Make sure MongoDB service is running:
Windows:
# Check if MongoDB is running
Get-Service MongoDB
# Start MongoDB if not running
Start-Service MongoDB
Linux/Mac:
sudo systemctl start mongod
cd d:\rag-chatbot-app\backend
.\venv\Scripts\Activate
python app.py
Expected output:
Loading knowledge base...
Loading embedding model for retrieval...
Creating FAISS index...
Loading generation model... This may take a while on first run.
RAG model loaded successfully!
Starting Flask server...
* Serving Flask app 'app'
* Running on http://127.0.0.1:5000
cd d:\rag-chatbot-app\frontend
npm start
Expected output:
Compiled successfully!
You can now view frontend in the browser.
Local: http://localhost:3000
Create a file start.bat in the root folder:
@echo off
echo Starting RAG Chatbot...
echo Starting Backend...
start cmd /k "cd /d d:\rag-chatbot-app\backend && venv\Scripts\activate && python app.py"
timeout /t 10
echo Starting Frontend...
start cmd /k "cd /d d:\rag-chatbot-app\frontend && npm start"
echo Done! Backend: http://localhost:5000 | Frontend: http://localhost:3000
| Service | URL |
|---|---|
| Frontend (Chat UI) | http://localhost:3000 |
| Backend API | http://localhost:5000 |
| MongoDB | mongodb://localhost:27017 |
rag-chatbot-app/
β
βββ backend/
β βββ venv/ # Python virtual environment
β βββ app.py # Flask API server
β βββ rag_model.py # RAG model implementation
β βββ __pycache__/ # Python cache
β
βββ frontend/
β βββ node_modules/ # Node.js dependencies
β βββ public/ # Static files
β βββ src/
β β βββ App.js # Main React component
β β βββ App.css # Styling
β β βββ index.js # Entry point
β βββ package.json # Node.js config
β
βββ data/
β βββ knowledge_base.json # Knowledge base for RAG
β
βββ README.md # This file
User Question: "What is RAG?"
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 1. EMBEDDING β
β Convert question to vector β
β Model: all-MiniLM-L6-v2 β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 2. RETRIEVAL β
β Search similar documents in FAISS β
β Return top-k relevant documents β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 3. AUGMENTATION β
β Combine: Context + Question β
β Create prompt for generation β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββ
β 4. GENERATION β
β Generate answer using Flan-T5 β
β Model: google/flan-t5-base β
βββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Answer: "RAG is Retrieval-Augmented Generation..."
| Component | Model | Size | Purpose |
|---|---|---|---|
| Embedding | all-MiniLM-L6-v2 | ~90 MB | Convert text to vectors |
| Generation | google/flan-t5-base | ~990 MB | Generate responses |
| Vector DB | FAISS | In-memory | Similarity search |
Retrieve all messages from database.
Request:
curl http://localhost:5000/message
Response:
{
"messages": [
{"message": "Hello", "sender": "user"},
{"message": "Hi! How can I help?", "sender": "bot"}
]
}
Send a message and get bot response.
Request:
curl -X POST http://localhost:5000/message \
-H "Content-Type: application/json" \
-d '{"message": "What is RAG?"}'
Response:
{
"message": "RAG is Retrieval-Augmented Generation, a technique that combines retrieval and generation for more accurate responses."
}
Edit data/knowledge_base.json:
[
{
"title": "Topic Title",
"text": "Detailed information about the topic that the bot should know."
},
{
"title": "Another Topic",
"text": "More information here..."
}
]
After editing, restart the backend to reload the knowledge base.
Edit backend/rag_model.py:
# For better quality (requires more RAM)
gen_tokenizer = AutoTokenizer.from_pretrained("google/flan-t5-large")
gen_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-large")
# For Indonesian language
gen_tokenizer = AutoTokenizer.from_pretrained("Wikidepia/IndoT5-base")
gen_model = AutoModelForSeq2SeqLM.from_pretrained("Wikidepia/IndoT5-base")
pip install <missing-module>
Make sure MongoDB is running:
Get-Service MongoDB
Start-Service MongoDB
Backend (5000):
netstat -ano | findstr :5000
taskkill /PID <PID> /F
Frontend (3000):
netstat -ano | findstr :3000
taskkill /PID <PID> /F
gen_model = AutoModelForSeq2SeqLM.from_pretrained("google/flan-t5-small")
Make sure Flask-CORS is installed and backend is running:
pip install flask-cors
Check internet connection. Models are downloaded from HuggingFace (~1GB total for first run).
Jika backend stuck saat start, matikan Flask debug/reloader di app.py:
if __name__ == '__main__':
app.run(debug=False, use_reloader=False)
| Layer | Technology |
|---|---|
| Frontend | React.js, Axios |
| Backend | Flask, Flask-RESTful, Flask-CORS |
| Database | MongoDB |
| AI/ML | Transformers, SentenceTransformers, FAISS |
| Language Model | Google Flan-T5 |
This project is for educational purposes, following the tutorial from fullstack-chatbot-with-langchain-and-rag.
Feel free to fork, modify, and improve this project!
Happy Coding! π npm install
## Running the Application
### Start the Backend
```bash
cd backend
python app.py
The backend will run on http://localhost:5000
cd frontend
npm start
The frontend will run on http://localhost:3000
http://localhost:3000Edit the data/knowledge_base.json file to add your own documents:
[
{"title": "Document Title", "text": "Document content..."},
{"title": "Another Document", "text": "More content..."}
]
The first time you run the backend, it will download the RAG model (~3GB), which may take some time.
1 commits
Python
34.2%
JavaScript
32.7%
CSS
16.8%
HTML
16.2%