vithacocf commited on
Commit
856e273
·
verified ·
1 Parent(s): dc23d0f

Kiến trúc Hệ thống Chatbot Multi-Tenant với Dynamic Routing & RAG

Browse files

1. Mục tiêu hệ thống
• Hỗ trợ Multi-Tenant với khả năng cấu hình động cho:
o Topics (chủ đề)
o Intents (ý định)
o Routing rules (luồng xử lý)
o LLM models, RAG pipelines
o Backend endpoints (eFMS, eTMS, eWMS…)
• Cho phép thêm/sửa topic, intent, prompt, backend mà không cần deploy lại.
• Hỗ trợ RAG (Retrieval-Augmented Generation) để truy xuất dữ liệu từ:
o API backend
o Knowledge base nội bộ
• Lưu trữ đầy đủ session & message logs để training và phân tích.
________________________________________
2. Thành phần chính
2.1. Tenants
• Đại diện cho khách hàng hoặc tổ chức sử dụng hệ thống.
• Mỗi tenant có:
o Danh sách topics
o Cấu hình routing, agent, pipeline
o Dữ liệu RAG knowledge base
o Danh sách backend có thể sử dụng
________________________________________
2.2. Topics
Mỗi topic đại diện cho một chức năng hoặc chủ đề mà chatbot xử lý:
• topic_configs: config endpoint, method, headers, mapping request/response
• intents: ý định trong topic (tra cứu công nợ, báo cáo nợ xấu…)
• topic_prompts: prompt cho LLM theo từng bước
• topic_layouts: định dạng trả về (UI, API)
• multi-backend mapping: một topic có thể gọi đến nhiều backend (eTMS, eFMS, eWMS).
________________________________________
2.3. Router Configs
Xác định routing logic:
• Cách phân tích intent từ message
• Chọn backend nào để xử lý
• Chọn pipeline (retriever → LLM → post-processor)
Thuộc tính chính:
• intent_keywords, entity_patterns: keyword cho rule-based detection
• agent_mapping: mapping intent → agent
• backend_mapping: mapping intent → backend(s)
• confidence_threshold: fallback khi AI detection không đủ tin cậy
________________________________________
2.4. Agent Configs
Cấu hình model AI:
• llm_provider: OpenAI, Llama, Azure...
• llm_model: GPT-4, Llama-3, v.v.
• system_prompt, temperature, max_tokens
• Cho phép mỗi tenant chọn model khác nhau.
________________________________________
2.5. Pipeline
• Retriever: Lấy dữ liệu từ knowledge base hoặc backend API
• LLM: Sinh phản hồi dựa trên prompt + dữ liệu
• Post-processor: Format kết quả theo topic_layouts
________________________________________
2.6. Sessions & Message Logs
• sessions: Quản lý session của user
• message_logs: Lưu hội thoại, entity, intent, response time
________________________________________
3. Quy trình xử lý yêu cầu
1. Nhận Request
POST /api/<tenant>/<topic> hoặc GET /api/<tenant>/<topic>
2. Xác định Tenant + Topic
o Load config từ tenants, topics, topic_configs.
3. Routing & Intent Detection
o Dùng router_configs + AI model → xác định intent
o Mapping topic → backend(s)
4. RAG Pipeline
o Nếu pipeline có retriever → truy xuất dữ liệu
o Gọi LLM với prompt + dữ liệu
5. Post-processing
o Format kết quả theo topic_layouts
6. AI Interaction sau khi dữ liệu gốc đã được trả ra
o Người dùng có thể hỏi sâu mà không cần gọi lại backend.
o Hỗ trợ tóm tắt dữ liệu, giải thích, gợi ý phân tích.
o Query Rewriter: Tự động hiểu câu hỏi tiếp theo của user dựa trên kết quả trước.
o LLM Explainer: Giải thích dữ liệu bằng ngôn ngữ tự nhiên.
o Follow-up QA: Cho phép người dùng hỏi thêm mà không cần gọi lại backend.
o Data-to-Text: Chuyển dữ liệu dạng số/thống kê → đoạn văn tóm tắt.

7. Ghi log
o Lưu sessions + message_logs

