text stringlengths 0 59.1k |
|---|
scorers.exactMatch; // output === expected |
scorers.levenshtein; // edit distance (0-1 score) |
// Numeric and data comparison |
scorers.numericDiff; // normalized numeric difference |
scorers.jsonDiff; // JSON object comparison |
scorers.listContains; // list element matching |
``` |
### LLM-Based Scorers |
For LLM-based evaluation, use the native VoltAgent scorers that explicitly require a model: |
```ts |
import { |
createAnswerCorrectnessScorer, |
createAnswerRelevancyScorer, |
createContextPrecisionScorer, |
createContextRecallScorer, |
createContextRelevancyScorer, |
createModerationScorer, |
createFactualityScorer, |
createSummaryScorer, |
} from "@voltagent/scorers"; |
import { openai } from "@ai-sdk/openai"; |
// Create LLM scorers with explicit model configuration |
const answerCorrectness = createAnswerCorrectnessScorer({ |
model: openai("gpt-4o-mini"), |
options: { factualityWeight: 0.8 }, |
}); |
const moderation = createModerationScorer({ |
model: openai("gpt-4o-mini"), |
threshold: 0.5, |
}); |
``` |
### Custom Scorers |
For custom scoring logic, use `buildScorer` from @voltagent/core: |
```ts |
import { buildScorer } from "@voltagent/core"; |
const customLengthScorer = buildScorer({ |
id: "length-validator", |
label: "Length Validator", |
}) |
.score(({ payload }) => { |
const output = String(payload.output || ""); |
const minLength = Number(payload.minLength || 10); |
const valid = output.length >= minLength; |
return { |
score: valid ? 1.0 : 0.0, |
metadata: { |
actualLength: output.length, |
minLength, |
}, |
}; |
}) |
.reason(({ score, results }) => ({ |
reason: |
score >= 1 |
? `Output meets minimum length of ${results.raw.minLength}` |
: `Output too short: ${results.raw.actualLength} < ${results.raw.minLength}`, |
})) |
.build(); |
``` |
## Result Structure |
`runExperiment` returns: |
```ts |
interface ExperimentResult { |
runId?: string; // VoltOps run ID (if connected) |
summary: ExperimentSummary; // aggregate metrics |
items: ExperimentItemResult[]; // per-item results |
metadata?: Record<string, unknown> | null; |
} |
``` |
### Summary |
```ts |
interface ExperimentSummary { |
totalCount: number; |
completedCount: number; |
successCount: number; // items with status "passed" |
failureCount: number; // items with status "failed" |
errorCount: number; // items with status "error" |
skippedCount: number; // items with status "skipped" |
meanScore?: number | null; |
passRate?: number | null; |
startedAt: number; // Unix timestamp |
completedAt?: number; // Unix timestamp |
durationMs?: number; |
scorers: Record<string, ScorerAggregate>; // per-scorer stats |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.