DocumentRecallEvaluator
DocumentRecallEvaluator
DocumentRecallEvaluator는 정답 레이블(ground truth)을 기준으로 Haystack 파이프라인이 검색한 문서를 평가해요. 정답 문서 중 몇 개가 검색되었는지 확인하죠. 이 지표를 재현율(recall)이라고 불러요.
출처: 문서
본문
- 파이프라인에서의 일반적인 위치: 단독으로, 또는 평가 파이프라인 안에서 사용해요. Evaluator의 입력을 생성한 별도의 파이프라인 뒤에서 사용하는 것이 일반적이에요.
- 필수 실행 변수:
ground_truth_documents(질문별 정답 문서 목록을 담은 리스트),retrieved_documents(질문별 검색 문서 목록을 담은 리스트) - 출력 변수: 딕셔너리 —
score(모든 입력에 대한 평균 recall 점수, 0.01.0),1.0 사이의 개별 recall 점수 리스트. mode가individual_scores(검색 문서 목록과 정답 문서 목록의 입력 쌍 각각에 대한 0.0single_hit이면 각 점수는 0 또는 1이에요.)
개요 (Overview)
DocumentRecallEvaluator 컴포넌트를 사용해 RAG 파이프라인 같은 Haystack 파이프라인이 검색한 문서를 정답 레이블과 비교해 평가할 수 있어요.
DocumentRecallEvaluator를 초기화할 때 mode 파라미터를 RecallMode.SINGLE_HIT 또는 RecallMode.MULTI_HIT로 설정할 수 있어요. 기본값은 RecallMode.SINGLE_HIT예요.
RecallMode.SINGLE_HIT는 정답 문서 중 어느 하나라도 검색되면 recall 점수 1로 올바른 검색으로 간주해요. 검색된 문서 하나만으로도 전체 점수를 달성할 수 있어요.
RecallMode.MULTI_HIT는 정답 문서가 모두 검색되어야 recall 점수 1로 올바른 검색으로 간주해요. 전체 점수를 얻으려면 검색된 문서 수가 최소한 정답 문서 수만큼은 되어야 해요.
단독 사용 (On its own)
두 쿼리에 대해 검색된 문서를 DocumentRecallEvaluator 컴포넌트로 평가하는 예시예요. 첫 번째 쿼리에는 정답 문서와 검색 문서가 각각 1개씩 있고, 두 번째 쿼리에는 정답 문서 2개와 검색 문서 3개가 있어요.
from haystack import Document
from haystack.components.evaluators import DocumentRecallEvaluator
evaluator = DocumentRecallEvaluator()
result = evaluator.run(
ground_truth_documents=[
[Document(content="France")],
[Document(content="9th century"), Document(content="9th")],
],
retrieved_documents=[
[Document(content="France")],
[
Document(content="9th century"),
Document(content="10th century"),
Document(content="9th"),
],
],
)
print(result["individual_scores"])
# [1.0, 1.0]
print(result["score"])
# 1.0
파이프라인에서 사용 (In a pipeline)
DocumentRecallEvaluator와 DocumentMRREvaluator를 파이프라인에서 함께 사용해 두 답변을 평가하고 정답 답변과 비교하는 예시예요. 개별 컴포넌트를 각각 실행하는 대신 파이프라인을 실행하면 한 번에 여러 지표를 계산하기 쉬워져요.
from haystack import Document, Pipeline
from haystack.components.evaluators import DocumentMRREvaluator, DocumentRecallEvaluator
pipeline = Pipeline()
mrr_evaluator = DocumentMRREvaluator()
recall_evaluator = DocumentRecallEvaluator()
pipeline.add_component("mrr_evaluator", mrr_evaluator)
pipeline.add_component("recall_evaluator", recall_evaluator)
ground_truth_documents = [
[Document(content="France")],
[Document(content="9th century"), Document(content="9th")],
]
retrieved_documents = [
[Document(content="France")],
[
Document(content="9th century"),
Document(content="10th century"),
Document(content="9th"),
],
]
result = pipeline.run(
{
"mrr_evaluator": {
"ground_truth_documents": ground_truth_documents,
"retrieved_documents": retrieved_documents,
},
"recall_evaluator": {
"ground_truth_documents": ground_truth_documents,
"retrieved_documents": retrieved_documents,
},
},
)
for evaluator in result:
print(result[evaluator]["individual_scores"])
# [1.0, 1.0]
# [1.0, 1.0]
for evaluator in result:
print(result[evaluator]["score"])
# 1.0
# 1.0