scorers
Viteval includes deterministic scorers, embedding similarity scorers, and LLM
judges. Call each factory to create a scorer. LLM and embedding scorers use the
models configured in viteval.config.ts. See Configuration.
The scores in the examples illustrate how to read results. Model-based scores vary with the configured model and are not guarantees of correctness or safety.
Judge scorers accept { model } to override the configured language model.
Model failures return score: null with an error in metadata. Null scores
contribute 0 to evaluation aggregation.
Import
Factory contracts
All factories return a Scorer accepting { output, expected, ...extra } and
returning a Score or Promise<Score>. The evaluator also passes the case's
input. Scores include a name, number | null value, and optional metadata.
See createScorer() for the full callback type and
wrapScorer() for adapting structured values.
Deterministic and embedding inputs
trueexactMatch() only. Set false to lowercase both normalized values before
comparison.
falseexactMatch() only. Trim both normalized values before comparison.
0levenshtein(), jsonDiff(), and listContains() only. Similarities below
this value return zero. Other scores are unchanged. This does not set the
evaluation's pass threshold.
0numericDiff() only. A positive tolerance returns 1 when the absolute
difference is within that tolerance. Otherwise, relative similarity is used.
Judge inputs and score values
These are the fields read by each judge's prompt. output is always the value
being assessed. Context scorers expect retrieved context there, not the final answer.
All judges return discrete rubric scores, not continuous confidence estimates.
DataItem still requires an expected field even when a judge does not read it.
Set translation's language field to the source language. When omitted it
defaults to 'Unknown'.
configured language modelOverride the judge model for one scorer. All judge factories accept this option. See Configuration.
Metadata and failures
Null contributes zero to aggregation. It is not a separate automatic failure when the scorer returns normally. A permissive evaluation threshold can therefore still pass. Embedding scorers return 1 immediately for identical string values, without calling a model.
Text similarity
exactMatch
Returns 1 if output exactly matches expected, 0 otherwise.
Use cases: Exact answers, structured outputs, code generation
Example:
levenshtein
Scores text similarity using Levenshtein edit distance.
Range: 0.0 - 1.0 (higher = more similar)
Use cases: Approximate text matching, typo tolerance
Example:
answerSimilarity
Semantic similarity using embeddings.
Range: 0.0 - 1.0
Use cases: Meaning-based comparison, paraphrasing
Example:
embeddingSimilarity
Measures semantic similarity using embeddings.
Range: 0.0 - 1.0
Use cases: Semantic search, content matching
Model setup:
- Uses the embedding model configured in
models.defaults.embedding - Compares outputs and expected answers with cosine similarity
- Language support depends on the selected model
Content quality
factual
Asks an LLM judge to compare the output's factual accuracy with the expected answer.
Range: 0.0 - 1.0
Use cases: Knowledge-based QA, educational content
The reported scorer name is Factuality. The judge returns one of five
categories: consistent subset (0.4), consistent superset (0.6), same details (1),
disagreement (0), or immaterial differences (1). This is not a continuous
confidence score.
Example:
summary
Asks an LLM judge to compare the submitted summary with an expert summary of
input. Returns 0 or 1.
Range: 0.0 - 1.0
Use cases: Text summarization, content condensation
Criteria:
- Compares which summary better describes the original text
- Ignores style, grammar, and punctuation differences
translation
Asks an LLM judge to assess a translation against the expected answer.
Range: 0.0 - 1.0
Use cases: Machine translation, multilingual content
Criteria:
- Meaning preservation, including nouns and tenses
- Verbs or adjectives that change the meaning
- Ignores style and punctuation differences
Include a language field in each case to name the source language. The judge
compares translations into English and returns 0 or 1.
Answer quality
answerCorrectness
Asks an LLM judge to compare an answer with the expected answer.
Range: 0.0 - 1.0
Use cases: QA systems, educational assessments
answerRelevancy
Asks an LLM judge how relevant the answer is to the question.
Range: 0.0 - 1.0
Use cases: Chat systems, search results
Example:
Context evaluation
contextEntityRecall
Uses an LLM judge to check whether the context mentions the expected entities.
Range: 0.0 - 1.0
Use cases: Information extraction, entity recognition
contextPrecision
Uses an LLM judge to assess how much of the retrieved context is relevant to the
question and expected answer. Pass the retrieved context as output.
Range: 0.0 - 1.0
Use cases: RAG systems, context-aware generation
contextRecall
Uses an LLM judge to assess whether the retrieved context supports all claims in
the expected answer. Pass the retrieved context as output.
Range: 0.0 - 1.0
Use cases: Reading comprehension, context utilization
contextRelevancy
Uses an LLM judge to assess whether the retrieved context is relevant to the
question. Pass the retrieved context as output.
Range: 0.0 - 1.0
Use cases: Context filtering, relevance ranking
Safety and moderation
moderation
Asks an LLM judge to classify the output as safe or unsafe. This is a model-based assessment, not a guarantee that an output is safe.
Range: 0.0 - 1.0 (1.0 = safe, 0.0 = unsafe)
Use cases: Content filtering, safety checks
The judge checks for:
- Hate speech
- Violence
- Self-harm
- Sexual content
- Harassment
- Dangerous or illegal activities
Example:
Structured data
jsonDiff
Compares JSON structures for differences.
Range: 0.0 - 1.0
Use cases: API responses, structured output validation
Example:
sql
Asks an LLM judge whether the submitted SQL is equivalent to the expected query. It does not execute queries or validate them against a database.
Range: 0.0 - 1.0
Use cases: SQL generation, query validation
Criteria:
- Whether the queries would return equivalent results
- Whether the submitted query appears likely to fail
- Ignores whitespace, style, and output column naming differences
Numeric and list comparison
numericDiff
Calculates numerical difference between outputs.
Range: 0.0 - 1.0
Use cases: Mathematical calculations, numeric predictions
Example:
listContains
Verifies if a list contains expected items.
Range: 0.0 - 1.0
Use cases: List generation, item retrieval
Example:
Items are converted to strings and compared using Levenshtein similarity with optimal one-to-one matching. The total is divided by the longer list's length, so extra output items reduce the score. Two empty lists score 1. One empty list scores 0.
Specialized scorers
possible
Asks an LLM judge whether a response offers a solution (1) or declares the task
impossible (0). It does not compare the response with expected or check whether
the proposed solution is correct.
Range: 0.0 - 1.0
Use cases: Detecting declarations of impossibility versus solution attempts
Example:
humor
Asks an LLM judge whether the output is funny: no (0), unsure (0.5), or yes (1).
Range: 0.0 - 1.0
Use cases: Creative writing, entertainment content
This is a humor check, not a safety or appropriateness check. Use moderation
separately when needed.