Web app chatbot hỏi–đáp tài liệu học tập theo cơ chế RAG (Retrieval-Augmented Generation): sinh viên hỏi, hệ thống truy xuất đúng đoạn tài liệu đã index rồi để LLM trả lời có trích dẫn nguồn và chỉ trong phạm vi tài liệu. Kèm một Module nghiên cứu (RBL) để benchmark RAG vs Fine-tuned, các chiến lược chunking và các model embedding.
llama-3.3-70b-versatile (OpenAI-compatible API)sentence-transformers cho các model mở (e5 / bge-m3 / PhoBERT)DocumentChunks.VectorJson).Local (hashing), multilingual-e5-base, PhoBERT-base, bge-m3 (chạy offline), text-embedding-3-small (cần OpenAI key) — đo cosine retrieval + độ trễ.PresentationLayer (Razor Pages, Controllers API, SignalR Hubs, EmbeddingSidecarLauncher)
│ gọi
ServiceLayer (ChatService, DocumentService, ChunkingService, RetrievalService,
│ GroqService, các *ComparisonService của RBL, BillingService, ReportService,
│ Embeddings/{Local, LocalST, HuggingFace, OpenAI}EmbeddingProvider)
│ gọi
DataAccessLayer (AppDbContext + Repositories, EF Core → SQL Server)
Chi tiết sơ đồ: xem docs/architecture.md.
Luồng RAG: Upload → trích xuất text → chunk → embed → lưu DocumentChunks. Hỏi → RetrievalService truy xuất top-K chunk (keyword + cosine) → GroqService dựng prompt grounded → LLM trả lời + citations.
admin / mật khẩu 123, DB ChatBotPRN222 (tự tạo khi chạy lần đầu qua EnsureCreated + SQL idempotent)PresentationLayer/appsettings.json (đã .gitignore — tự điền giá trị thật):
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=ChatBotPRN222;User Id=admin;Password=123;TrustServerCertificate=True;"
},
"Groq": { "ApiKey": "gsk_...", "Model": "llama-3.3-70b-versatile", "BaseUrl": "https://api.groq.com/openai/v1" },
"Email": { "SmtpHost": "smtp.gmail.com", "SmtpPort": 587, "FromEmail": "you@gmail.com", "AppPassword": "..." },
"Embedding": { "AutoStartSidecar": true, "SidecarPort": 8600 }
}
Cài đặt RBL (chiến lược chunk, model embedding, key OpenAI/HuggingFace) chỉnh trong app tại Giám sát hệ thống → Cài đặt RBL (lưu vào bảng SystemSettings).
cd PresentationLayer
dotnet run
→ http://localhost:5300 · HTTPS: https://localhost:7300
App tự khởi động sidecar embedding (tools/embedding_server.py) khi chạy — lần đầu tự tải model (~vài GB); tắt tính năng bằng "Embedding:AutoStartSidecar": false.
Nếu build báo
file locked by "PresentationLayer (pid)"→ đang có 1 instance chạy, ấn Ctrl+C hoặctaskkill /F /IM PresentationLayer.exerồi chạy lại.
App tự bật; nếu muốn chạy tay:
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -r tools/requirements.txt
python tools/embedding_server.py # http://127.0.0.1:8600
| Vai trò | Tài khoản | Mật khẩu |
|---|---|---|
| Admin | admin | admin123 |
(Giảng viên/Sinh viên tạo trong Quản lý người dùng.)
TestSet_50cau_GroundTruth.xlsx — 50 câu hỏi + câu trả lời đúng do con người soạn (cột: STT · Mã môn · Chủ đề · Câu hỏi · Ground Truth · Tài liệu nguồn).
Chấm độ chính xác (accuracy) bằng LLM-as-judge:
cd eval
pip install -r requirements.txt
python evaluate_chatbot.py --base-url http://localhost:5300 # xuất Eval_Results.xlsx
Đo các chỉ số RAG chuyên biệt (faithfulness, answer relevancy, context precision, context recall) — dùng Groq làm judge + embedding local, không cần OpenAI key:
cd eval
pip install -r ragas_requirements.txt
python ragas_benchmark.py # xuất RAGAS_Results.xlsx + RAGAS_Results.md
Kết quả tóm tắt: xem docs/BaoCao_ThucNghiem_RBL.md.
Tổng hợp so sánh chunking / embedding / RAG-vs-FT + bảng RAGAS + nhận xét: docs/BaoCao_ThucNghiem_RBL.md.
PresentationLayer/ # Razor Pages, Controllers API, Hubs, Program.cs, EmbeddingSidecarLauncher
ServiceLayer/ # nghiệp vụ: Chat/Document/Chunking/Retrieval/Groq + RBL comparison + Embeddings
DataAccessLayer/ # EF Core: AppDbContext, Entities, Repositories
tools/ # embedding_server.py (sidecar), requirements.txt, start_embedding_server.bat
eval/ # evaluate_chatbot.py (accuracy), ragas_benchmark.py (RAGAS), test scripts
docs/ # architecture.md/svg, BaoCao_ThucNghiem_RBL.md
TestSet_50cau_GroundTruth.xlsx
C#
57.8%
HTML
30.2%
Python
4.2%
TSQL
3.7%
CSS
3.4%
Web app chatbot hỏi–đáp tài liệu học tập theo cơ chế RAG (Retrieval-Augmented Generation): sinh viên hỏi, hệ thống truy xuất đúng đoạn tài liệu đã index rồi để LLM trả lời có trích dẫn nguồn và chỉ trong phạm vi tài liệu. Kèm một Module nghiên cứu (RBL) để benchmark RAG vs Fine-tuned, các chiến lược chunking và các model embedding.
llama-3.3-70b-versatile (OpenAI-compatible API)sentence-transformers cho các model mở (e5 / bge-m3 / PhoBERT)DocumentChunks.VectorJson).Local (hashing), multilingual-e5-base, PhoBERT-base, bge-m3 (chạy offline), text-embedding-3-small (cần OpenAI key) — đo cosine retrieval + độ trễ.PresentationLayer (Razor Pages, Controllers API, SignalR Hubs, EmbeddingSidecarLauncher)
│ gọi
ServiceLayer (ChatService, DocumentService, ChunkingService, RetrievalService,
│ GroqService, các *ComparisonService của RBL, BillingService, ReportService,
│ Embeddings/{Local, LocalST, HuggingFace, OpenAI}EmbeddingProvider)
│ gọi
DataAccessLayer (AppDbContext + Repositories, EF Core → SQL Server)
Chi tiết sơ đồ: xem docs/architecture.md.
Luồng RAG: Upload → trích xuất text → chunk → embed → lưu DocumentChunks. Hỏi → RetrievalService truy xuất top-K chunk (keyword + cosine) → GroqService dựng prompt grounded → LLM trả lời + citations.
admin / mật khẩu 123, DB ChatBotPRN222 (tự tạo khi chạy lần đầu qua EnsureCreated + SQL idempotent)PresentationLayer/appsettings.json (đã .gitignore — tự điền giá trị thật):
{
"ConnectionStrings": {
"DefaultConnection": "Server=localhost;Database=ChatBotPRN222;User Id=admin;Password=123;TrustServerCertificate=True;"
},
"Groq": { "ApiKey": "gsk_...", "Model": "llama-3.3-70b-versatile", "BaseUrl": "https://api.groq.com/openai/v1" },
"Email": { "SmtpHost": "smtp.gmail.com", "SmtpPort": 587, "FromEmail": "you@gmail.com", "AppPassword": "..." },
"Embedding": { "AutoStartSidecar": true, "SidecarPort": 8600 }
}
Cài đặt RBL (chiến lược chunk, model embedding, key OpenAI/HuggingFace) chỉnh trong app tại Giám sát hệ thống → Cài đặt RBL (lưu vào bảng SystemSettings).
cd PresentationLayer
dotnet run
→ http://localhost:5300 · HTTPS: https://localhost:7300
App tự khởi động sidecar embedding (tools/embedding_server.py) khi chạy — lần đầu tự tải model (~vài GB); tắt tính năng bằng "Embedding:AutoStartSidecar": false.
Nếu build báo
file locked by "PresentationLayer (pid)"→ đang có 1 instance chạy, ấn Ctrl+C hoặctaskkill /F /IM PresentationLayer.exerồi chạy lại.
App tự bật; nếu muốn chạy tay:
pip install torch --index-url https://download.pytorch.org/whl/cpu
pip install -r tools/requirements.txt
python tools/embedding_server.py # http://127.0.0.1:8600
| Vai trò | Tài khoản | Mật khẩu |
|---|---|---|
| Admin | admin | admin123 |
(Giảng viên/Sinh viên tạo trong Quản lý người dùng.)
TestSet_50cau_GroundTruth.xlsx — 50 câu hỏi + câu trả lời đúng do con người soạn (cột: STT · Mã môn · Chủ đề · Câu hỏi · Ground Truth · Tài liệu nguồn).
Chấm độ chính xác (accuracy) bằng LLM-as-judge:
cd eval
pip install -r requirements.txt
python evaluate_chatbot.py --base-url http://localhost:5300 # xuất Eval_Results.xlsx
Đo các chỉ số RAG chuyên biệt (faithfulness, answer relevancy, context precision, context recall) — dùng Groq làm judge + embedding local, không cần OpenAI key:
cd eval
pip install -r ragas_requirements.txt
python ragas_benchmark.py # xuất RAGAS_Results.xlsx + RAGAS_Results.md
Kết quả tóm tắt: xem docs/BaoCao_ThucNghiem_RBL.md.
Tổng hợp so sánh chunking / embedding / RAG-vs-FT + bảng RAGAS + nhận xét: docs/BaoCao_ThucNghiem_RBL.md.
PresentationLayer/ # Razor Pages, Controllers API, Hubs, Program.cs, EmbeddingSidecarLauncher
ServiceLayer/ # nghiệp vụ: Chat/Document/Chunking/Retrieval/Groq + RBL comparison + Embeddings
DataAccessLayer/ # EF Core: AppDbContext, Entities, Repositories
tools/ # embedding_server.py (sidecar), requirements.txt, start_embedding_server.bat
eval/ # evaluate_chatbot.py (accuracy), ragas_benchmark.py (RAGAS), test scripts
docs/ # architecture.md/svg, BaoCao_ThucNghiem_RBL.md
TestSet_50cau_GroundTruth.xlsx
C#
57.8%
HTML
30.2%
Python
4.2%
TSQL
3.7%
CSS
3.4%