Quoted spans metric
Quoted spans metric (인용 구간 지표)
모델이 응답에서 인용한 구간이 실제 검색된 출처에 그대로 존재하는지 측정하는 지표예요. 사용자는 정확한 인용 구절에 특히 신뢰를 두기 때문에, 근거에 없는 인용이 나오면 신뢰도가 흔들려요. 이 지표로 인용 표류(citation drift)를 잡아낼 수 있어요.
출처: 문서
본문
QuotedSpansAlignment
무엇인가요(What): 모델 답변의 인용 구간(quoted spans) 중 검색된 출처(source)에 원문 그대로 등장하는 비율을 측정하는 지표예요. 점수는 [0, 1] 범위이며, 1.0은 모든 인용 구간이 근거로 뒷받침된다는 뜻이고 0.0은 출처에서 어떤 인용 구간도 발견되지 않았다는 뜻이에요.
왜 필요한가요(Why): 사용자는 정확한 인용 구절에 더 큰 신뢰를 두어요. 모델이 근거에 없는 사실을 인용하면 신뢰도가 떨어지죠. 이 지표는 답변의 인용 문구가 뒷받침되지 않는 '인용 표류' 사례를 잡아내는 데 도움을 줘요.
최신 컬렉션 API (Modern Collections API, 권장)
from ragas.metrics.collections import QuotedSpansAlignment
metric = QuotedSpansAlignment()
result = await metric.ascore(
response='The study found that "machine learning improves accuracy".',
retrieved_contexts=["Machine learning improves accuracy by 15%."]
)
print(f"Score: {result.value}") # 1.0
print(f"Reason: {result.reason}") # "Matched 1/1 quoted spans"
파라미터(Parameters):
name: 지표 이름 (기본값: "quoted_spans_alignment")casefold: 일치 전에 텍스트를 소문자로 정규화할지 여부 (기본값: True)min_span_words: 인용 구간의 최소 단어 수 (기본값: 3)
입력(Input):
response: str– 인용 구간을 포함한 모델 응답retrieved_contexts: List[str]– 대조할 출처 구절 목록
출력(Output): 다음과 같은 MetricResult:
value: [0, 1] 범위의 점수reason: 일치/전체 구간에 대한 설명
참고(Notes):
- 구현은 공백을 접고 소문자화하여 텍스트를 정규화해요.
- 기본적으로 3단어 미만의 구간은 무시해요.
min_span_words로 변경할 수 있어요. - 응답에 인용 구간이 없으면 점수는 1.0이에요(검증할 것이 없으니까요).
레거시 API (Legacy API, 사용 중단)
경고(Warning): 레거시
quoted_spans_alignment함수는 사용이 중단(deprecated)됐어요.ragas.metrics.collections의QuotedSpansAlignment를 사용해주세요.
입력 형태(Input shape):
answers: List[str]– 모델 답변 목록 (길이 N)sources: List[List[str]]– 출처 구절 목록의 목록 (길이 N)
출력(Output): 다음을 포함하는 딕셔너리:
{
"citation_alignment_quoted_spans": float, # score in [0,1]
"matched": float, # number of spans found in sources
"total": float # total number of spans considered
}
참고(Notes):
- 모든 답변에서 인용 구간이 발견되지 않으면 점수는
total = 0으로 0.0으로 정의돼요.