BanglaSupport-LLM built with Unsloth (QLoRA), FastAPI, ChromaDB, and React that combines fine-tuned LLMs, Retrieval-Augmented Generation, conversation memory, and agentic tool calling into a single modular pipeline for Bangla e-commerce customer support.
- Domain-specific instruction fine-tuning on Qwen2.5-7B/Qwen3-8B using Unsloth QLoRA (4-bit NF4)
- Custom Bangla dataset pipeline with NFC Unicode normalization and MinHash LSH deduplication
- Multi-tier comparative evaluation comparing BLEU-4, ROUGE-L, BERTScore, and LLM-as-a-Judge metrics
- Document-grounded RAG comparing base vs. fine-tuned vs. fine-tuned + RAG latency and hallucination rates
- Agentic tool-calling to resolve customer query intents (such as SQLite order status lookup)
- Streamed responses using Server-Sent Events (SSE) from a FastAPI backend
- Modern responsive glassmorphic React chat UI with native Bangla typography (Hind Siliguri)
- Production-grade containerized deployment with multi-stage Docker Compose
flowchart TD
subgraph DataPrep [Phase 1: Dataset Pipeline]
A1[Bangla-Instruct 342K] --> A3[Support Intent Filter]
A2[Aya Dataset Bengali] --> A3
A3 --> A4[NFC Normalization & Dedup]
A4 --> A5[Train / Val / Test Split 289K]
end
subgraph Training [Phase 2: QLoRA Fine-Tuning]
A5 --> B1[Qwen3-8B Base Model]
B1 --> B2[Unsloth + SFTTrainer 4-bit NF4]
B2 --> B3[Merged Model Safetensors / GGUF]
end
subgraph Eval [Phase 3: Multi-Metric Evaluation]
B3 --> C1[BLEU / ROUGE-L]
B3 --> C2[BERTScore bangla-bert-base]
B3 --> C3[LLM-as-a-Judge 1-5 Scale]
end
subgraph Serving [Phase 5-6: RAG, Agent & UI Serving]
B3 --> D1[FastAPI SSE Server]
D2[ChromaDB Policy Vector Store] --> D1
D3[SQLite Order DB Tools] --> D1
D1 --> D4[Glassmorphic React UI]
end
graph LR
UserQuery[User Query] --> Router{System Mode}
Router -->|System A: Base + RAG| BaseLLM[Base Qwen3-8B]
ChromaDB[ChromaDB Vector Store] --> BaseLLM
Router -->|System B: Fine-Tuned| FTModel[Fine-Tuned BanglaSupport-LLM]
Router -->|System C: Fine-Tuned + RAG| FTRAG[Fine-Tuned BanglaSupport-LLM]
ChromaDB --> FTRAG
BaseLLM --> EvalComp[Latency / Hallucination / BLEU Metrics]
FTModel --> EvalComp
FTRAG --> EvalComp
sequenceDiagram
autonumber
actor Customer as Customer
participant API as FastAPI Backend
participant Agent as Intent Detector
participant DB as SQLite Order DB
participant LLM as Fine-Tuned Model
Customer->>API: Order BD1001 status request
API->>Agent: Parse intent & extract order_id=BD1001
Agent->>DB: get_order_status(BD1001)
DB-->>Agent: Status: Hub, Delivery: 2026-07-21
Agent->>LLM: Formulate contextual Bangla prompt
LLM-->>API: Streamed response text
API-->>Customer: Real-time SSE Streamed Answer
The dataset and model training pipeline performs the following steps:
- Filter instruction-tuning pairs from
md-nishat-008/Bangla-Instruct(ACL 2025) andCohereForAI/aya_datasetinto 12 intent categories - Perform NFC Unicode normalization and deduplicate using MinHash LSH (Locality-Sensitive Hashing)
- Split data into training, validation, and testing sets (85/10/5 split)
- Train the base model using Unsloth QLoRA (4-bit NF4 quantization,
$r=16, \alpha=32$ ,bfloat16precision) - Merge the LoRA adapter to standard Safetensors and GGUF format for CPU/GPU inference
For every retrieval request in RAG mode:
- Chunk policy Markdown documents and generate embeddings using
paraphrase-multilingual-MiniLM-L12-v2 - Index the embeddings into a local ChromaDB vector store
- Perform semantic search for the user's query against ChromaDB
- Retrieve the most relevant policy text snippets and inject them as context into the prompt template
This ensures the model answers according to official store policies and minimizes domain-specific hallucinations.
The backend includes a functional routing engine to determine intent:
- Extract order details (e.g. order ID) or query parameters from user inputs
- Execute target tools against mock SQLite database (using functions like
get_order_statusorrefund_eligibility) - Pass retrieved status data back to the fine-tuned LLM
- Generate the final natural-language response streamed in real-time to the client
Different system prompts/templates are used depending on the active mode:
Employs a baseline customer support persona instruction in Bangla to answer queries directly without external data.
Forces the model to only use the retrieved context snippets from the policy documents and restrict answers to verified facts.
Commands the model to utilize structured database query tools whenever order or tracking lookups are requested.
| Component | Technology |
|---|---|
| Base Model | Qwen2.5-7B-Instruct / Qwen3-8B |
| Training Optimization | Unsloth, QLoRA (4-bit NF4), PyTorch, PEFT |
| RAG Embeddings | Sentence-Transformers (paraphrase-multilingual-MiniLM-L12-v2) |
| Vector Store | ChromaDB |
| Mock DB / Tools | SQLite |
| Backend Server | FastAPI, Uvicorn, SSE-Starlette |
| Frontend Client | React (Vite), Lucide Icons, Vanilla CSS (Glassmorphism) |
| Containerization | Docker, Docker Compose |
- Python 3.10+
- Node.js (for React frontend)
- Docker & Docker Compose (optional)
- GPU (optional, for Unsloth training)
git clone https://github.com/FHJibon/BanglaSupport-LLM.git
cd BanglaSupport-LLMSet up a virtual environment and prepare datasets:
python -m venv venv
# Activate virtual environment
# Windows: venv\Scripts\activate | Linux/macOS: source venv/bin/activate
pip install -r requirements.txt
# Run prep scripts
python dataset/scripts/download_and_filter.py
python dataset/scripts/download_aya.py
python dataset/scripts/prepare_dataset.py
python dataset/scripts/split_data.py# Smoke test (50 steps)
python training/train.py --max_steps 50
# Full training
python training/train.py
# Merge adapter into full model
python training/merge_adapter.py --adapter checkpoints/qwen3-8b-bangla-support/final_adapterBuild the RAG document store index:
python knowledge_base/build_index.pyuvicorn inference.api.main:app --reload --port 8000cd app/frontend
npm install
npm run devdocker-compose -f docker/docker-compose.yml up --buildPOST /chat
This endpoint:
- Receives the query and operating mode
- Performs RAG retrieval or executes database tools depending on selected
mode - Returns a Server-Sent Events (SSE) stream of token responses
{
"message": "আমার অর্ডার BD1001 কোথায়?",
"mode": "agent"
}{
"response": "আপনার অর্ডারটি বর্তমানে ডেলিভারি সেন্টারে রয়েছে এবং ২০২৬-০৭-২১ তারিখের মধ্যে ডেলিভারি করা হবে।",
"mode": "agent",
"tool_called": "get_order_status",
"tool_args": {"order_id": "BD1001"}
}User:
আসসালামু আলাইকুম
Assistant:
ওয়া আলাইকুম আসসালাম! বাংলা ই-কমার্স গ্রাহক সহায়তায় আপনাকে স্বাগতম। আমি কিভাবে সাহায্য করতে পারি?
User:
ডেলিভারি রিফান্ড পলিসি কী?
Assistant:
পণ্য হাতে পাওয়ার ৭ দিনের মধ্যে যেকোনো ত্রুটিপূর্ণ পণ্য সম্পূর্ণ রিফান্ড অথবা পরিবর্তনের জন্য আবেদন করা যাবে। (RAG রিট্রিভড তথ্য ব্যবহার করে)
User:
আমার অর্ডার BD1001 কোথায়?
Assistant:
আপনার অর্ডার BD1001 বর্তমানে ডেলিভারি সেন্টারে রয়েছে এবং এটি ২০২৬-০৭-২১ তারিখে পৌঁছাবে। (এক্সিকিউটেড টুল: get_order_status)
| Model Variant | BLEU-4 | ROUGE-L | BERTScore (F1) | LLM-Judge (Fluency) | LLM-Judge (Accuracy) |
|---|---|---|---|---|---|
| Base Qwen2.5-7B-Instruct | 0.1820 | 0.3840 | 0.7620 | 3.4 / 5.0 | 3.1 / 5.0 |
| Fine-Tuned BanglaSupport-LLM (QLoRA) | 0.4280 | 0.6910 | 0.9140 | 4.8 / 5.0 | 4.7 / 5.0 |
The application gracefully handles:
- Incomplete/malformed prompt templates
- Empty context extraction from vector store (fallback message)
- Invalid or non-existent order IDs in SQLite lookup
- Missing training checkpoints or local databases
- Backend network timeout and disconnect exceptions
This system was engineered end-to-end by:
-
Mahmudur Rahman
- Focus: ML Pipeline, Model Fine-Tuning, Full-Stack Architecture, RAG implementation.
- Email: mahmudurrahman858@gmail.com
- GitHub: @mrshibly
-
Ferdous Hasan
- Focus: ML Pipeline, Model Fine-Tuning, Dataset curation, Evaluation.
- Email: ferdoushasanjibon25@gmail.com
- GitHub: @FHJibon
- Hugging Face: @FHJibon
Distributed under the MIT License. See LICENSE for more information.