PRN222 Assignment — Group 4 | SE1938
VietRAG là hệ thống chatbot hỏi đáp tài liệu môn học sử dụng RAG (Retrieval-Augmented Generation), cho phép sinh viên đặt câu hỏi và nhận câu trả lời chính xác, có trích dẫn nguồn dựa trên tài liệu được giảng viên upload. Đồng thời, hệ thống cung cấp bộ công cụ nghiên cứu và benchmark để so sánh hiệu quả giữa các embedding model trong bối cảnh tiếng Việt.
| Tính năng | Mô tả |
|---|---|
| 📄 Document Upload | Upload PDF, DOCX, PPTX — tự động trích xuất text, chunk và embed |
| 💬 RAG Chat | Hỏi đáp AI với trích dẫn nguồn tài liệu, giới hạn trong phạm vi môn học |
| 🔬 Embedding Benchmark | So sánh Gemini / multilingual-e5-base / bge-m3 / PhoBERT qua Precision@3, Recall@3, MRR |
| 📊 Dashboard | Biểu đồ kết quả benchmark theo thời gian thực |
| 🗂️ Lịch sử hội thoại | Lưu session, rename, xóa hội thoại |
| 🔐 Phân quyền | Admin (quản lý tất cả) / Teacher / Student |
| ⚙️ RAG Sandbox | Tùy chỉnh model, chunking strategy, chunk size, overlap theo từng truy vấn |
| Layer | Technology | Version |
|---|---|---|
| Frontend | ASP.NET Core MVC, Bootstrap 5, jQuery, SweetAlert2 | Bootstrap 5.3 |
| Backend | C# ASP.NET Core MVC | .NET 9 |
| Architecture | N-Tier (3 Layers) + Repository Pattern + DI | — |
| Database | SQL Server + Entity Framework Core | EF Core 9 |
| AI / LLM | Google Gemini 2.5 Flash | v1beta |
| Embedding | Gemini Embedding 001, HuggingFace Inference API | — |
| HF Models | multilingual-e5-base (768d), bge-m3 (1024d), PhoBERT-base (768d) | — |
| PDF Parsing | PdfPig | 0.1.9 |
| Auth | Cookie Authentication + SHA-256 password hashing | — |
┌─────────────────────────────────────────────────────┐
│ PresentationLayer (MVC) │
│ Controllers │ Views (Razor) │ ViewModels │ wwwroot │
└──────────────────────┬──────────────────────────────┘
│ injects IService interfaces
┌──────────────────────▼──────────────────────────────┐
│ BusinessLayer (Services) │
│ ChatService │ DocumentService │ GeminiService │
│ BenchmarkService │ UserService │ EmbeddingFactory │
└──────────────────────┬──────────────────────────────┘
│ injects IGenericRepository<T>
┌──────────────────────▼──────────────────────────────┐
│ DataAccessLayer (EF Core + Repos) │
│ GenericRepository<T> │ DbContext │ EF Migrations │
└─────────────────────────────────────────────────────┘
Để đảm bảo tính độc lập giữa các tầng theo chuẩn Enterprise Architecture:
Domain.Models / DataAccessLayer.Models).BusinessLayer/DTOs/.Để chatbot hoạt động chính xác dựa trên tài liệu học tập của bạn, hệ thống thực hiện hai bước xử lý cốt lõi:
git clone https://github.com/YOUR_USERNAME/VietRAG.git
cd VietRAG/Group4_SE1938_A01
Mở SQL Server Management Studio, chạy lệnh tạo DB:
CREATE DATABASE Prn222_assigment;
Sau đó apply migrations:
cd PresentationLayer
dotnet ef database update --project ../DataAccessLayer
Mở PresentationLayer/appsettings.json và điền:
{
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database=Prn222_assigment;User Id=sa;Password=YOUR_PASSWORD;TrustServerCertificate=True"
},
"GeminiSettings": {
"ApiKey": "YOUR_GEMINI_API_KEY",
"Model": "gemini-2.5-flash"
},
"HuggingFaceToken": "hf_YOUR_TOKEN"
}
cd PresentationLayer
dotnet run
Mở trình duyệt: http://localhost:5007
| Role | Mật khẩu | |
|---|---|---|
| Admin | admin@fpt.edu.vn | 123456789 |
Admin được tự động tạo khi app khởi động lần đầu.
Group4_SE1938_A01/
├── PresentationLayer/ # Tầng hiển thị (MVC)
│ ├── Controllers/
│ │ ├── AccountController.cs # Login, Register, User CRUD
│ │ ├── ChatController.cs # RAG Chat sessions
│ │ ├── DocumentController.cs # Upload, Index, Re-Index
│ │ └── BenchmarkController.cs # Benchmark Runner & Dashboard
│ ├── Views/
│ │ ├── Chat/ # Chat UI
│ │ ├── Document/ # Document management UI
│ │ └── Benchmark/ # Dashboard & metrics
│ ├── Models/ # ViewModels (LoginVM, RegisterVM...)
│ └── wwwroot/ # CSS, JS, static files
│
├── BusinessLayer/ # Tầng nghiệp vụ
│ ├── Interfaces/ # Service contracts (IUserService, IChatService...)
│ ├── Services/
│ │ ├── ChatService.cs # RAG retrieval pipeline
│ │ ├── DocumentService.cs # Chunking + Embedding indexing
│ │ ├── GeminiService.cs # LLM generation
│ │ ├── BenchmarkService.cs # RAGAS metrics computation
│ │ ├── Embedding/
│ │ │ ├── EmbeddingProviderFactory.cs
│ │ │ ├── HuggingFaceEmbeddingProvider.cs
│ │ │ ├── GeminiEmbeddingAdapter.cs
│ │ │ └── OpenAIEmbeddingProvider.cs
│ │ └── Chunking/
│ │ ├── FixedSizeChunker.cs
│ │ ├── SentenceChunker.cs
│ │ └── RecursiveChunker.cs
│ └── Helpers/
│ └── VectorHelper.cs # Cosine similarity
│
└── DataAccessLayer/ # Tầng dữ liệu
├── Models/ # EF Core entities + DbContext
├── Repository/
│ ├── IGenericRepository.cs
│ └── GenericRepository.cs
├── Seeds/
│ └── TestSet50Questions.json # 50 câu hỏi PRN212 benchmark
└── Migrations/ # EF Core migrations
| Metric | Ý nghĩa |
|---|---|
| Precision@3 | Trong top-3 chunks trả về, bao nhiêu % thực sự liên quan |
| Recall@3 | Tìm được bao nhiêu % ground truth chunks |
| MRR | Mean Reciprocal Rank — chunk đúng xuất hiện ở vị trí nào |
| Latency (ms) | Thời gian embedding + retrieval |
| Model | Dim | Precision@3 | Recall@3 | MRR | Latency |
|---|---|---|---|---|---|
| gemini-embedding-001 | 768 | — | — | — | — |
| multilingual-e5-base | 768 | — | — | — | — |
| bge-m3 | 1024 | — | — | — | — |
| PhoBERT-base | 768 | — | — | — | — |
Cập nhật sau khi chạy benchmark thực tế. Lưu ý: bge-m3 (1024d) không tương thích vector với Gemini (768d) — cần Re-Index riêng.
Mỗi embedding model tạo vector với số chiều khác nhau. Khi chat, query vector phải cùng chiều với chunk vectors trong DB. Nếu chọn model khác với model đã index → hệ thống tự động báo "Vui lòng Re-Index với model đang chọn".
User Question
→ Embed query (EmbeddingProviderFactory)
→ Cosine Similarity với chunks trong DB
→ Top-K retrieval (threshold 0.4)
→ Gemini 2.5 Flash (context + question)
→ Response với Citations
HuggingFace Inference API (api-inference.huggingface.co) cần kết nối internet trực tiếp. Nếu mạng trường/công ty block → cần VPN hoặc hotspot.
| Họ tên | MSSV | Role |
|---|---|---|
| Phạm Trí Tính | SE1938_xxx | Team Lead / Developer |
MIT License — Free for educational use.
C#
58.1%
HTML
39.8%
CSS
1.6%
PRN222 Assignment — Group 4 | SE1938
VietRAG là hệ thống chatbot hỏi đáp tài liệu môn học sử dụng RAG (Retrieval-Augmented Generation), cho phép sinh viên đặt câu hỏi và nhận câu trả lời chính xác, có trích dẫn nguồn dựa trên tài liệu được giảng viên upload. Đồng thời, hệ thống cung cấp bộ công cụ nghiên cứu và benchmark để so sánh hiệu quả giữa các embedding model trong bối cảnh tiếng Việt.
| Tính năng | Mô tả |
|---|---|
| 📄 Document Upload | Upload PDF, DOCX, PPTX — tự động trích xuất text, chunk và embed |
| 💬 RAG Chat | Hỏi đáp AI với trích dẫn nguồn tài liệu, giới hạn trong phạm vi môn học |
| 🔬 Embedding Benchmark | So sánh Gemini / multilingual-e5-base / bge-m3 / PhoBERT qua Precision@3, Recall@3, MRR |
| 📊 Dashboard | Biểu đồ kết quả benchmark theo thời gian thực |
| 🗂️ Lịch sử hội thoại | Lưu session, rename, xóa hội thoại |
| 🔐 Phân quyền | Admin (quản lý tất cả) / Teacher / Student |
| ⚙️ RAG Sandbox | Tùy chỉnh model, chunking strategy, chunk size, overlap theo từng truy vấn |
| Layer | Technology | Version |
|---|---|---|
| Frontend | ASP.NET Core MVC, Bootstrap 5, jQuery, SweetAlert2 | Bootstrap 5.3 |
| Backend | C# ASP.NET Core MVC | .NET 9 |
| Architecture | N-Tier (3 Layers) + Repository Pattern + DI | — |
| Database | SQL Server + Entity Framework Core | EF Core 9 |
| AI / LLM | Google Gemini 2.5 Flash | v1beta |
| Embedding | Gemini Embedding 001, HuggingFace Inference API | — |
| HF Models | multilingual-e5-base (768d), bge-m3 (1024d), PhoBERT-base (768d) | — |
| PDF Parsing | PdfPig | 0.1.9 |
| Auth | Cookie Authentication + SHA-256 password hashing | — |
┌─────────────────────────────────────────────────────┐
│ PresentationLayer (MVC) │
│ Controllers │ Views (Razor) │ ViewModels │ wwwroot │
└──────────────────────┬──────────────────────────────┘
│ injects IService interfaces
┌──────────────────────▼──────────────────────────────┐
│ BusinessLayer (Services) │
│ ChatService │ DocumentService │ GeminiService │
│ BenchmarkService │ UserService │ EmbeddingFactory │
└──────────────────────┬──────────────────────────────┘
│ injects IGenericRepository<T>
┌──────────────────────▼──────────────────────────────┐
│ DataAccessLayer (EF Core + Repos) │
│ GenericRepository<T> │ DbContext │ EF Migrations │
└─────────────────────────────────────────────────────┘
Để đảm bảo tính độc lập giữa các tầng theo chuẩn Enterprise Architecture:
Domain.Models / DataAccessLayer.Models).BusinessLayer/DTOs/.Để chatbot hoạt động chính xác dựa trên tài liệu học tập của bạn, hệ thống thực hiện hai bước xử lý cốt lõi:
git clone https://github.com/YOUR_USERNAME/VietRAG.git
cd VietRAG/Group4_SE1938_A01
Mở SQL Server Management Studio, chạy lệnh tạo DB:
CREATE DATABASE Prn222_assigment;
Sau đó apply migrations:
cd PresentationLayer
dotnet ef database update --project ../DataAccessLayer
Mở PresentationLayer/appsettings.json và điền:
{
"ConnectionStrings": {
"DefaultConnection": "Server=.;Database=Prn222_assigment;User Id=sa;Password=YOUR_PASSWORD;TrustServerCertificate=True"
},
"GeminiSettings": {
"ApiKey": "YOUR_GEMINI_API_KEY",
"Model": "gemini-2.5-flash"
},
"HuggingFaceToken": "hf_YOUR_TOKEN"
}
cd PresentationLayer
dotnet run
Mở trình duyệt: http://localhost:5007
| Role | Mật khẩu | |
|---|---|---|
| Admin | admin@fpt.edu.vn | 123456789 |
Admin được tự động tạo khi app khởi động lần đầu.
Group4_SE1938_A01/
├── PresentationLayer/ # Tầng hiển thị (MVC)
│ ├── Controllers/
│ │ ├── AccountController.cs # Login, Register, User CRUD
│ │ ├── ChatController.cs # RAG Chat sessions
│ │ ├── DocumentController.cs # Upload, Index, Re-Index
│ │ └── BenchmarkController.cs # Benchmark Runner & Dashboard
│ ├── Views/
│ │ ├── Chat/ # Chat UI
│ │ ├── Document/ # Document management UI
│ │ └── Benchmark/ # Dashboard & metrics
│ ├── Models/ # ViewModels (LoginVM, RegisterVM...)
│ └── wwwroot/ # CSS, JS, static files
│
├── BusinessLayer/ # Tầng nghiệp vụ
│ ├── Interfaces/ # Service contracts (IUserService, IChatService...)
│ ├── Services/
│ │ ├── ChatService.cs # RAG retrieval pipeline
│ │ ├── DocumentService.cs # Chunking + Embedding indexing
│ │ ├── GeminiService.cs # LLM generation
│ │ ├── BenchmarkService.cs # RAGAS metrics computation
│ │ ├── Embedding/
│ │ │ ├── EmbeddingProviderFactory.cs
│ │ │ ├── HuggingFaceEmbeddingProvider.cs
│ │ │ ├── GeminiEmbeddingAdapter.cs
│ │ │ └── OpenAIEmbeddingProvider.cs
│ │ └── Chunking/
│ │ ├── FixedSizeChunker.cs
│ │ ├── SentenceChunker.cs
│ │ └── RecursiveChunker.cs
│ └── Helpers/
│ └── VectorHelper.cs # Cosine similarity
│
└── DataAccessLayer/ # Tầng dữ liệu
├── Models/ # EF Core entities + DbContext
├── Repository/
│ ├── IGenericRepository.cs
│ └── GenericRepository.cs
├── Seeds/
│ └── TestSet50Questions.json # 50 câu hỏi PRN212 benchmark
└── Migrations/ # EF Core migrations
| Metric | Ý nghĩa |
|---|---|
| Precision@3 | Trong top-3 chunks trả về, bao nhiêu % thực sự liên quan |
| Recall@3 | Tìm được bao nhiêu % ground truth chunks |
| MRR | Mean Reciprocal Rank — chunk đúng xuất hiện ở vị trí nào |
| Latency (ms) | Thời gian embedding + retrieval |
| Model | Dim | Precision@3 | Recall@3 | MRR | Latency |
|---|---|---|---|---|---|
| gemini-embedding-001 | 768 | — | — | — | — |
| multilingual-e5-base | 768 | — | — | — | — |
| bge-m3 | 1024 | — | — | — | — |
| PhoBERT-base | 768 | — | — | — | — |
Cập nhật sau khi chạy benchmark thực tế. Lưu ý: bge-m3 (1024d) không tương thích vector với Gemini (768d) — cần Re-Index riêng.
Mỗi embedding model tạo vector với số chiều khác nhau. Khi chat, query vector phải cùng chiều với chunk vectors trong DB. Nếu chọn model khác với model đã index → hệ thống tự động báo "Vui lòng Re-Index với model đang chọn".
User Question
→ Embed query (EmbeddingProviderFactory)
→ Cosine Similarity với chunks trong DB
→ Top-K retrieval (threshold 0.4)
→ Gemini 2.5 Flash (context + question)
→ Response với Citations
HuggingFace Inference API (api-inference.huggingface.co) cần kết nối internet trực tiếp. Nếu mạng trường/công ty block → cần VPN hoặc hotspot.
| Họ tên | MSSV | Role |
|---|---|---|
| Phạm Trí Tính | SE1938_xxx | Team Lead / Developer |
MIT License — Free for educational use.
C#
58.1%
HTML
39.8%
CSS
1.6%