A production-ready Retrieval-Augmented Generation (RAG) chatbot for banking products, built with FastAPI, LangChain, ChromaDB, and Groq. Features multilingual support (English + Burmese), automatic query routing, real-time evaluation, observability monitoring, conversation memory, and a full analytics dashboard.
- Architecture
- RAG Pipeline
- Evaluation Pipeline
- Observability Pipeline
- Query Routing
- Multilingual Support
- Metrics Explained
- Tech Stack
- Project Structure
- Getting Started
- API Endpoints
- Future Roadmap
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β User Interface β
β Chat UI β Analytics Dashboard β Observability β Admin β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββββββββββββββ
β FastAPI Backend β
β /chat β /ingest β /evaluate β /feedback β
β /sessions β /dashboard β /observability β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββΌββββββββββββββ
β β β
βββββββββΌβββββββ ββββββΌβββββ ββββββΌβββββββββββ
β LangChain β βChromaDB β β Groq LLMs β
β RAG Chain β βVectors β β Llama 3.3 β
β + Routing β β741 chunksβ β Qwen 3 32B β
ββββββββββββββββ βββββββββββ βββββββββββββββββ
β
βββββββββΌβββββββββββββββββββββββββββββββββββββββ
β Logging & Observability β
β eval_log β feedback_log β obs_log β
ββββββββββββββββββββββββββββββββββββββββββββββββ
User Query
β
βΌ
Language Detection
(Unicode range check β English or Burmese)
β
βΌ
Query Router
βββ Simple / Factual βββββββββββΊ Llama 3.3 70B (fast retrieval)
βββ Complex / Comparison βββββββΊ Qwen 3 32B (deep reasoning)
β
βΌ
ChromaDB Similarity Search
(HuggingFace all-MiniLM-L6-v2 embeddings)
β
βΌ
Top-K Chunks Retrieved (k=15)
+ Similarity Scores
+ Source Metadata
β
βΌ
Prompt Builder
(System prompt + language instruction + context + chat history)
β
βΌ
LLM Response Generation (streaming)
β
ββββΊ Evaluation Pipeline (optional, per-query)
ββββΊ Observability Logger (always)
ββββΊ Session Memory (always)
β
βΌ
Final Response + Source Citations
Query + Retrieved Context + Generated Answer
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββ
β LLM Judge (Llama 4 Scout) β
β Bilingual-aware β handles Burmese contextβ
βββββββββββββββββββββββββββββββββββββββββββββ
β
ββββΊ Context Relevance
β Are retrieved chunks relevant to the question?
β Score: 0.0 β 1.0
β
ββββΊ Faithfulness
β Is the answer grounded in the context?
β Score: 0.0 β 1.0
β
ββββΊ Answer Relevance
β Does the answer address the question?
β Score: 0.0 β 1.0
β
ββββΊ Hallucination Detection
β LLM Judge + Rule-based word overlap
β Score: 0.0 (hallucinated) β 1.0 (clean)
β
ββββΊ Retrieval Quality
Precision, Recall, MRR
Rule-based keyword overlap scoring
β
βΌ
Overall Score (average of LLM-based metrics)
β
βΌ
Logged to eval_log.csv + eval_log.json
Every Inference Request
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Latency Monitor β
β retrieval_latency_ms β
β llm_latency_ms β
β total_latency_ms β
β P50 / P95 / P99 percentiles β
ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Token Tracker β
β estimated_prompt_tokens β
β estimated_completion_tokens β
β estimated_total_tokens β
β cumulative total across all queries β
ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Retrieval Diagnostics β
β top_score, avg_score, min_score β
β chunks_retrieved, chunks_used β
β top_chunk_source, top_chunk_section β
β full retrieved_docs list with scores β
ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββ
β Failure Analysis β
β retrieval_success (score > 0.2) β
β grounded_retrieval (answer β© context) β
β failed_retrieval β
β failure_reason: β
β - unsupported_query β
β - low_confidence β
β - empty_retrieval β
ββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Logged to observability_log.csv + observability_log.json
β
βΌ
Observability Dashboard
(Latency trends, token usage, score distribution,
failure table, retrieval diagnostics per query)
The router classifies every question before sending it to an LLM. Simple factual questions use the fast retrieval model; complex multi-step questions use the reasoning model.
Routing logic:
REASONING_KEYWORDS = [
# Comparison
"compare", "difference", "better", "best", "vs", "versus", "which",
# Multi-step
"calculate", "how much", "total", "eligibility", "qualify",
# Conditional
"if i", "what happens if", "can i", "should i",
# Complex
"explain", "why", "recommend", "advise", "pros and cons"
]| Question Type | Example | Model |
|---|---|---|
| Factual lookup | "What is the interest rate for term loan?" | β‘ Llama 3.3 70B |
| Comparison | "Which loan is better for 2 years?" | π§ Qwen 3 32B |
| Eligibility | "Can I apply for a credit card?" | π§ Qwen 3 32B |
| Definition | "What is a fixed deposit account?" | β‘ Llama 3.3 70B |
| Recommendation | "Which account should I open?" | π§ Qwen 3 32B |
Language detection uses Unicode character range analysis β no external library needed.
User sends a question
β
βΌ
Count Burmese Unicode characters (U+1000 β U+109F)
β
βββ ratio > 20% βββΊ Language = Burmese (ααΌααΊαα¬αα¬αα¬)
βββ ratio β€ 20% βββΊ Language = English
β
βΌ
Language injected into system prompt:
"You MUST respond in {language}"
β
βΌ
LLM answers in the detected language
Source citations remain in original Burmese
Supported languages: English, Burmese (ααΌααΊαα¬αα¬αα¬)
Example:
| Input | Detected | Output |
|---|---|---|
| "What is the interest rate?" | π¬π§ English | English answer |
| "α‘ααα―αΈααΎα―ααΊαΈ αααΊαα±α¬ααΊαα²?" | π²π² Burmese | Burmese answer |
| "CB Pay ααα― αααΊααα― register αα―ααΊαααα²?" | π²π² Burmese | Burmese answer |
| Metric | Description | Range | Good Score |
|---|---|---|---|
| Context Relevance | Are retrieved chunks relevant to the question? | 0 β 1 | > 0.7 |
| Faithfulness | Is the answer supported by the context? | 0 β 1 | > 0.8 |
| Answer Relevance | Does the answer address the question asked? | 0 β 1 | > 0.8 |
| Hallucination Score | Combined LLM judge + rule-based overlap check | 0 β 1 | > 0.7 |
| Overall Score | Average of the four LLM-based metrics above | 0 β 1 | > 0.7 |
| Metric | Description |
|---|---|
| Precision | Fraction of retrieved chunks with keyword overlap > 20% |
| Coverage | Average overlap score across all retrieved chunks |
| MRR | Mean Reciprocal Rank β how high the first relevant chunk ranks |
| Top Score | Highest similarity score among retrieved chunks (0 = no match, 1 = perfect) |
| Metric | Description |
|---|---|
| Retrieval Latency | Time to embed query + search ChromaDB |
| LLM Latency | Time for LLM to generate the full response |
| Total Latency | End-to-end response time |
| P95 Latency | 95th percentile β worst-case latency for 95% of queries |
| Grounded Rate | Fraction of answers where content overlaps with retrieved context |
| Failed Retrieval Rate | Fraction of queries where retrieval returned low-confidence or unsupported results |
| Estimated Tokens | Prompt + completion token count (1 token β 4 characters) |
The ingestion pipeline handles 3 Q&A document formats automatically:
Format 1 β Q:/A: style
Q: Term Loan ααα―αα¬αα¬αα²?
A: Term Loan αααΊ ...
Format 2 β Structured metadata style
Category: Loans
Product: Term Loan
Topic: Overview
Question:
What is a Term Loan?
Alternative Questions:
β’ Term loan ααα―αα¬αα¬αα²
Answer:
A Term Loan is...
Format 3 β Plain FAQ
What is Personal Internet Banking?
CB Bank's Personal Internet Banking is...
Alternative questions are indexed as separate searchable chunks, each containing the full answer. This dramatically improves retrieval for varied phrasings.
| Component | Technology |
|---|---|
| API Framework | FastAPI + Uvicorn |
| RAG Orchestration | LangChain |
| Vector Store | ChromaDB (local) |
| Embeddings | HuggingFace all-MiniLM-L6-v2 (free, local) |
| LLM β Retrieval | Groq Llama 3.3 70B |
| LLM β Reasoning | Groq Qwen 3 32B |
| LLM β Evaluation | Groq Llama 4 Scout 17B |
| Document Parsing | PyMuPDF (PDF), python-docx (DOCX) |
| Frontend | Vanilla HTML/CSS/JS + Chart.js |
| Session Storage | JSON files |
| Log Storage | CSV + JSON |
banking-rag-chatbot/
βββ app/
β βββ config.py # Settings, model names, admin password
β βββ ingest.py # Document parsing (3 formats), ChromaDB ingestion
β βββ chain.py # RAG chain, query routing, multilingual detection
β βββ evaluator.py # 5 evaluation metrics, LLM judge
β βββ logger.py # Evaluation log (CSV + JSON)
β βββ feedback.py # User feedback log (CSV + JSON)
β βββ session_manager.py # Conversation memory, context window management
β βββ observability.py # Latency, token, retrieval diagnostics logging
β βββ main.py # FastAPI app, all endpoints
β
βββ frontend/
β βββ index.html # Streaming chat UI
β βββ dashboard.html # Analytics dashboard
β βββ observability.html # Observability monitoring page
β βββ admin.html # Password-protected admin panel
β
βββ docs/ # Product knowledge base
β βββ accounts/ # Account product documents
β βββ cards/ # Card product documents
β βββ loans/ # Loan product documents
β βββ mobile_banking/ # Mobile banking documents
β βββ ibanking/ # Internet banking documents
β
βββ sessions/ # Conversation session JSON files
β
βββ logs/
β βββ eval_log.csv # Evaluation scores per query
β βββ eval_log.json
β βββ feedback_log.csv # User π π feedback
β βββ feedback_log.json
β βββ observability_log.csv # Latency, tokens, retrieval diagnostics
β βββ observability_log.json
β
βββ .env # API keys (not committed)
βββ .gitignore
βββ requirements.txt
- Python 3.10+
- Free Groq API key
git clone https://github.com/yourusername/banking-rag-chatbot
cd banking-rag-chatbot
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtCreate .env:
GROQ_API_KEY=your_groq_api_key_here
ADMIN_PASSWORD=your_admin_passwordPlace your PDF or DOCX files in the appropriate folder:
docs/accounts/ β account product documents
docs/cards/ β card product documents
docs/loans/ β loan product documents
docs/mobile_banking/
docs/ibanking/
python -c "from app.ingest import ingest_documents; print(ingest_documents())"uvicorn app.main:app --reload --port 8000| URL | Description |
|---|---|
| http://localhost:8000/chat-ui | Chat interface |
| http://localhost:8000/dashboard | Analytics dashboard |
| http://localhost:8000/observability | Observability monitoring |
| http://localhost:8000/admin | Admin panel (password protected) |
| http://localhost:8000/docs | Auto-generated API docs |
| Method | Endpoint | Description |
|---|---|---|
| POST | /chat |
Streaming chat with session memory |
| POST | /ingest |
Upload and index a document |
| POST | /evaluate |
Manual evaluation of a Q&A pair |
| POST | /feedback |
Submit π π feedback |
| GET | /sessions |
List all sessions |
| POST | /sessions/new |
Create a new session |
| GET | /sessions/{id} |
Get session with full history |
| DELETE | /sessions/{id} |
Delete a session |
| GET | /logs/summary |
Evaluation summary statistics |
| GET | /logs/all |
All evaluation records |
| GET | /feedback/summary |
Feedback summary statistics |
| GET | /feedback/all |
All feedback records |
| GET | /observability/summary |
Observability summary |
| GET | /observability/all |
All observation records |
| GET | /admin/files |
List all ingested documents |
| DELETE | /admin/files/{cat}/{file} |
Delete a document |
| POST | /admin/reingest |
Re-ingest all documents |
| GET | /admin/stats |
System-wide admin statistics |
| GET | /health |
Health check |
- Convert scanned PDFs to structured DOCX for better extraction
- Add batch evaluation from CSV upload in admin panel
- Auto-generate overview documents per product category
- Add confidence score display in chat UI
- Deploy to cloud (Railway / Render / AWS)
- Add Redis for session storage (scale beyond single server)
- Implement re-ranking layer (Cohere or cross-encoder)
- Add user authentication and multi-tenant support
- Webhook notifications for low evaluation scores
- Fine-tune embedding model on domain-specific Burmese banking text
- Agentic RAG β multi-hop reasoning across documents
- Voice input support for Burmese
- Integrate with live banking API for real-time product data
- A/B testing framework for prompt and model experiments