RAGAS Context Recall

RAGAS Context Recall (컨텍스트 재현율)

검색 단계를 평가할 때 '관련 문서를 얼마나 빠뜨리지 않고 찾아냈는가'도 중요해요. 정밀도(precision)가 상위 결과의 정확성을 본다면, 재현율(recall)은 중요한 정보를 놓치지 않았는지 보는 관점이에요. Ragas의 Context Recall 메트릭이 바로 이 재현율을 측정해 줘요. 관련 문서나 정보 중 실제로 검색에 성공한 비율을 수치화해요.

출처: RAGAS Context Recall

Context Recall이란

Context Recall은 관련 문서(또는 정보 조각) 가운데 얼마나 많이 성공적으로 검색됐는지 측정해요. 중요한 결과를 빠뜨리지 않는 데 초점을 맞추는데, 재현율이 높을수록 빠뜨린 관련 문서가 적다는 뜻이에요. 한마디로 "중요한 걸 놓치지 않았다"는 걸 보는 메트릭이죠.

놓치지 않는 것에 대한 메트릭이라서 항상 비교할 참조(reference)가 필요해요. LLM 기반 Context Recall 메트릭은 referencereference_contexts의 대리(proxy)로 사용해요. 참조 컨텍스트를 일일이 주석으로 달기는 매우 번거롭기 때문에, reference를 여러 주장(claim)으로 쪼갠 뒤 각 주장이 검색된 컨텍스트로 귀속(attribution) 가능한지 분석하는 방식으로 재현율을 추정해요. 이상적으로는 참조 답변의 모든 주장이 검색된 컨텍스트에 귀속되어야 해요.

[ \text{Context Recall} = \frac{\text{Number of claims in the reference supported by the retrieved context}}{\text{Total number of claims in the reference}} ]

즉, 참조 답변 속 주장 중 검색된 컨텍스트로 뒷받침되는 비율이 Context Recall 점수예요.

사용 예시

컬렉션 기반 API로 ContextRecall 메트릭을 만들어 평가해 볼게요. user_input, retrieved_contexts, reference를 넘겨 ascore로 점수를 얻어요.

from openai import AsyncOpenAI
from ragas.llms import llm_factory
from ragas.metrics.collections import ContextRecall

# Setup LLM
client = AsyncOpenAI()
llm = llm_factory("gpt-4o-mini", client=client)

# Create metric
scorer = ContextRecall(llm=llm)

# Evaluate
result = await scorer.ascore(
    user_input="Where is the Eiffel Tower located?",
    retrieved_contexts=["Paris is the capital of France."],
    reference="The Eiffel Tower is located in Paris."
)
print(f"Context Recall Score: {result.value}")

동기 코드를 선호한다면 ascore 대신 .score() 메서드를 사용해요.

Non LLM 기반 Context Recall

NonLLMContextRecall 메트릭은 retrieved_contextsreference_contexts로 계산돼요. 값은 0에서 1 사이이고, 높을수록 성능이 좋아요. 비(非)LLM 문자열 비교 메트릭을 거리 측정(distance measure)으로 사용해 검색된 컨텍스트가 관련 있는지 판단하는데, 아무 비LLM 메트릭이나 거리 측도로 쓸 수 있어요.

[ \text{context recall} = {|\text{Number of relevant contexts retrieved}| \over |\text{Total number of reference contexts}|} ]

ID 기반 Context Recall

IDBasedContextRecall은 문서에 고유 ID 체계가 있을 때 내용 대신 ID로 재현율을 측정해요. retrieved_context_idsreference_context_ids를 비교하며, 값은 0에서 1 사이예요. 문자열·정수 ID 모두 지원해요.

[ \text{ID-Based Context Recall} = \frac{\text{Number of reference context IDs found in retrieved context IDs}}{\text{Total number of reference context IDs}} ]

예를 들어 참조 ID 4개(doc_1, doc_4, doc_5, doc_6) 중 검색된 ID에 포함된 게 1개(doc_1)뿐이라면 재현율은 0.25가 돼요.

더 알아보기