Tally

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:SingleTurnMetricDef | MultiTurnMetricDef

Metric definition used as input.

weight:number

Weight for this input when combining scores.

normalizerOverride?:NormalizerSpec | NormalizeToScore

Optional normalizer override for this input.

required?:boolean

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.

name:string

Scorer name (used in reports).

output:BaseMetricDef<number>

Base metric definition for the derived score.

inputs:readonly ScorerInput[]

Array of weighted inputs.

normalizeWeights?:booleanDefault: true

Normalize weights to sum to 1.

combineScores?:(scores: InputScores) => Score

Optional custom combiner over scores.

fallbackScore?:Score

Optional fallback score when inputs are missing.

description?:string

Optional description for reports.

metadata?:Record<string, unknown>

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.

name:string

Scorer name (used in reports).

output:BaseMetricDef<number>

Base metric definition for the derived score.

inputs:readonly ScorerInput[]

Array of weighted inputs.

normalizeWeights?:booleanDefault: true

Normalize weights to sum to 1.

fallbackScore?:Score

Optional fallback score when inputs are missing.

description?:string

Optional description for reports.

metadata?:Record<string, unknown>

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 }),
  ],
});

On this page