@mastra/evals 0.0.0-commonjs-20250227130920

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/.turbo/turbo-build.log +37 -0
  2. package/CHANGELOG.md +777 -0
  3. package/LICENSE +44 -0
  4. package/README.md +185 -0
  5. package/dist/_tsup-dts-rollup.d.cts +764 -0
  6. package/dist/_tsup-dts-rollup.d.ts +764 -0
  7. package/dist/chunk-4VNS5WPM.js +37 -0
  8. package/dist/chunk-TXXJUIES.js +15 -0
  9. package/dist/dist-MSGH6PAG.js +17947 -0
  10. package/dist/index.cjs +19675 -0
  11. package/dist/index.d.cts +3 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.js +86 -0
  14. package/dist/magic-string.es-5UDOWOAZ.js +1296 -0
  15. package/dist/metrics/judge/index.cjs +17 -0
  16. package/dist/metrics/judge/index.d.cts +1 -0
  17. package/dist/metrics/judge/index.d.ts +1 -0
  18. package/dist/metrics/judge/index.js +2 -0
  19. package/dist/metrics/llm/index.cjs +2482 -0
  20. package/dist/metrics/llm/index.d.cts +11 -0
  21. package/dist/metrics/llm/index.d.ts +11 -0
  22. package/dist/metrics/llm/index.js +2459 -0
  23. package/dist/metrics/nlp/index.cjs +202 -0
  24. package/dist/metrics/nlp/index.d.cts +5 -0
  25. package/dist/metrics/nlp/index.d.ts +5 -0
  26. package/dist/metrics/nlp/index.js +189 -0
  27. package/eslint.config.js +6 -0
  28. package/package.json +89 -0
  29. package/src/attachListeners.ts +40 -0
  30. package/src/constants.ts +1 -0
  31. package/src/evaluation.test.ts +29 -0
  32. package/src/evaluation.ts +58 -0
  33. package/src/index.ts +2 -0
  34. package/src/metrics/index.ts +3 -0
  35. package/src/metrics/judge/index.ts +14 -0
  36. package/src/metrics/llm/answer-relevancy/index.test.ts +156 -0
  37. package/src/metrics/llm/answer-relevancy/index.ts +58 -0
  38. package/src/metrics/llm/answer-relevancy/metricJudge.ts +56 -0
  39. package/src/metrics/llm/answer-relevancy/prompts.ts +214 -0
  40. package/src/metrics/llm/bias/index.test.ts +152 -0
  41. package/src/metrics/llm/bias/index.ts +52 -0
  42. package/src/metrics/llm/bias/metricJudge.ts +53 -0
  43. package/src/metrics/llm/bias/prompts.ts +109 -0
  44. package/src/metrics/llm/context-position/index.test.ts +275 -0
  45. package/src/metrics/llm/context-position/index.ts +69 -0
  46. package/src/metrics/llm/context-position/metricJudge.ts +55 -0
  47. package/src/metrics/llm/context-position/prompts.ts +135 -0
  48. package/src/metrics/llm/context-precision/index.test.ts +213 -0
  49. package/src/metrics/llm/context-precision/index.ts +68 -0
  50. package/src/metrics/llm/context-precision/metricJudge.ts +55 -0
  51. package/src/metrics/llm/context-precision/prompts.ts +139 -0
  52. package/src/metrics/llm/context-relevancy/index.test.ts +162 -0
  53. package/src/metrics/llm/context-relevancy/index.ts +59 -0
  54. package/src/metrics/llm/context-relevancy/metricJudge.ts +51 -0
  55. package/src/metrics/llm/context-relevancy/prompts.ts +111 -0
  56. package/src/metrics/llm/contextual-recall/index.test.ts +90 -0
  57. package/src/metrics/llm/contextual-recall/index.ts +56 -0
  58. package/src/metrics/llm/contextual-recall/metricJudge.ts +52 -0
  59. package/src/metrics/llm/contextual-recall/prompts.ts +82 -0
  60. package/src/metrics/llm/faithfulness/index.test.ts +254 -0
  61. package/src/metrics/llm/faithfulness/index.ts +59 -0
  62. package/src/metrics/llm/faithfulness/metricJudge.ts +62 -0
  63. package/src/metrics/llm/faithfulness/prompts.ts +166 -0
  64. package/src/metrics/llm/hallucination/index.test.ts +214 -0
  65. package/src/metrics/llm/hallucination/index.ts +59 -0
  66. package/src/metrics/llm/hallucination/metricJudge.ts +44 -0
  67. package/src/metrics/llm/hallucination/prompts.ts +143 -0
  68. package/src/metrics/llm/index.ts +11 -0
  69. package/src/metrics/llm/prompt-alignment/index.test.ts +335 -0
  70. package/src/metrics/llm/prompt-alignment/index.ts +116 -0
  71. package/src/metrics/llm/prompt-alignment/metricJudge.ts +43 -0
  72. package/src/metrics/llm/prompt-alignment/prompts.ts +224 -0
  73. package/src/metrics/llm/summarization/index.test.ts +274 -0
  74. package/src/metrics/llm/summarization/index.ts +72 -0
  75. package/src/metrics/llm/summarization/metricJudge.ts +101 -0
  76. package/src/metrics/llm/summarization/prompts.ts +252 -0
  77. package/src/metrics/llm/toxicity/index.test.ts +84 -0
  78. package/src/metrics/llm/toxicity/index.ts +54 -0
  79. package/src/metrics/llm/toxicity/metricJudge.ts +39 -0
  80. package/src/metrics/llm/toxicity/prompts.ts +87 -0
  81. package/src/metrics/llm/types.ts +7 -0
  82. package/src/metrics/llm/utils.ts +20 -0
  83. package/src/metrics/nlp/completeness/index.test.ts +98 -0
  84. package/src/metrics/nlp/completeness/index.ts +121 -0
  85. package/src/metrics/nlp/content-similarity/index.test.ts +76 -0
  86. package/src/metrics/nlp/content-similarity/index.ts +49 -0
  87. package/src/metrics/nlp/index.ts +5 -0
  88. package/src/metrics/nlp/keyword-coverage/index.test.ts +85 -0
  89. package/src/metrics/nlp/keyword-coverage/index.ts +49 -0
  90. package/src/metrics/nlp/textual-difference/index.test.ts +88 -0
  91. package/src/metrics/nlp/textual-difference/index.ts +38 -0
  92. package/src/metrics/nlp/tone/index.test.ts +100 -0
  93. package/src/metrics/nlp/tone/index.ts +55 -0
  94. package/tsconfig.json +5 -0
  95. package/vitest.config.ts +12 -0
