> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # 환각 득점자 그만큼`createHallucinationScorer()`함수는 제공된 컨텍스트와 출력을 비교하여 LLM이 사실적으로 올바른 정보를 생성하는지 여부를 평가합니다. 이 채점자는 맥락과 출력 ​​사이의 직접적인 모순을 식별하여 환각을 측정합니다. ## 매개변수 `createHallucinationScorer()` 함수는 다음 속성이 포함된 단일 옵션 객체를 받습니다. **model** (`LanguageModel`): 환각을 평가하는 데 사용되는 Model 구성입니다. **options** (`Options`): 구성 옵션입니다. **options.scale** (`number`): 최대 점수 값입니다. **options.context** (`string[]`): 환각 감지의 정답 데이터로 사용할 정적 컨텍스트 문자열입니다. **options.getContext** (`(params: GetContextParams) => string[] | Promise`): 런타임에 컨텍스트를 동적으로 확인하는 훅입니다. 정적 컨텍스트보다 우선합니다. 채점기가 실행될 때만 컨텍스트(예: Tool 결과)를 사용할 수 있는 실시간 채점에 유용합니다. 이 함수는 MastraScorer 클래스의 인스턴스를 반환합니다. `.run()` 메서드는 다른 채점기와 동일한 입력을 받지만([MastraScorer 참조](https://mastra.zisheng.pro/ko/reference/evals/mastra-scorer) 확인), 반환값에는 아래에 설명된 LLM 관련 필드가 포함됩니다. ## `.run()`보고 **runId** (`string`): 실행 ID입니다(선택 사항). **preprocessStepResult** (`object`): 추출된 주장이 포함된 객체: { claims: string\[] } **preprocessPrompt** (`string`): 전처리 단계를 위해 LLM에 전송된 Prompt입니다(선택 사항). **analyzeStepResult** (`object`): 판정이 포함된 객체: { verdicts: Array<{ statement: string, verdict: 'yes' | 'no', reason: string }> } **analyzePrompt** (`string`): 분석 단계를 위해 LLM에 전송된 Prompt입니다(선택 사항). **score** (`number`): 환각 점수(0부터 scale까지, 기본값 0\~1)입니다. **reason** (`string`): 점수와 식별된 모순에 대한 상세 설명입니다. **generateReasonPrompt** (`string`): generateReason 단계를 위해 LLM에 전송된 Prompt입니다(선택 사항). ## 채점 세부정보 채점자는 모순 탐지 및 뒷받침되지 않는 주장 분석을 통해 환각을 평가합니다. ### 채점 과정 1. 사실적인 내용을 분석합니다. - 컨텍스트에서 명령문을 추출합니다. - 숫자 값과 날짜를 식별합니다. - 지도 문 관계 2. 환각에 대한 결과를 분석합니다. - 컨텍스트 설명과 비교합니다. - 직접적인 갈등을 환각으로 표시합니다. - 근거가 없는 주장을 환각으로 식별합니다. - 수치 정확도 평가 - 근사 컨텍스트를 고려합니다. 3. 환각 점수를 계산합니다. - 환각적인 진술(모순 및 뒷받침되지 않는 주장)을 계산합니다. - 총 명세서로 나눕니다. - 구성된 범위로 확장 최종 점수:`(hallucinated_statements / total_statements) * scale` ### 중요한 고려사항 - 맥락에 없는 주장은 환각으로 간주됩니다. - 주관적인 주장은 명시적으로 뒷받침되지 않는 한 환각입니다. - 맥락상 사실에 대한 추측적 언어('아마도', '아마도')는 허용됩니다. - 맥락에 맞지 않는 사실에 대한 추측적 언어는 환각으로 간주됩니다. - 빈 출력으로 인해 환각 현상이 발생하지 않습니다. - 수치 평가에서는 다음을 고려합니다. - 규모에 맞는 정밀도 - 상황에 따른 근사치 - 명시적 정밀도 표시기 ### 점수 해석 0에서 1 사이의 환각 점수: - **0.0**: 환각 없음, 모든 주장이 문맥과 일치함. - **0.3\~0.4**: 낮은 환각, 몇 가지 모순. - **0.5\~0.6**: 혼합된 환각, 여러 가지 모순. - **0.7\~0.8**: 높은 환각, 많은 모순. - **0.9\~1.0**: 완전한 환각, 대부분 또는 모든 주장이 맥락과 모순됩니다. 점수는 환각의 정도를 나타냅니다. 점수가 낮을수록 제공된 맥락과 사실이 더 잘 일치함을 나타냅니다. ## 예 ### 정적 컨텍스트 다음과 비교할 실제 정보가 있는 경우 정적 컨텍스트를 사용하십시오. ```typescript import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt' const scorer = createHallucinationScorer({ model: 'openai/gpt-5.6-sol', options: { context: [ 'The first iPhone was announced on January 9, 2007.', 'It was released on June 29, 2007.', 'Steve Jobs introduced it at Macworld.', ], }, }) ``` ### 동적 컨텍스트`getContext` Tool 결과에서 컨텍스트를 가져오는 실시간 채점 시나리오에는 `getContext`를 사용하세요. ```typescript import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt' import { extractToolResults } from '@mastra/evals/scorers' const scorer = createHallucinationScorer({ model: 'openai/gpt-5.6-sol', options: { getContext: ({ run, step }) => { // Extract tool results as context const toolResults = extractToolResults(run.output) return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result })) }, }, }) ``` ### Agent를 통한 실시간 채점 실시간 평가를 위해 채점자를 Agent에 연결합니다. ```typescript import { Agent } from '@mastra/core/agent' import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt' import { extractToolResults } from '@mastra/evals/scorers' const hallucinationScorer = createHallucinationScorer({ model: 'openai/gpt-5.6-sol', options: { getContext: ({ run }) => { const toolResults = extractToolResults(run.output) return toolResults.map(t => JSON.stringify({ tool: t.toolName, result: t.result })) }, }, }) const agent = new Agent({ id: 'my-agent', name: 'my-agent', model: 'openai/gpt-5.6-sol', instructions: 'You are a helpful assistant.', evals: { scorers: [hallucinationScorer], }, }) ``` ### 일괄 평가`runEvals` ```typescript import { runEvals } from '@mastra/core/evals' import { createHallucinationScorer } from '@mastra/evals/scorers/prebuilt' import { myAgent } from './agent' const scorer = createHallucinationScorer({ model: 'openai/gpt-5.6-sol', options: { context: ['Known fact 1', 'Known fact 2'], }, }) const result = await runEvals({ data: [{ input: 'Tell me about topic A' }, { input: 'Tell me about topic B' }], scorers: [scorer], target: myAgent, onItemComplete: ({ scorerResults }) => { console.log({ score: scorerResults[scorer.id].score, reason: scorerResults[scorer.id].reason, }) }, }) console.log(result.scores) ``` `runEvals`에 대한 자세한 내용은 [runEvals 참조](https://mastra.zisheng.pro/ko/reference/evals/run-evals)를 확인하세요. 이 득점자를 Agent에 추가하려면 다음을 참조하세요.[Scorers overview](https://mastra.zisheng.pro/ko/docs/evals/overview) guide. ## 관련된 - [성실성 득점자](https://mastra.zisheng.pro/ko/reference/evals/faithfulness) - [답변 관련성 득점자](https://mastra.zisheng.pro/ko/reference/evals/answer-relevancy)