完全性評価
We just released a new evals API called Scorers, with a more ergonomic API and more metadata stored for error analysis, and more flexibility to evaluate data structures. It’s fairly simple to migrate, but we will continue to support the existing Evals API.
CompletenessMetric
を使用して、応答が入力の主要要素をすべて網羅しているかを評価します。このメトリクスは query
と response
を受け取り、スコアと、要素ごとの詳細な比較を含む info
オブジェクトを返します。
インストール
npm install @mastra/evals
完全網羅の例
この例では、応答に入力のすべての要素が含まれています。内容は完全に一致しており、結果としてカバレッジは100%になります。
import { CompletenessMetric } from "@mastra/evals/nlp";
const metric = new CompletenessMetric();
const query = "The primary colors are red, blue, and yellow.";
const response = "The primary colors are red, blue, and yellow.";
const result = await metric.measure(query, response);
console.log(result);
完全網羅の出力
出力は、応答に欠落がなく、すべての入力要素が含まれているため、スコアは1になります。
{
score: 1,
info: {
inputElements: [
'the', 'primary',
'colors', 'be',
'red', 'blue',
'and', 'yellow'
],
outputElements: [
'the', 'primary',
'colors', 'be',
'red', 'blue',
'and', 'yellow'
],
missingElements: [],
elementCounts: { input: 8, output: 8 }
}
}
部分的なカバレッジの例
この例では、応答はすべての入力要素を含んでいますが、元のクエリにはなかった追加の内容も含まれています。
import { CompletenessMetric } from "@mastra/evals/nlp";
const metric = new CompletenessMetric();
const query = "The primary colors are red and blue.";
const response = "The primary colors are red, blue, and yellow.";
const result = await metric.measure(query, response);
console.log(result);
部分的なカバレッジの出力
欠落している入力要素がないため、出力は高いスコアになります。ただし、応答には入力を超える追加の内容が含まれています。
{
score: 1,
info: {
inputElements: [
'the', 'primary',
'colors', 'be',
'red', 'and',
'blue'
],
outputElements: [
'the', 'primary',
'colors', 'be',
'red', 'blue',
'and', 'yellow'
],
missingElements: [],
elementCounts: { input: 7, output: 8 }
}
}
最小カバレッジの例
この例では、応答は入力の要素の一部しか含んでいません。重要な用語が抜け落ちている、あるいは変更されており、その結果、カバレッジが低下しています。
import { CompletenessMetric } from "@mastra/evals/nlp";
const metric = new CompletenessMetric();
const query = "The seasons include summer.";
const response = "The four seasons are spring, summer, fall, and winter.";
const result = await metric.measure(query, response);
console.log(result);
最小カバレッジの出力
入力の要素が1つ以上欠落しているため、出力のスコアは低くなります。応答は一部重複していますが、元の内容を完全には反映していません。
{
score: 0.75,
info: {
inputElements: [ 'the', 'seasons', 'summer', 'include' ],
outputElements: [
'the', 'four',
'seasons', 'spring',
'summer', 'winter',
'be', 'fall',
'and'
],
missingElements: [ 'include' ],
elementCounts: { input: 4, output: 9 }
}
}
メトリクスの設定
CompletenessMetric
インスタンスはデフォルト設定で作成できます。追加の設定は不要です。
const metric = new CompletenessMetric();
設定オプションの全一覧は CompletenessMetric を参照してください。
結果の解釈
CompletenessMetric
は次の形式の結果を返します:
{
score: number,
info: {
inputElements: string[],
outputElements: string[],
missingElements: string[],
elementCounts: {
input: number,
output: number
}
}
}
完全性スコア
完全性スコアは 0 から 1 の範囲です:
- 1.0: すべての入力要素がレスポンスに含まれている。
- 0.7–0.9: 主要な要素の大半が含まれており、欠落は最小限。
- 0.4–0.6: 一部の入力要素は網羅されているが、重要なものが欠けている。
- 0.1–0.3: 一致した入力要素はわずかで、ほとんどが欠けている。
- 0.0: レスポンスに入力要素がまったく含まれていない。
完全性情報
スコアの根拠となる説明。詳細には次が含まれます:
- クエリから抽出された入力要素
- レスポンスで一致した出力要素
- レスポンスから欠けている入力要素
- 入力と出力の要素数の比較