4. Cấu hình RAG
Bổ sung bảng:
• collections: Tập dữ liệu cho từng tenant/topic
• documents: Lưu văn bản gốc
• embeddings: Vector embeddings để truy vấn
Pipeline:
User → Router → Retriever → LLM → Post-processor → Response
________________________________________


5. Kiến trúc tổng thể
[ Tenants ] --(Auth Keys)--> [ Dynamic Router ] --(Topic Mapping)--> [ RAG / APIs Layer ]
|
v
[ Post-Processing ]
|
v
[ AI Interaction Layer ]
|
v
[ User Output UI ] ________________________________________
6. Ưu điểm kiến trúc mới
• Dynamic & Config-driven: Thêm topic/intent/backend mà không cần deploy lại.
• Multi-tenant: Mỗi tenant có thể chọn model & pipeline riêng.
• Multi-backend: Một topic có thể gọi nhiều hệ thống backend khác nhau.
• RAG-ready: Dễ dàng tích hợp knowledge base.
• Scalable: Mở rộng nhiều agent & pipeline phức tạp.
• Version control: Prompts & config có thể versioned.

- Initial Deployment

Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +417 -18
  3. prompts.txt +111 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Chatbot Dynamic Routing Rag
3
- emoji: 🚀
4
- colorFrom: purple
5
- colorTo: indigo
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: chatbot-dynamic-routing-rag
3
+ emoji: 🐳
4
+ colorFrom: pink
5
+ colorTo: red
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,418 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
+ <!DOCTYPE html>
2
+ <html lang="vi">
3
+ <head>
4
+ <meta charset="UTF-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
6
+ <title>Kiến trúc Hệ thống Chatbot Multi-Tenant</title>
7
+ <link rel="icon" type="image/x-icon" href="/static/favicon.ico">
8
+ <script src="https://cdn.tailwindcss.com"></script>
9
+ <link href="https://unpkg.com/aos@2.3.1/dist/aos.css" rel="stylesheet">
10
+ <script src="https://unpkg.com/aos@2.3.1/dist/aos.js"></script>
11
+ <script src="https://cdn.jsdelivr.net/npm/feather-icons/dist/feather.min.js"></script>
12
+ <script src="https://unpkg.com/feather-icons"></script>
13
+ <script src="https://cdn.jsdelivr.net/npm/vanta@latest/dist/vanta.globe.min.js"></script>
14
+ <style>
15
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');
16
+
17
+ body {
18
+ font-family: 'Inter', sans-serif;
19
+ scroll-behavior: smooth;
20
+ }
21
+
22
+ .hero-gradient {
23
+ background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
24
+ }
25
+
26
+ .section-gradient {
27
+ background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
28
+ }
29
+
30
+ .feature-card:hover {
31
+ transform: translateY(-5px);
32
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
33
+ }
34
+
35
+ .architecture-diagram {
36
+ background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
37
+ }
38
+
39
+ .process-step {
40
+ transition: all 0.3s ease;
41
+ }
42
+
43
+ .process-step:hover {
44
+ transform: scale(1.05);
45
+ }
46
+ </style>
47
+ </head>
48
+ <body class="bg-gray-50">
49
+ <!-- Hero Section -->
50
+ <section id="hero" class="min-h-screen flex items-center justify-center relative overflow-hidden">
51
+ <div id="vanta-bg" class="absolute inset-0 z-0"></div>
52
+ <div class="container mx-auto px-6 py-20 relative z-10">
53
+ <div class="text-center text-white" data-aos="fade-down" data-aos-duration="1000">
54
+ <h1 class="text-4xl md:text-6xl font-bold mb-6">Kiến trúc Hệ thống Chatbot Multi-Tenant</h1>
55
+ <p class="text-xl md:text-2xl mb-8">Dynamic Routing & RAG Integration</p>
56
+ <div class="flex justify-center gap-4">
57
+ <a href="#architecture" class="bg-white text-purple-700 px-6 py-3 rounded-lg font-semibold hover:bg-gray-100 transition">Xem Kiến trúc</a>
58
+ <a href="#features" class="border-2 border-white text-white px-6 py-3 rounded-lg font-semibold hover:bg-white hover:text-purple-700 transition">Tính năng</a>
59
+ </div>
60
+ </div>
61
+ </div>
62
+ </section>
63
+
64
+ <!-- System Goals Section -->
65
+ <section id="goals" class="py-20 bg-white">
66
+ <div class="container mx-auto px-6">
67
+ <div class="text-center mb-16" data-aos="fade-up">
68
+ <h2 class="text-3xl md:text-4xl font-bold text-gray-800 mb-4">Mục tiêu Hệ thống</h2>
69
+ <p class="text-xl text-gray-600">Hỗ trợ Multi-Tenant với khả năng cấu hình động mạnh mẽ</p>
70
+ </div>
71
+
72
+ <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
73
+ <div class="feature-card bg-gray-50 p-8 rounded-xl shadow-md border border-gray-100" data-aos="fade-up" data-aos-delay="100">
74
+ <div class="text-blue-500 mb-4">
75
+ <i data-feather="settings" class="w-12 h-12"></i>
76
+ </div>
77
+ <h3 class="text-xl font-semibold mb-3">Cấu hình Động</h3>
78
+ <p class="text-gray-600">Thêm/sửa topic, intent, prompt, backend mà không cần deploy lại hệ thống</p>
79
+ </div>
80
+
81
+ <div class="feature-card bg-gray-50 p-8 rounded-xl shadow-md border border-gray-100" data-aos="fade-up" data-aos-delay="200">
82
+ <div class="text-green-500 mb-4">
83
+ <i data-feather="database" class="w-12 h-12"></i>
84
+ </div>
85
+ <h3 class="text-xl font-semibold mb-3">RAG Integration</h3>
86
+ <p class="text-gray-600">Truy xuất dữ liệu từ API backend và knowledge base nội bộ</p>
87
+ </div>
88
+
89
+ <div class="feature-card bg-gray-50 p-8 rounded-xl shadow-md border border-gray-100" data-aos="fade-up" data-aos-delay="300">
90
+ <div class="text-purple-500 mb-4">
91
+ <i data-feather="archive" class="w-12 h-12"></i>
92
+ </div>
93
+ <h3 class="text-xl font-semibold mb-3">Logging & Analytics</h3>
94
+ <p class="text-gray-600">Lưu trữ đầy đủ session & message logs để training và phân tích</p>
95
+ </div>
96
+ </div>
97
+ </div>
98
+ </section>
99
+
100
+ <!-- Architecture Overview -->
101
+ <section id="architecture" class="py-20 architecture-diagram text-white">
102
+ <div class="container mx-auto px-6">
103
+ <div class="text-center mb-16" data-aos="fade-up">
104
+ <h2 class="text-3xl md:text-4xl font-bold mb-4">Kiến trúc Tổng thể</h2>
105
+ <p class="text-xl">Dynamic Routing & Multi-Tenant Architecture</p>
106
+ </div>
107
+
108
+ <div class="relative" data-aos="zoom-in">
109
+ <div class="grid grid-cols-1 md:grid-cols-5 gap-6 items-center">
110
+ <!-- Tenants -->
111
+ <div class="bg-white/20 p-6 rounded-lg text-center backdrop-blur-sm">
112
+ <i data-feather="users" class="w-10 h-10 mx-auto mb-4"></i>
113
+ <h3 class="font-semibold">Tenants</h3>
114
+ <p class="text-sm mt-2">Khách hàng/Tổ chức</p>
115
+ </div>
116
+
117
+ <!-- Arrow -->
118
+ <div class="hidden md:flex justify-center">
119
+ <i data-feather="arrow-right" class="w-8 h-8"></i>
120
+ </div>
121
+ <div class="md:hidden flex justify-center py-4">
122
+ <i data-feather="arrow-down" class="w-8 h-8"></i>
123
+ </div>
124
+
125
+ <!-- Dynamic Router -->
126
+ <div class="bg-white/20 p-6 rounded-lg text-center backdrop-blur-sm">
127
+ <i data-feather="navigation" class="w-10 h-10 mx-auto mb-4"></i>
128
+ <h3 class="font-semibold">Dynamic Router</h3>
129
+ <p class="text-sm mt-2">Topic Mapping</p>
130
+ </div>
131
+
132
+ <!-- Arrow -->
133
+ <div class="hidden md:flex justify-center">
134
+ <i data-feather="arrow-right" class="w-8 h-8"></i>
135
+ </div>
136
+ <div class="md:hidden flex justify-center py-4">
137
+ <i data-feather="arrow-down" class="w-8 h-8"></i>
138
+ </div>
139
+
140
+ <!-- RAG/APIs Layer -->
141
+ <div class="bg-white/20 p-6 rounded-lg text-center backdrop-blur-sm">
142
+ <i data-feather="layers" class="w-10 h-10 mx-auto mb-4"></i>
143
+ <h3 class="font-semibold">RAG/APIs Layer</h3>
144
+ <p class="text-sm mt-2">Data Retrieval</p>
145
+ </div>
146
+
147
+ <!-- Arrow -->
148
+ <div class="hidden md:flex justify-center">
149
+ <i data-feather="arrow-right" class="w-8 h-8"></i>
150
+ </div>
151
+ <div class="md:hidden flex justify-center py-4">
152
+ <i data-feather="arrow-down" class="w-8 h-8"></i>
153
+ </div>
154
+
155
+ <!-- Post-Processing -->
156
+ <div class="bg-white/20 p-6 rounded-lg text-center backdrop-blur-sm">
157
+ <i data-feather="cpu" class="w-10 h-10 mx-auto mb-4"></i>
158
+ <h3 class="font-semibold">Post-Processing</h3>
159
+ <p class="text-sm mt-2">Data Formatting</p>
160
+ </div>
161
+
162
+ <!-- Arrow -->
163
+ <div class="hidden md:flex justify-center">
164
+ <i data-feather="arrow-right" class="w-8 h-8"></i>
165
+ </div>
166
+ <div class="md:hidden flex justify-center py-4">
167
+ <i data-feather="arrow-down" class="w-8 h-8"></i>
168
+ </div>
169
+
170
+ <!-- AI Interaction -->
171
+ <div class="bg-white/20 p-6 rounded-lg text-center backdrop-blur-sm">
172
+ <i data-feather="message-circle" class="w-10 h-10 mx-auto mb-4"></i>
173
+ <h3 class="font-semibold">AI Interaction</h3>
174
+ <p class="text-sm mt-2">User Output</p>
175
+ </div>
176
+ </div>
177
+ </div>
178
+ </div>
179
+ </section>
180
+
181
+ <!-- Key Components -->
182
+ <section id="components" class="py-20 bg-gray-50">
183
+ <div class="container mx-auto px-6">
184
+ <div class="text-center mb-16" data-aos="fade-up">
185
+ <h2 class="text-3xl md:text-4xl font-bold text-gray-800 mb-4">Thành phần Chính</h2>
186
+ <p class="text-xl text-gray-600">Các module cốt lõi của hệ thống</p>
187
+ </div>
188
+
189
+ <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
190
+ <div class="bg-white p-6 rounded-xl shadow-md" data-aos="fade-up" data-aos-delay="100">
191
+ <div class="flex items-center mb-4">
192
+ <div class="bg-blue-100 p-3 rounded-lg">
193
+ <i data-feather="user-check" class="w-6 h-6 text-blue-600"></i>
194
+ </div>
195
+ <h3 class="text-lg font-semibold ml-4">Tenants</h3>
196
+ </div>
197
+ <p class="text-gray-600">Đại diện cho khách hàng hoặc tổ chức sử dụng hệ thống với cấu hình riêng biệt</p>
198
+ </div>
199
+
200
+ <div class="bg-white p-6 rounded-xl shadow-md" data-aos="fade-up" data-aos-delay="150">
201
+ <div class="flex items-center mb-4">
202
+ <div class="bg-green-100 p-3 rounded-lg">
203
+ <i data-feather="folder" class="w-6 h-6 text-green-600"></i>
204
+ </div>
205
+ <h3 class="text-lg font-semibold ml-4">Topics</h3>
206
+ </div>
207
+ <p class="text-gray-600">Chức năng hoặc chủ đề chatbot xử lý với config endpoint, intents, prompts</p>
208
+ </div>
209
+
210
+ <div class="bg-white p-6 rounded-xl shadow-md" data-aos="fade-up" data-aos-delay="200">
211
+ <div class="flex items-center mb-4">
212
+ <div class="bg-purple-100 p-3 rounded-lg">
213
+ <i data-feather="navigation" class="w-6 h-6 text-purple-600"></i>
214
+ </div>
215
+ <h3 class="text-lg font-semibold ml-4">Router Configs</h3>
216
+ </div>
217
+ <p class="text-gray-600">Xác định routing logic và mapping intent → backend với confidence threshold</p>
218
+ </div>
219
+
220
+ <div class="bg-white p-6 rounded-xl shadow-md" data-aos="fade-up" data-aos-delay="250">
221
+ <div class="flex items-center mb-4">
222
+ <div class="bg-yellow-100 p-3 rounded-lg">
223
+ <i data-feather="cpu" class="w-6 h-6 text-yellow-600"></i>
224
+ </div>
225
+ <h3 class="text-lg font-semibold ml-4">Agent Configs</h3>
226
+ </div>
227
+ <p class="text-gray-600">Cấu hình model AI với llm_provider, llm_model, system_prompt và parameters</p>
228
+ </div>
229
+
230
+ <div class="bg-white p-6 rounded-xl shadow-md" data-aos="fade-up" data-aos-delay="300">
231
+ <div class="flex items-center mb-4">
232
+ <div class="bg-red-100 p-3 rounded-lg">
233
+ <i data-feather="git-merge" class="w-6 h-6 text-red-600"></i>
234
+ </div>
235
+ <h3 class="text-lg font-semibold ml-4">Pipeline</h3>
236
+ </div>
237
+ <p class="text-gray-600">Retriever → LLM → Post-processor workflow để xử lý và format dữ liệu</p>
238
+ </div>
239
+
240
+ <div class="bg-white p-6 rounded-xl shadow-md" data-aos="fade-up" data-aos-delay="350">
241
+ <div class="flex items-center mb-4">
242
+ <div class="bg-indigo-100 p-3 rounded-lg">
243
+ <i data-feather="database" class="w-6 h-6 text-indigo-600"></i>
244
+ </div>
245
+ <h3 class="text-lg font-semibold ml-4">Sessions & Logs</h3>
246
+ </div>
247
+ <p class="text-gray-600">Quản lý session và lưu trữ hội thoại, entity, intent, response time</p>
248
+ </div>
249
+ </div>
250
+ </div>
251
+ </section>
252
+
253
+ <!-- Process Flow -->
254
+ <section id="process" class="py-20 bg-white">
255
+ <div class="container mx-auto px-6">
256
+ <div class="text-center mb-16" data-aos="fade-up">
257
+ <h2 class="text-3xl md:text-4xl font-bold text-gray-800 mb-4">Quy trình Xử lý Yêu cầu</h2>
258
+ <p class="text-xl text-gray-600">7 bước xử lý từ request đến response</p>
259
+ </div>
260
+
261
+ <div class="grid md:grid-cols-7 gap-4">
262
+ <div class="process-step bg-blue-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="100">
263
+ <div class="bg-blue-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
264
+ <span class="font-bold">1</span>
265
+ </div>
266
+ <h3 class="font-semibold text-sm mb-1">Nhận Request</h3>
267
+ <p class="text-xs text-gray-600">POST/GET API</p>
268
+ </div>
269
+
270
+ <div class="process-step bg-green-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="150">
271
+ <div class="bg-green-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
272
+ <span class="font-bold">2</span>
273
+ </div>
274
+ <h3 class="font-semibold text-sm mb-1">Xác định Tenant + Topic</h3>
275
+ <p class="text-xs text-gray-600">Load config</p>
276
+ </div>
277
+
278
+ <div class="process-step bg-purple-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="200">
279
+ <div class="bg-purple-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
280
+ <span class="font-bold">3</span>
281
+ </div>
282
+ <h3 class="font-semibold text-sm mb-1">Routing & Intent Detection</h3>
283
+ <p class="text-xs text-gray-600">AI + Rule-based</p>
284
+ </div>
285
+
286
+ <div class="process-step bg-yellow-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="250">
287
+ <div class="bg-yellow-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
288
+ <span class="font-bold">4</span>
289
+ </div>
290
+ <h3 class="font-semibold text-sm mb-1">RAG Pipeline</h3>
291
+ <p class="text-xs text-gray-600">Retriever → LLM</p>
292
+ </div>
293
+
294
+ <div class="process-step bg-red-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="300">
295
+ <div class="bg-red-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
296
+ <span class="font-bold">5</span>
297
+ </div>
298
+ <h3 class="font-semibold text-sm mb-1">Post-processing</h3>
299
+ <p class="text-xs text-gray-600">Format kết quả</p>
300
+ </div>
301
+
302
+ <div class="process-step bg-indigo-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="350">
303
+ <div class="bg-indigo-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
304
+ <span class="font-bold">6</span>
305
+ </div>
306
+ <h3 class="font-semibold text-sm mb-1">AI Interaction</h3>
307
+ <p class="text-xs text-gray-600">Follow-up QA</p>
308
+ </div>
309
+
310
+ <div class="process-step bg-gray-50 p-4 rounded-lg text-center" data-aos="fade-up" data-aos-delay="400">
311
+ <div class="bg-gray-500 text-white rounded-full w-10 h-10 flex items-center justify-center mx-auto mb-2">
312
+ <span class="font-bold">7</span>
313
+ </div>
314
+ <h3 class="font-semibold text-sm mb-1">Ghi log</h3>
315
+ <p class="text-xs text-gray-600">Sessions + message_logs</p>
316
+ </div>
317
+ </div>
318
+ </div>
319
+ </section>
320
+
321
+ <!-- Benefits Section -->
322
+ <section id="benefits" class="py-20 section-gradient text-white">
323
+ <div class="container mx-auto px-6">
324
+ <div class="text-center mb-16" data-aos="fade-up">
325
+ <h2 class="text-3xl md:text-4xl font-bold mb-4">Ưu điểm Kiến trúc</h2>
326
+ <p class="text-xl">Dynamic, Multi-Tenant, Scalable & RAG-ready</p>
327
+ </div>
328
+
329
+ <div class="grid md:grid-cols-2 lg:grid-cols-3 gap-8">
330
+ <div class="bg-white/10 p-6 rounded-xl backdrop-blur-sm" data-aos="fade-up" data-aos-delay="100">
331
+ <i data-feather="refresh-cw" class="w-10 h-10 mb-4"></i>
332
+ <h3 class="text-xl font-semibold mb-3">Dynamic & Config-driven</h3>
333
+ <p>Thêm topic/intent/backend mà không cần deploy lại hệ thống</p>
334
+ </div>
335
+
336
+ <div class="bg-white/10 p-6 rounded-xl backdrop-blur-sm" data-aos="fade-up" data-aos-delay="200">
337
+ <i data-feather="users" class="w-10 h-10 mb-4"></i>
338
+ <h3 class="text-xl font-semibold mb-3">Multi-tenant</h3>
339
+ <p>Mỗi tenant có thể chọn model & pipeline riêng biệt</p>
340
+ </div>
341
+
342
+ <div class="bg-white/10 p-6 rounded-xl backdrop-blur-sm" data-aos="fade-up" data-aos-delay="300">
343
+ <i data-feather="server" class="w-10 h-10 mb-4"></i>
344
+ <h3 class="text-xl font-semibold mb-3">Multi-backend</h3>
345
+ <p>Một topic có thể gọi nhiều hệ thống backend khác nhau</p>
346
+ </div>
347
+
348
+ <div class="bg-white/10 p-6 rounded-xl backdrop-blur-sm" data-aos="fade-up" data-aos-delay="400">
349
+ <i data-feather="database" class="w-10 h-10 mb-4"></i>
350
+ <h3 class="text-xl font-semibold mb-3">RAG-ready</h3>
351
+ <p>Dễ dàng tích hợp knowledge base và vector search</p>
352
+ </div>
353
+
354
+ <div class="bg-white/10 p-6 rounded-xl backdrop-blur-sm" data-aos="fade-up" data-aos-delay="500">
355
+ <i data-feather="trending-up" class="w-10 h-10 mb-4"></i>
356
+ <h3 class="text-xl font-semibold mb-3">Scalable</h3>
357
+ <p>Mở rộng nhiều agent & pipeline phức tạp</p>
358
+ </div>
359
+
360
+ <div class="bg-white/10 p-6 rounded-xl backdrop-blur-sm" data-aos="fade-up" data-aos-delay="600">
361
+ <i data-feather="git-branch" class="w-10 h-10 mb-4"></i>
362
+ <h3 class="text-xl font-semibold mb-3">Version Control</h3>
363
+ <p>Prompts & config có thể versioned và quản lý</p>
364
+ </div>
365
+ </div>
366
+ </div>
367
+ </section>
368
+
369
+ <!-- Footer -->
370
+ <footer class="bg-gray-900 text-white py-12">
371
+ <div class="container mx-auto px-6">
372
+ <div class="text-center">
373
+ <h3 class="text-2xl font-bold mb-4">Kiến trúc Hệ thống Chatbot Multi-Tenant</h3>
374
+ <p class="text-gray-400 mb-6">Dynamic Routing & RAG Integration</p>
375
+ <div class="flex justify-center space-x-4">
376
+ <a href="#" class="text-gray-400 hover:text-white transition">
377
+ <i data-feather="github" class="w-6 h-6"></i>
378
+ </a>
379
+ <a href="#" class="text-gray-400 hover:text-white transition">
380
+ <i data-feather="twitter" class="w-6 h-6"></i>
381
+ </a>
382
+ <a href="#" class="text-gray-400 hover:text-white transition">
383
+ <i data-feather="linkedin" class="w-6 h-6"></i>
384
+ </a>
385
+ </div>
386
+ </div>
387
+ <div class="border-t border-gray-800 mt-8 pt-8 text-center text-gray-400">
388
+ <p>&copy; 2023 Chatbot Architecture. All rights reserved.</p>
389
+ </div>
390
+ </div>
391
+ </footer>
392
+
393
+ <script>
394
+ // Initialize AOS
395
+ AOS.init({
396
+ duration: 1000,
397
+ once: true
398
+ });
399
+
400
+ // Initialize Feather Icons
401
+ feather.replace();
402
+
403
+ // Initialize Vanta.js
404
+ VANTA.GLOBE({
405
+ el: "#vanta-bg",
406
+ mouseControls: true,
407
+ touchControls: true,
408
+ gyroControls: false,
409
+ minHeight: 200.00,
410
+ minWidth: 200.00,
411
+ scale: 1.00,
412
+ scaleMobile: 1.00,
413
+ color: 0x3f51b5,
414
+ backgroundColor: 0x0
415
+ });
416
+ </script>
417
+ </body>
418
  </html>
