Scorers
Combine multiple inputs into derived scores.
Scorers
Scorers combine multiple input metrics into a derived score.
Import
import { defineInput, defineScorer } from 'tally';
import { createWeightedAverageScorer } from 'tally/scorers';
import type { CreateWeightedAverageScorerOptions } from 'tally/scorers';defineInput()
Creates a weighted input for a scorer. Each input references a metric and specifies its weight in the combined score.
Metric definition used as input.
Weight for this input when combining scores.
Optional normalizer override for this input.
If false, missing score is ignored.
defineScorer()
Creates a custom scorer with full control over how input metrics are combined. Use this when you need custom combination logic beyond weighted averages.
Scorer name (used in reports).
Base metric definition for the derived score.
Array of weighted inputs.
Normalize weights to sum to 1.
Optional custom combiner over scores.
Optional fallback score when inputs are missing.
Optional description for reports.
Optional metadata for reports.
createWeightedAverageScorer()
Creates a scorer that computes a weighted average of input metrics. This is the most common way to combine multiple quality signals into a single score.
Scorer name (used in reports).
Base metric definition for the derived score.
Array of weighted inputs.
Normalize weights to sum to 1.
Optional fallback score when inputs are missing.
Optional description for reports.
Optional metadata for reports.
Average scorer (equal weights)
Use createWeightedAverageScorer with the same weight for each input.
import { defineBaseMetric, defineInput } from 'tally';
import { createWeightedAverageScorer } from 'tally/scorers';
const averageOutput = defineBaseMetric<number>({
name: 'averageQuality',
valueType: 'number',
});
const averageScorer = createWeightedAverageScorer({
name: 'AverageQuality',
output: averageOutput,
inputs: [
defineInput({ metric: answerRelevance, weight: 1 }),
defineInput({ metric: completeness, weight: 1 }),
defineInput({ metric: roleAdherence, weight: 1 }),
],
});