RAG Evaluation: Context Precision, Recall và Faithfulness Metrics

RAG Evaluation: Đánh giá Context Precision, Recall và Faithfulness

Retrieval-Augmented Generation (RAG) trở thành kiến trúc mặc định cho ứng dụng AI dựa trên knowledge, nhưng đa số team chỉ đo “có hoạt động không” mà không đo “có đúng không”. Bài này giới thiệu bộ metrics thực tế để đánh giá từng component trong RAG pipeline — retrieval, reranking, generation — không cần nhân sự reviewer nặng.

RAG gồm 2 stage: retrieval lấy context từ vector DB, generation viết answer dựa trên retrieved chunks. Stage 1 sai → stage 2 dù mô hình lớn đến đâu cũng hallucinate. Stage 2 sai → retrieval có thể đúng nhưng answer vẫn sai. Vì vậy, bạn cần metrics riêng cho từng stage, không chỉ một điểm số chung.

RAG Retrieval-Augmented Generation pipeline architecture

Context Precision và Recall

Context Precision đo “trong những chunk retrieved, bao nhiêu thực sự liên quan đến query?”. Nếu bạn retrieve 10 chunks nhưng chỉ 2 relevant → precision = 0.2. Precision thấp thường do: embedding model không match domain, chunk size quá lớn, hoặc top-k quá cao.

Context Recall đo “trong tất cả relevant chunks có trong KB, bao nhiêu được retrieve về?”. Recall thấp thường do: chunk overlap strategy kém, hybrid search (BM25 + vector) không tuned, hoặc metadata filter quá restrictive.

Trade-off thực tế: precision cao + recall thấp → model thiếu context, bỏ sót thông tin. Recall cao + precision thấp → model nhiễu, tốn token, latency tăng. Target production thường là precision@10 > 0.7, recall@10 > 0.8. Tùy use case: medical/legal cần recall cao, e-commerce search cần precision cao.

Precision recall metrics chart cho RAG evaluation

Faithfulness và Answer Correctness

Faithfulness đo “answer có được support hoàn toàn bởi retrieved context không?”. Answer có thể đúng nhưng không faithfulness — ví dụ model thêm kiến thức ngoài context. Faithfulness thấp là dấu hiệu hallucination. Tính bằng LLM-as-judge: cho model retrieved context + generated answer, hỏi “mỗi claim trong answer có trích dẫn được từ context không?”

Answer Correctness chỉ đo “có đúng so với ground truth không?”. Đây là metric dễ nhưng đắt: cần human-annotated ground truth cho mỗi query. Trong production, bạn dùng faithfulness + context precision như proxy, không phải correctness trực tiếp.

LLM-as-Judge: thực tế triển khai

Thay vì train classifier riêng, dùng LLM mạnh (GPT-4o, Claude 3.5) làm judge. Template prompt chuẩn: đưa context + answer, yêu cầu điểm từng claim. Nhược điểm: judge model có thể bias, tốn tiền, latency cao. Ưu tiên: no-code, nhanh triển khai, generalize tốt across domain.

Framework phổ biến: Ragas, DeepEval, TruLens. Ragas tích hợp sẵn faithfulness, context precision/recall, answer correctness. DeepEval có G-Eval metric custom. TruLens hỗ trợ multi-turn conversation tracking.

LLM as judge evaluation setup cho RAG

Khi nào cần A/B test retrieval configuration

Thay đổi chunk size, overlap, top-k, embedding model, reranker — mỗi thay đổi nên có evaluation set cố định 50-200 queries. So sánh metrics trước/sau. Nếu precision tăng 5% nhưng recall giảm 8% → không rõ có improvement. Dùng paired t-test để xác định statistical significance.

Production monitoring: log retrieval metrics cho mỗi request, theo dõi distribution theo thời gian. Nếu precision tuột dưới 0.5 đột ngột → có thể KB content drift hoặc embedding model bị update bên third-party. Set alert threshold thay vì manual review.

Kết luận

RAG không phải “set and forget”. Bạn cần evaluation loop liên tục: offline evaluation set cho config change, online monitoring cho production drift. Metrics chính là context precision, context recall, faithfulness — bổ sung answer correctness khi có ground truth. Đừng chỉ đo latency, đo chất lượng retrieval + generation riêng biệt.

Nguồn tham khảo

Tôi là một lập trình viên IOS. Code chính là IOS nhưng thỉnnh thoảng vẫn đá sang Android hoặc web. Mặc dù không quá thông thạo nhưng tôi sẽ chia sẻ những kiến thức mà mình đã tìm hiểu, áp dụng qua.

Bài viết liên quan

NeMo Guardrails là gì? Bộ công cụ bảo vệ LLM đầu tiên của NVIDIA

NeMo Guardrails là gì? Bộ công cụ bảo vệ LLM đầu tiên của NVIDIA NeMo Guardrails là framework mã nguồn mở do NVIDIA phát triển, giúp developers thêm lớp kiểm…

Xem thêm

AI Agent Memory Systems: Short-term, Long-term và External Knowledge

AI Agent Memory Systems: Short-term vs Long-term vs External Knowledge Khi triển khai AI agent tự chủ, bộ nhớ là thành phần quyết định khả năng học hỏi và duy…

Xem thêm
Magentic-One multi-agent system

AutoGen — Framework Multi-Agent AI của Microsoft

AutoGen — Framework Multi-Agent AI của Microsoft AutoGen là framework đa tác nhân do Microsoft Research phát triển, ra mắt đầu 2023 và nhanh chóng trở thành lựa chọn hàng…

Xem thêm
0 0 đánh giá
Article Rating
Theo dõi
Thông báo của
guest
0 Comments
Cũ nhất
Mới nhất Được bỏ phiếu nhiều nhất