@@ -0,0 +1,214 @@
1
+ import { openai } from '@ai-sdk/openai';
2
+ import { describe, it, expect } from 'vitest';
3
+
4
+ import type { TestCaseWithContext } from '../utils';
5
+
6
+ import { HallucinationMetric } from './index';
7
+
8
+ const testCases: TestCaseWithContext[] = [
9
+ {
10
+ // No hallucination - output aligns with context
11
+ input: 'Tell me about Tesla.',
12
+ context: ['Tesla was founded in 2003.', 'Elon Musk joined Tesla in 2004.', 'The first Tesla car was the Roadster.'],
13
+ output: 'Tesla, founded in 2003, welcomed Elon Musk in 2004. Their first vehicle was the Roadster.',
14
+ expectedResult: {
15
+ score: 0.0,
16
+ reason: 'The output perfectly aligns with all context statements without any contradictions.',
17
+ },
18
+ },
19
+ {
20
+ // Complete hallucination - output contradicts all context
21
+ input: 'Tell me about Tesla.',
22
+ context: ['Tesla was founded in 2003.', 'Elon Musk joined Tesla in 2004.', 'The first Tesla car was the Roadster.'],
23
+ output: 'Tesla was established in 2001 by Elon Musk himself. Their first car was the Model S.',
24
+ expectedResult: {
25
+ score: 1.0,
26
+ reason: "The output contradicts all context statements about founding date, Musk's role, and first car model.",
27
+ },
28
+ },
29
+ {
30
+ // Partial hallucination - output contradicts some context
31
+ input: 'Tell me about Tesla.',
32
+ context: ['Tesla was founded in 2003.', 'Elon Musk joined Tesla in 2004.', 'The first Tesla car was the Roadster.'],
33
+ output: 'Tesla was founded in 2003. Elon Musk started the company. The Roadster was their first car.',
34
+ expectedResult: {
35
+ score: 0.33,
36
+ reason:
37
+ "One out of three statements contradicts the context (Musk's role), while founding date and first car are accurate.",
38
+ },
39
+ },
40
+ {
41
+ // Empty output - should have no contradictions
42
+ input: 'Tell me about Tesla.',
43
+ context: ['Tesla was founded in 2003.', 'Elon Musk joined Tesla in 2004.'],
44
+ output: '',
45
+ expectedResult: {
46
+ score: 0.0,
47
+ reason: 'Empty output cannot contradict any context statements.',
48
+ },
49
+ },
50
+ {
51
+ // Speculative language - should not count as contradictions
52
+ input: 'Tell me about Tesla.',
53
+ context: ['Tesla was founded in 2003.', 'Elon Musk joined Tesla in 2004.'],
54
+ output: 'Tesla might have been founded around 2003, and I believe Elon Musk possibly joined a year later.',
55
+ expectedResult: {
56
+ score: 0.0,
57
+ reason: 'Speculative language (might, possibly, believe) does not constitute contradictions with context.',
58
+ },
59
+ },
60
+ {
61
+ // Empty context - should return score of 0
62
+ input: 'Tell me about Tesla.',
63
+ context: [],
64
+ output: 'Tesla was founded in 2001 by Elon Musk.',
65
+ expectedResult: {
66
+ score: 0.0,
67
+ reason: 'No context statements to contradict, resulting in zero hallucination score.',
68
+ },
69
+ },
70
+ {
71
+ // Implicit contradictions
72
+ input: 'Tell me about SpaceX achievements.',
73
+ context: ['SpaceX achieved first successful landing in 2015.', 'Their first crewed mission was in 2020.'],
74
+ output: 'Before anyone else, SpaceX pioneered reusable rockets with their first landing in 2014.',
75
+ expectedResult: {
76
+ score: 0.5,
77
+ reason: 'One context statement is contradicted through implicit claim about timing (2014 vs 2015).',
78
+ },
79
+ },
80
+ {
81
+ // Numerical approximations
82
+ input: 'Describe company metrics.',
83
+ context: ['The company has exactly 1,234 employees.', 'Revenue reached $50.5 million in 2022.'],
84
+ output: 'The company employs around 1,200 people and made about $50 million in 2022.',
85
+ expectedResult: {
86
+ score: 0.0,
87
+ reason: 'Approximate numbers that reasonably represent the actual figures are not considered contradictions.',
88
+ },
89
+ },
90
+ {
91
+ // Out of scope additions
92
+ input: 'Tell me about the company.',
93
+ context: ['The company was founded in New York.', 'They specialize in software.'],
94
+ output:
95
+ 'The company, founded in New York, specializes in software and has offices worldwide with plans to expand into AI.',
96
+ expectedResult: {
97
+ score: 0.0,
98
+ reason:
99
+ 'Additional information beyond context scope is not counted as contradictions unless it directly conflicts with context.',
100
+ },
101
+ },
102
+ {
103
+ // Temporal contradictions
104
+ input: 'Describe the project timeline.',
105
+ context: [
106
+ 'Project started in January 2023.',
107
+ 'Phase 1 completed in March 2023.',
108
+ 'Phase 2 completed in June 2023.',
109
+ ],
110
+ output: 'The project began in January 2023, with Phase 2 finishing before Phase 1 in February.',
111
+ expectedResult: {
112
+ score: 0.67,
113
+ reason:
114
+ 'Two context statements are contradicted through temporal inconsistency in phase completion order and dates.',
115
+ },
116
+ },
117
+ {
118
+ // Numerical contradiction despite approximation
119
+ input: 'Tell me about the company size.',
120
+ context: ['The company employs 300 people globally.'],
121
+ output: 'The company has approximately 1000 employees worldwide.',
122
+ expectedResult: {
123
+ score: 1.0,
124
+ reason:
125
+ 'Despite using "approximately", the claimed number (1000) represents a deviation too large from the actual value (300) to be considered a reasonable approximation.',
126
+ },
127
+ },
128
+ ];
129
+
130
+ const model = openai('gpt-4o');
131
+ describe(
132
+ 'HallucinationMetric',
133
+ () => {
134
+ it('should handle perfect alignment', async () => {
135
+ const testCase = testCases[0]!;
136
+ const metric = new HallucinationMetric(model, { context: testCase.context });
137
+ const result = await metric.measure(testCase.input, testCase.output);
138
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
139
+ });
140
+
141
+ it('should handle complete hallucination', async () => {
142
+ const testCase = testCases[1]!;
143
+ const metric = new HallucinationMetric(model, { context: testCase.context });
144
+ const result = await metric.measure(testCase.input, testCase.output);
145
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
146
+ });
147
+
148
+ it('should handle partial hallucination', async () => {
149
+ const testCase = testCases[2]!;
150
+ const metric = new HallucinationMetric(model, { context: testCase.context });
151
+ const result = await metric.measure(testCase.input, testCase.output);
152
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
153
+ });
154
+
155
+ it('should handle empty output', async () => {
156
+ const testCase = testCases[3]!;
157
+ const metric = new HallucinationMetric(model, { context: testCase.context });
158
+ const result = await metric.measure(testCase.input, testCase.output);
159
+ expect(result.score).toBe(testCase.expectedResult.score);
160
+ });
161
+
162
+ it('should handle speculative language', async () => {
163
+ const testCase = testCases[4]!;
164
+ const metric = new HallucinationMetric(model, { context: testCase.context });
165
+ const result = await metric.measure(testCase.input, testCase.output);
166
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
167
+ });
168
+
169
+ it('should handle empty context', async () => {
170
+ const testCase = testCases[5]!;
171
+ const metric = new HallucinationMetric(model, { context: testCase.context });
172
+ const result = await metric.measure(testCase.input, testCase.output);
173
+ expect(result.score).toBe(testCase.expectedResult.score);
174
+ });
175
+
176
+ it('should handle implicit contradictions', async () => {
177
+ const testCase = testCases[6]!;
178
+ const metric = new HallucinationMetric(model, { context: testCase.context });
179
+ const result = await metric.measure(testCase.input, testCase.output);
180
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
181
+ });
182
+
183
+ it('should handle numerical approximations', async () => {
184
+ const testCase = testCases[7]!;
185
+ const metric = new HallucinationMetric(model, { context: testCase.context });
186
+ const result = await metric.measure(testCase.input, testCase.output);
187
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
188
+ });
189
+
190
+ it('should handle out of scope additions', async () => {
191
+ const testCase = testCases[8]!;
192
+ const metric = new HallucinationMetric(model, { context: testCase.context });
193
+ const result = await metric.measure(testCase.input, testCase.output);
194
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
195
+ });
196
+
197
+ it('should handle temporal contradictions', async () => {
198
+ const testCase = testCases[9]!;
199
+ const metric = new HallucinationMetric(model, { context: testCase.context });
200
+ const result = await metric.measure(testCase.input, testCase.output);
201
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
202
+ });
203
+
204
+ it('should handle numerical contradiction despite approximation', async () => {
205
+ const testCase = testCases[10]!;
206
+ const metric = new HallucinationMetric(model, { context: testCase.context });
207
+ const result = await metric.measure(testCase.input, testCase.output);
208
+ expect(result.score).toBeCloseTo(testCase.expectedResult.score, 2);
209
+ });
210
+ },
211
+ {
212
+ timeout: 15 * 10000,
213
+ },
214
+ );
@@ -0,0 +1,59 @@
1
+ import { Metric } from '@mastra/core/eval';
2
+ import type { LanguageModel } from '@mastra/core/llm';
3
+
4
+ import type { MetricResultWithReason } from '../types';
5
+ import { roundToTwoDecimals } from '../utils';
6
+
7
+ import { HallucinationJudge } from './metricJudge';
8
+
9
+ export interface HallucinationMetricOptions {
10
+ scale?: number;
11
+ context: string[];
12
+ }
13
+
14
+ export class HallucinationMetric extends Metric {
15
+ private judge: HallucinationJudge;
16
+ private scale: number;
17
+ private context: string[];
18
+
19
+ constructor(model: LanguageModel, { scale = 1, context }: HallucinationMetricOptions) {
20
+ super();
21
+
22
+ this.context = context;
23
+ this.judge = new HallucinationJudge(model);
24
+ this.scale = scale;
25
+ }
26
+
27
+ async measure(input: string, output: string): Promise<MetricResultWithReason> {
28
+ const verdicts = await this.judge.evaluate(output, this.context);
29
+ const score = this.calculateScore(verdicts);
30
+ const reason = await this.judge.getReason({
31
+ input,
32
+ output,
33
+ context: this.context,
34
+ score,
35
+ scale: this.scale,
36
+ verdicts,
37
+ });
38
+
39
+ return {
40
+ score,
41
+ info: {
42
+ reason,
43
+ },
44
+ };
45
+ }
46
+
47
+ private calculateScore(verdicts: Array<{ verdict: string; reason: string }>): number {
48
+ const totalStatements = verdicts.length;
49
+ const contradictedStatements = verdicts.filter(v => v.verdict === 'yes').length;
50
+
51
+ if (totalStatements === 0) {
52
+ return 0;
53
+ }
54
+
55
+ const score = (contradictedStatements / totalStatements) * this.scale;
56
+
57
+ return roundToTwoDecimals(score);
58
+ }
59
+ }
@@ -0,0 +1,44 @@
1
+ import type { LanguageModel } from '@mastra/core/llm';
2
+ import { z } from 'zod';
3
+
4
+ import { MastraAgentJudge } from '../../judge';
5
+
6
+ import { generateEvaluatePrompt, HALLUCINATION_AGENT_INSTRUCTIONS, generateReasonPrompt } from './prompts';
7
+
8
+ export class HallucinationJudge extends MastraAgentJudge {
9
+ constructor(model: LanguageModel) {
10
+ super('Hallucination', HALLUCINATION_AGENT_INSTRUCTIONS, model);
11
+ }
12
+
13
+ async evaluate(output: string, context: string[]): Promise<{ statement: string; verdict: string; reason: string }[]> {
14
+ const evaluatePrompt = generateEvaluatePrompt({ context, output });
15
+ const result = await this.agent.generate(evaluatePrompt, {
16
+ output: z.object({
17
+ verdicts: z.array(
18
+ z.object({
19
+ statement: z.string(),
20
+ verdict: z.string(),
21
+ reason: z.string(),
22
+ }),
23
+ ),
24
+ }),
25
+ });
26
+
27
+ return result.object.verdicts;
28
+ }
29
+
30
+ async getReason(args: {
31
+ input: string;
32
+ output: string;
33
+ context: string[];
34
+ score: number;
35
+ scale: number;
36
+ verdicts: { verdict: string; reason: string }[];
37
+ }): Promise<string> {
38
+ const prompt = generateReasonPrompt(args);
39
+ const result = await this.agent.generate(prompt, {
40
+ output: z.object({ reason: z.string() }),
41
+ });
42
+ return result.object.reason;
43
+ }
44
+ }
@@ -0,0 +1,143 @@
1
+ export const HALLUCINATION_AGENT_INSTRUCTIONS = `You are a precise and thorough hallucination evaluator. Your job is to determine if an LLM's output contradicts the provided context, focusing on identifying factual inconsistencies.
2
+
3
+ Key Principles:
4
+ 1. Treat each context piece as a statement to verify
5
+ 2. Verify if the output contradicts any of these statements
6
+ 3. Consider a contradiction when the output directly conflicts with context statements
7
+ 4. Consider no contradiction when the output aligns with or doesn't mention context statements
8
+ 5. Empty outputs should be handled as having no contradictions
9
+ 6. Focus on factual inconsistencies, not omissions
10
+ 7. Never use prior knowledge in judgments
11
+ 8. Speculative language (may, might, possibly) should not be considered contradictions`;
12
+
13
+ export function generateEvaluatePrompt({ context, output }: { context: string[]; output: string }) {
14
+ return `Verify if the output contradicts any of the provided context statements. A contradiction occurs when the output directly conflicts with a statement.
15
+
16
+ Output to verify:
17
+ ${output}
18
+
19
+ Number of context statements: ${context.length}
20
+
21
+ Context statements to check:
22
+ ${context.join('\n')}
23
+
24
+ For each context statement, determine if the output contradicts it. When evaluating numbers:
25
+ - Numbers with qualifiers ("about", "around", "approximately") allow reasonable approximations
26
+ - Consider the scale of the number when determining reasonable approximations
27
+ - Only mark as contradiction if the difference would be misleading in context
28
+ - Respect explicit precision markers ("exactly", "precisely")
29
+
30
+ Example:
31
+ Context: "Tesla was founded in 2003"
32
+ Output: "Tesla, established in 2004, revolutionized the electric car industry."
33
+ {
34
+ "verdicts": [
35
+ {
36
+ "statement": "Tesla was founded in 2003",
37
+ "verdict": "yes",
38
+ "reason": "The output claims Tesla was established in 2004, which directly contradicts the statement that it was founded in 2003"
39
+ }
40
+ ]
41
+ }
42
+
43
+ Context: "The company has exactly 1,234 employees"
44
+ Output: "The company employs around 1,200 people"
45
+ {
46
+ "verdicts": [
47
+ {
48
+ "statement": "The company has exactly 1,234 employees",
49
+ "verdict": "no",
50
+ "reason": "While the output uses an approximation (around 1,200), this is a reasonable representation of 1,234 employees and maintains the correct order of magnitude"
51
+ }
52
+ ]
53
+ }
54
+
55
+ Context: "Revenue reached $50.5 million in 2022"
56
+ Output: "The company made about $50 million in 2022"
57
+ {
58
+ "verdicts": [
59
+ {
60
+ "statement": "Revenue reached $50.5 million in 2022",
61
+ "verdict": "no",
62
+ "reason": "The output's approximation of 'about $50 million' is a reasonable representation of $50.5 million, maintaining accuracy at this scale"
63
+ }
64
+ ]
65
+ }
66
+
67
+ Context: "The startup raised $2.1 million in seed funding"
68
+ Output: "The company secured approximately $5 million in their seed round"
69
+ {
70
+ "verdicts": [
71
+ {
72
+ "statement": "The startup raised $2.1 million in seed funding",
73
+ "verdict": "yes",
74
+ "reason": "Despite using 'approximately', the output claims $5 million which is more than double the actual amount ($2.1 million), making it a significant and misleading deviation"
75
+ }
76
+ ]
77
+ }
78
+
79
+ Rules:
80
+ - Only mark as contradicted if there's a direct conflict
81
+ - Omissions are not contradictions
82
+ - Never use prior knowledge in your judgment
83
+ - Provide clear reasoning for each verdict
84
+ - Be specific about where in the output the contradiction occurs
85
+ - The number of verdicts MUST MATCH the number of context statements exactly
86
+
87
+ Format:
88
+ {
89
+ "verdicts": [
90
+ {
91
+ "statement": "context statement",
92
+ "verdict": "yes/no",
93
+ "reason": "explanation of contradiction or lack thereof"
94
+ }
95
+ ]
96
+ }`;
97
+ }
98
+
99
+ export function generateReasonPrompt({
100
+ input,
101
+ output,
102
+ context,
103
+ score,
104
+ scale,
105
+ verdicts,
106
+ }: {
107
+ input: string;
108
+ output: string;
109
+ context: string[];
110
+ score: number;
111
+ scale: number;
112
+ verdicts: { verdict: string; reason: string }[];
113
+ }) {
114
+ return `Explain the hallucination score where 0 is the lowest and ${scale} is the highest for the LLM's response using this context:
115
+ Context:
116
+ ${context.join('\n')}
117
+ Input:
118
+ ${input}
119
+ Output:
120
+ ${output}
121
+ Score: ${score}
122
+ Verdicts:
123
+ ${JSON.stringify(verdicts)}
124
+ Rules:
125
+ - Explain score based on ratio of contradicted statements to total statements
126
+ - Focus on factual inconsistencies with context
127
+ - Keep explanation concise and focused
128
+ - Use given score, don't recalculate
129
+ - Explain both contradicted and non-contradicted aspects
130
+ - For mixed cases, explain the balance
131
+ - Base explanation only on the verified statements, not prior knowledge
132
+ Format:
133
+ {
134
+ "reason": "The score is {score} because {explanation of hallucination}"
135
+ }
136
+ Example Responses:
137
+ {
138
+ "reason": "The score is 0.0 because none of the statements from the context were contradicted by the output"
139
+ }
140
+ {
141
+ "reason": "The score is 0.5 because half of the statements from the context were directly contradicted by claims in the output"
142
+ }`;
143
+ }
@@ -0,0 +1,11 @@
1
+ export { AnswerRelevancyMetric } from './answer-relevancy';
2
+ export { ContextPositionMetric } from './context-position';
3
+ export { ContextPrecisionMetric } from './context-precision';
4
+ export { FaithfulnessMetric } from './faithfulness';
5
+ export { HallucinationMetric } from './hallucination';
6
+ export { PromptAlignmentMetric } from './prompt-alignment';
7
+ export { ToxicityMetric } from './toxicity';
8
+ export { ContextRelevancyMetric } from './context-relevancy';
9
+ export { ContextualRecallMetric } from './contextual-recall';
10
+ export { SummarizationMetric } from './summarization';
11
+ export { BiasMetric } from './bias';