prompts.txt ADDED
@@ -0,0 +1,111 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Kiến trúc Hệ thống Chatbot Multi-Tenant với Dynamic Routing & RAG
2
+ 1. Mục tiêu hệ thống
3
+ • Hỗ trợ Multi-Tenant với khả năng cấu hình động cho:
4
+ o Topics (chủ đề)
5
+ o Intents (ý định)
6
+ o Routing rules (luồng xử lý)
7
+ o LLM models, RAG pipelines
8
+ o Backend endpoints (eFMS, eTMS, eWMS…)
9
+ • Cho phép thêm/sửa topic, intent, prompt, backend mà không cần deploy lại.
10
+ • Hỗ trợ RAG (Retrieval-Augmented Generation) để truy xuất dữ liệu từ:
11
+ o API backend
12
+ o Knowledge base nội bộ
13
+ • Lưu trữ đầy đủ session & message logs để training và phân tích.
14
+ ________________________________________
15
+ 2. Thành phần chính
16
+ 2.1. Tenants
17
+ • Đại diện cho khách hàng hoặc tổ chức sử dụng hệ thống.
18
+ • Mỗi tenant có:
19
+ o Danh sách topics
20
+ o Cấu hình routing, agent, pipeline
21
+ o Dữ liệu RAG knowledge base
22
+ o Danh sách backend có thể sử dụng
23
+ ________________________________________
24
+ 2.2. Topics
25
+ Mỗi topic đại diện cho một chức năng hoặc chủ đề mà chatbot xử lý:
26
+ • topic_configs: config endpoint, method, headers, mapping request/response
27
+ • intents: ý định trong topic (tra cứu công nợ, báo cáo nợ xấu…)
28
+ • topic_prompts: prompt cho LLM theo từng bước
29
+ • topic_layouts: định dạng trả về (UI, API)
30
+ • multi-backend mapping: một topic có thể gọi đến nhiều backend (eTMS, eFMS, eWMS).
31
+ ________________________________________
32
+ 2.3. Router Configs
33
+ Xác định routing logic:
34
+ • Cách phân tích intent từ message
35
+ • Chọn backend nào để xử lý
36
+ • Chọn pipeline (retriever → LLM → post-processor)
37
+ Thuộc tính chính:
38
+ • intent_keywords, entity_patterns: keyword cho rule-based detection
39
+ • agent_mapping: mapping intent → agent
40
+ • backend_mapping: mapping intent → backend(s)
41
+ • confidence_threshold: fallback khi AI detection không đủ tin cậy
42
+ ________________________________________
43
+ 2.4. Agent Configs
44
+ Cấu hình model AI:
45
+ • llm_provider: OpenAI, Llama, Azure...
46
+ • llm_model: GPT-4, Llama-3, v.v.
47
+ • system_prompt, temperature, max_tokens
48
+ • Cho phép mỗi tenant chọn model khác nhau.
49
+ ________________________________________
50
+ 2.5. Pipeline
51
+ • Retriever: Lấy dữ liệu từ knowledge base hoặc backend API
52
+ • LLM: Sinh phản hồi dựa trên prompt + dữ liệu
53
+ • Post-processor: Format kết quả theo topic_layouts
54
+ ________________________________________
55
+ 2.6. Sessions & Message Logs
56
+ • sessions: Quản lý session của user
57
+ • message_logs: Lưu hội thoại, entity, intent, response time
58
+ ________________________________________
59
+ 3. Quy trình xử lý yêu cầu
60
+ 1. Nhận Request
61
+ POST /api/<tenant>/<topic> hoặc GET /api/<tenant>/<topic>
62
+ 2. Xác định Tenant + Topic
63
+ o Load config từ tenants, topics, topic_configs.
64
+ 3. Routing & Intent Detection
65
+ o Dùng router_configs + AI model → xác định intent
66
+ o Mapping topic → backend(s)
67
+ 4. RAG Pipeline
68
+ o Nếu pipeline có retriever → truy xuất dữ liệu
69
+ o Gọi LLM với prompt + dữ liệu
70
+ 5. Post-processing
71
+ o Format kết quả theo topic_layouts
72
+ 6. AI Interaction sau khi dữ liệu gốc đã được trả ra
73
+ o Người dùng có thể hỏi sâu mà không cần gọi lại backend.
74
+ o Hỗ trợ tóm tắt dữ liệu, giải thích, gợi ý phân tích.
75
+ o Query Rewriter: Tự động hiểu câu hỏi tiếp theo của user dựa trên kết quả trước.
76
+ o LLM Explainer: Giải thích dữ liệu bằng ngôn ngữ tự nhiên.
77
+ o Follow-up QA: Cho phép người dùng hỏi thêm mà không cần gọi lại backend.
78
+ o Data-to-Text: Chuyển dữ liệu dạng số/thống kê → đoạn văn tóm tắt.
79
+
80
+ 7. Ghi log
81
+ o Lưu sessions + message_logs
82
+
83
+ 4. Cấu hình RAG
84
+ Bổ sung bảng:
85
+ • collections: Tập dữ liệu cho từng tenant/topic
86
+ • documents: Lưu văn bản gốc
87
+ • embeddings: Vector embeddings để truy vấn
88
+ Pipeline:
89
+ User → Router → Retriever → LLM → Post-processor → Response
90
+ ________________________________________
91
+
92
+
93
+ 5. Kiến trúc tổng thể
94
+ [ Tenants ] --(Auth Keys)--> [ Dynamic Router ] --(Topic Mapping)--> [ RAG / APIs Layer ]
95
+ |
96
+ v
97
+ [ Post-Processing ]
98
+ |
99
+ v
100
+ [ AI Interaction Layer ]
101
+ |
102
+ v
103
+ [ User Output UI ] ________________________________________
104
+ 6. Ưu điểm kiến trúc mới
105
+ • Dynamic & Config-driven: Thêm topic/intent/backend mà không cần deploy lại.
106
+ • Multi-tenant: Mỗi tenant có thể chọn model & pipeline riêng.
107
+ • Multi-backend: Một topic có thể gọi nhiều hệ thống backend khác nhau.
108
+ • RAG-ready: Dễ dàng tích hợp knowledge base.
109
+ • Scalable: Mở rộng nhiều agent & pipeline phức tạp.
110
+ • Version control: Prompts & config có thể versioned.
111
+