Skip to content
iZenDeveloperPublic
forked from BIN9721/Chatbot

About

Hệ thống RAG học tập song ngữ Việt-Anh — Docling + bge-m3 + Chroma + Hybrid Search + Reranker

Resources

Stars

0 stars

Watchers

0 watching

Forks

 
 

Latest commit

 

History

2 Commits

Folders and files

Repository files navigation

RAG Học Tập Song Ngữ Việt–Anh

Hệ thống RAG (Retrieval-Augmented Generation) cá nhân, học tập, chạy hoàn toàn miễn phí (local + free-tier API). Trả lời câu hỏi dựa trên một kho tài liệu song ngữ Việt–Anh về AI trong giáo dục và kỹ thuật RAG, có trích dẫn nguồn và cơ chế chống hallucination.

Báo cáo kỹ thuật đầy đủ: xem GHI-CHU.md — kiến trúc, phương pháp, số liệu đánh giá (Retrieval + Generation), hạn chế và hướng cải thiện, kèm giải thích khái niệm/thuật ngữ.

Kiến trúc

Trích xuất (Docling) → Chunking (section-based + document-aware + semantic) → Embedding (BAAI/bge-m3) → Vector DB (Chroma, HNSW) → Retrieval (Hybrid BM25+Dense → Reranker cross-encoder) → Prompt chống hallucination → Generation (Gemini/Groq) → Answer Verification.

Kết quả

Đo trên golden set 65 câu hỏi, corpus 62 tài liệu / 7.044 chunk (chi tiết đầy đủ ở GHI-CHU.md):

Retrieval (Hybrid+Rerank) Generation (LLM-as-judge)
Recall@3 = 69.2%, Recall@10 = 78.5%, MRR = 0.867 Correctness = 76.9%, Faithfulness = 81.5%

Cài đặt

python3 -m venv rag-env
source rag-env/bin/activate
pip install -r requirements.txt

cp .env.example .env
# điền GOOGLE_API_KEY (aistudio.google.com/apikey) và GROQ_API_KEY (console.groq.com) — cả hai đều miễn phí

Dữ liệu

Thư mục data/raw/ (tài liệu nguồn) và data/processed/ (kết quả trích xuất/chunking) không có sẵn trong repo vì chứa toàn văn tài liệu có bản quyền của bên thứ ba. Để chạy dự án:

  1. Tạo data/raw/personal/ và data/raw/public/, thêm tài liệu PDF/HTML của riêng bạn vào đó.
  2. Chạy pipeline xử lý:
python scripts/rename_new_docs.py    # đổi tên tự động theo tiêu đề/tác giả (cần GOOGLE_API_KEY)
python scripts/extract_text.py       # trích xuất → data/processed/documents.jsonl
python scripts/chunk_text.py         # chunking → data/processed/chunks.jsonl
python scripts/embed_and_store.py    # embedding → data/chroma_db/
  1. (Tuỳ chọn) Soạn bộ câu hỏi đánh giá riêng theo đúng schema của data/golden_set.json có sẵn trong repo.

Chạy demo

streamlit run app.py

Đánh giá lại

python scripts/retrieve.py                    # Recall/Precision/MRR — dense-only
python scripts/evaluate_advanced_retrieval.py  # Hybrid+Rerank (chậm, rerank chạy CPU)
python scripts/evaluate_groq_batch.py          # Generation qua Groq (resumable — chạy lại nếu bị ngắt giữa chừng)

Cấu trúc mã nguồn

Xem Phụ lục A trong GHI-CHU.md để biết vai trò từng script.

About

Hệ thống RAG học tập song ngữ Việt-Anh — Docling + bge-m3 + Chroma + Hybrid Search + Reranker

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages