examples/basics/scorers/keyword-coverage/README.md
This example demonstrates how to use Mastra's Keyword Coverage Scorer to evaluate how well responses cover important keywords from the input text.
Clone the repository and navigate to the project directory:
git clone https://github.com/mastra-ai/mastra
cd examples/basics/scorers/keyword-coverage
Install dependencies:
pnpm install --ignore-workspace
Run the example:
pnpm start
The Keyword Coverage Scorer evaluates how well responses include important keywords and terms from the input text. It analyzes:
The example includes three scenarios:
Each scenario demonstrates:
The example will output:
createKeywordCoverageScorer: Function that creates the keyword coverage scorer instancescorer.run(): Method to evaluate input/output pairs for keyword coverage
{ input, output } where:
input: Array of chat messages (e.g., [{ role: 'user', content: 'text' }])output: Response object (e.g., { role: 'assistant', text: 'response' })score: Numerical coverage score (0-1)analyzeStepResult: Detailed keyword matching analysis and statistics