examples/basics/scorers/textual-difference/README.md
This example demonstrates how to use Mastra's Textual Difference Scorer to evaluate the similarity between input and output text strings by analyzing sequence differences and changes.
Clone the repository and navigate to the project directory:
git clone https://github.com/mastra-ai/mastra
cd examples/basics/scorers/textual-difference
Install dependencies:
pnpm install --ignore-workspace
Run the example:
pnpm start
The Textual Difference metric evaluates text similarity by analyzing:
The scorer uses algorithms to compare texts at the character and word level, providing detailed analysis of differences.
The example includes three scenarios:
Each scenario demonstrates:
The example will output:
createTextualDifferenceScorer: Function that creates the textual difference scorer instancescorer.run(): Method to evaluate input/output pairs for textual differences
{ 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 similarity score (0-1)analyzeStepResult: Detailed difference analysis including confidence, ratio, and change metrics