RAG 의 평가에 대해
- RAG 라고 하면 일반적인 챗봇이나, 분류 모델의 성능 개선, 멀티모달 rag 등 그 종류가 매우 많을 것이다.
- 여기서는 가장 일반적인 RAG 챗봇의 평가에 대해 다뤄보자.
RAGAS
데이터셋
- 4가지 필드로 구성된 데이터셋을 다룬다.
- question: 사용자 질문
- answer: 시스템이 생성한 답변
- contexts: 검색 (retrieve) 된 document chunk list
- ground truth: 사람이 직접 작성한 이상적인 정답, question 에 대해 기대하는 값
- ground truth 가 있을 때 / 없을 때 측정할 수 있는 항목이 다르다.
- 현실적인 프로덕션 서비스에서는 ground truth 가 없는 경우가 많다.
평가 지표
- 생성 (generation) 단계와 검색 (retrieve) 단계에 나누어서 평가한다.
실험
- PDF 파싱 기반의 RAG API 가 있다고 하자. RAG 성능을 어떻게 평가할 것인가?
1. ground truth 가 있는 question set
- 아래와 같이 question 에 대해 ground truth 가 적혀 있다고 하자.
- ground truth 는 사람이 직접 적었을 수도, LLM 이 적어줬을 수도 있다.
{
"question": "MAST는 어떤 구성 요소로 이루어져 있는가?",
"ground_truth": "MAST는 총 14개 실패 모드(failure modes)를 3개 상위 카테고리로 분류하여 구성된다: (1) Specification Issues, (2) Inter-Agent Misalignment, (3) Task Verification."
}
- 이를 RAG API 에 호출해서, LLM 의 응답 (answer) 과 검색된 컨텍스트 (context) 를 받아온다.
{
"question": "MAST는 어떤 구성 요소로 이루어져 있는가?",
"answer": "MAST는 14가지 세분화된 실패 모드를 식별하며, 이 모드들을 근본 원인이 일반적으로 나타나는 실행 단계(Pre-Execution, Execution, Post-Execution)에 매핑합니다. 또한, 이 모드들을 실패의 근본적인 특성에 따라 3가지 포괄적인 범주로 구성합니다.",
"contexts": ["provides the necessary framework to identify where these\nstructural weaknesses lie and guide the des...", "**MAST** identifies 14 fine-grained failure modes, mapping\nthem to execution stages (Pre-Execution, ...", "To further evaluate **MAST** ’s generalizability, we apply this\npipeline to two additional MAS (Mage...", "for future MAS research. We also develop and validate\nan automatic evaluation pipeline, LLM Annotato..."],
"ground_truth": "MAST는 총 14개 실패 모드(failure modes)를 3개 상위 카테고리로 분류하여 구성된다: (1) Specification Issues, (2) Inter-Agent Misalignment, (3) Task Verification."
}
- 다음으로, RAGAS 프레임워크를 실행해서 평가 지표를 얻는다.
- 평가 LLM 은 gemini-2.5-flash 를, 임베딩 모델은 gemini-embedding-001 을 썼다.
- ground truth 가 있는 경우, 4가지 지표를 측정할 수 있다.
- Context Precision (맥락 정밀도): 검색해온 내용이 정답과 얼마나 관련이 있는가?
- Context Recall (맥락 재현율): 정답을 맞추는 데 필요한 정보를 빠짐없이 검색했는가?
- Faithfulness (충실도): 답변이 검색된 문서 내용에 근거해서 사실대로 작성되었는가? (거짓말/환각 여부)
- Answer Relevancy (답변 관련성): 답변이 사용자의 질문 의도에 맞게 작성되었는가?
- 결과
{
"user_input": "MAST는 어떤 구성 요소로 이루어져 있는가?",
"retrieved_contexts": "['provides the necessary framework to identify where these\\nstructural weaknesses lie and guide the des...', '**MAST** identifies 14 fine-grained failure modes, mapping\\nthem to execution stages (Pre-Execution, ...', 'To further evaluate **MAST** ’s generalizability, we apply this\\npipeline to two additional MAS (Mage...', 'for future MAS research. We also develop and validate\\nan automatic evaluation pipeline, LLM Annotato...']",
"response": "MAST는 14가지 세분화된 실패 모드를 식별하며, 이 모드들을 근본 원인이 일반적으로 나타나는 실행 단계(Pre-Execution, Execution, Post-Execution)에 매핑합니다. 또한, 이 모드들을 실패의 근본적인 특성에 따라 3가지 포괄적인 범주로 구성합니다.",
"reference": "MAST는 총 14개 실패 모드(failure modes)를 3개 상위 카테고리로 분류하여 구성된다: (1) Specification Issues, (2) Inter-Agent Misalignment, (3) Task Verification.",
"context_precision": "0.49999999995",
"context_recall": "0.0",
"faithfulness": "0.3333333333333333",
"answer_relevancy": "0.8005286432107374"
}
{
'context_precision': 0.2708,
'context_recall': 0.1250,
'faithfulness': 0.1994,
'answer_relevancy': 0.8266}
- 결과적으로, 검색 (retieve) 성능에 문제가 있음을 확인했다.
분류 모델에 RAG 평가를 적용한다면?
DeepEval