Completeness scorer
The createCompletenessScorer() function evaluates how thoroughly an LLM's output covers the key elements present in the input. It analyzes nouns, verbs, topics, and terms to determine coverage and provides a detailed completeness score.
ParametersParameters的直接链接
The createCompletenessScorer() function doesn't take any options.
This function returns an instance of the MastraScorer class. See the MastraScorer reference for details on the .run() method and its input/output.
.run() returnsrun-returns的直接链接
runId:
preprocessStepResult:
score:
The .run() method returns a result in the following shape:
{
runId: string,
preprocessStepResult: {
inputElements: string[],
outputElements: string[],
missingElements: string[],
elementCounts: { input: number, output: number }
},
score: number
}
Element extraction detailsElement extraction details的直接链接
The scorer extracts and analyzes several types of elements:
- Nouns: Key objects, concepts, and entities
- Verbs: Actions and states (converted to infinitive form)
- Topics: Main subjects and themes
- Terms: Individual substantial words
The extraction process includes:
- Normalization of text (removing diacritics, converting to lowercase)
- Splitting camelCase words
- Handling of word boundaries
- Special handling of short words (3 characters or less)
- Deduplication of elements
preprocessStepResultpreprocessstepresult的直接链接
From the .run() method, you can get the preprocessStepResult object with the following properties:
- inputElements: Key elements found in the input (e.g., nouns, verbs, topics, terms).
- outputElements: Key elements found in the output.
- missingElements: Input elements not found in the output.
- elementCounts: The number of elements in the input and output.
Scoring detailsScoring details的直接链接
The scorer evaluates completeness through linguistic element coverage analysis.
Scoring ProcessScoring Process的直接链接
- Extracts key elements:
- Nouns and entities such as names
- Action verbs
- Topic-specific terms
- Normalized word forms
- Calculates coverage of input elements:
- Exact matches for short terms (≤3 chars)
- Substantial overlap (>60%) for longer terms
Final score: (covered_elements / total_input_elements) * scale
Score interpretationScore interpretation的直接链接
A completeness score between 0 and 1:
- 1.0: Addresses all aspects of the query in detail.
- 0.7 to 0.9: Covers most important aspects with good detail, minor gaps.
- 0.4 to 0.6: Addresses some key points but missing important aspects or lacking detail.
- 0.1 to 0.3: Only partially addresses the query with substantial gaps.
- 0.0: Fails to address the query or provides irrelevant information.
ExampleExample的直接链接
Evaluate agent responses for completeness across different query complexities:
import { runEvals } from '@mastra/core/evals'
import { createCompletenessScorer } from '@mastra/evals/scorers/prebuilt'
import { myAgent } from './agent'
const scorer = createCompletenessScorer()
const result = await runEvals({
data: [
{
input:
'Explain the process of photosynthesis, including the inputs, outputs, and stages involved.',
},
{
input: 'What are the benefits and drawbacks of remote work for both employees and employers?',
},
{
input:
'Compare renewable and non-renewable energy sources in terms of cost, environmental impact, and sustainability.',
},
],
scorers: [scorer],
target: myAgent,
onItemComplete: ({ scorerResults }) => {
console.log({
score: scorerResults[scorer.id].score,
})
},
})
console.log(result.scores)
For more details on runEvals, see the runEvals reference.
To add this scorer to an agent, see the Scorers overview guide.