組み込みのAIジャッジ
プレビュー
この機能はパブリックプレビュー段階です。
この記事では、AI Mosaic AIAgent Evaluation に組み込まれている各 ジャッジについて、必要な入力や出力メトリクスなど、詳細について説明します。
関連項目は次を参照してください。
AI審査員の概要
注:
すべての裁判官がグラウンドトゥルースラベルを必要とするわけではありません。 ラベルを必要としないジャッジは、エージェントを評価するためのリクエストがセットしかない場合に便利です。
審査員の氏名 |
審査員が評価する品質面 |
必須入力 |
グラウンドトゥルースが必要 |
---|---|---|---|
|
|
いいえ、ただし必須です |
|
|
|
あり |
|
|
|
あり |
|
|
|
いいえ |
|
|
|
あり |
|
|
|
いいえ |
|
|
レトリーバーは、ユーザーのリクエストに応答するのに役立つ(関連性のある)チャンクを見つけましたか? 注: このジャッジは、取得された各チャンクに個別に適用され、各チャンクのスコアと根拠が生成されます。 これらのスコアは、関連するチャンクの割合を表す各行の |
|
いいえ |
|
|
いいえ |
|
|
|
あり |
注:
マルチターンの会話の場合、AI の判断は会話の最後のエントリのみを評価します。
AIジャッジ出力
評価に使用された各審査員は、次の列を出力します。
データフィールド |
タイプ |
説明 |
---|---|---|
|
|
|
|
|
LLMの書面による推論は、 |
|
|
この評価の計算でエラーが発生した場合は、エラーの詳細がこちらに表示されます。 エラーがない場合、これは NULL です。 |
各ジャッジは、実行全体に対する集計メトリクスも作成します。
メトリクス名 |
タイプ |
説明 |
---|---|---|
|
|
すべての評価に対する |
ガイドラインの遵守
定義: 回答は提供されたガイドラインに準拠していますか?
グラウンドトゥルースが必要: global_guidelines
を使用する場合はいいえ。 [行ごとの guidelines
] を使用する場合は [はい]
ガイドラインの遵守は、エージェントの応答がガイドラインに規定されている特定の制約または指示に従っているかどうかを評価します。
ガイドラインは、次のいずれかの方法で定義できます。
per-row: 特定のリクエストのレスポンスは、その評価ローで定義されたガイドラインに従う必要があります。
globally: リクエストに対するすべてのレスポンスは、グローバルガイドラインに準拠する必要があります。
必須入力
入力評価セットには、次の列が必要です。
request
response
model
パラメーターをmlflow.evaluate()
に指定していない場合 .構成で定義されている行ごとの
guidelines
またはglobal_guidelines
。
例:
評価セットの行ごとのガイドラインの遵守を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris.",
# You can also just pass an array of guidelines directly to guidelines, but Databricks recommends naming them with a dictionary.
"guidelines": {
"english": ["The response must be in English"],
"clarity": ["The response must be clear, coherent, and concise"],
}
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["guideline_adherence"]
}
}
)
評価セットからグローバルガイドラインの遵守を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris.",
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["guideline_adherence"],
"global_guidelines": ["The response must be in English", "The response must be concise"]
}
}
)
callable judge SDKでガイドラインの遵守を使用します。
from databricks.agents.evals import judges
assessment = judges.guideline_adherence(
request="What is the capital of France?",
response="The capital of France is Paris.",
# You can also just pass an array of guidelines directly to guidelines, but Databricks recommends naming them with a dictionary.
"guidelines": {
"english": ["The response must be in English"],
"clarity": ["The response must be clear, coherent, and concise"],
}
)
print(assessment)
正確性
定義:エージェントは事実に基づいた正確な回答で応答しましたか?
グラウンドトゥルースが必要です:はい、 expected_facts[]
または expected_response
。
正確性は、エージェントの実際の応答をグラウンドトゥルースラベルと比較し、事実の誤りを検出するための良い方法です。
必須入力
入力評価セットには、次の列が必要です。
request
response
model
パラメーターをmlflow.evaluate()
に指定していない場合 .
重要
Databricks では、expected_response
の代わりに expected_facts[]
を使用することをお勧めします。expected_facts[]
、正しい回答に必要な最小限の事実のセットを表しており、対象分野の専門家がキュレーションしやすくなります。
expected_response
を使用する必要がある場合は、正しい応答に必要な最小限のファクトのセットのみを含める必要があります。別のソースから回答をコピーする場合は、回答を編集して、回答が正しいと見なされるために 必要 のないテキストを削除します。
必要な情報のみを含め、回答に厳密に必要でない情報を省略することで、Agent Evaluation は出力品質に関するより堅牢なシグナルを提供できます。
例:
評価セットの正確性を使用します。
import mlflow
eval_set = [{
"request": "What is the difference between reduceByKey and groupByKey in Spark?",
"response": "reduceByKey aggregates data before shuffling, whereas groupByKey shuffles all data, making reduceByKey more efficient.",
"expected_facts": [
"reduceByKey aggregates data before shuffling",
"groupByKey shuffles all data",
]
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["correctness"]
}
}
)
callable judge SDKで正確性を使用します。
from databricks.agents.evals import judges
assessment = judges.correctness(
request="What is the difference between reduceByKey and groupByKey in Spark?",
response="reduceByKey aggregates data before shuffling, whereas groupByKey shuffles all data, making reduceByKey more efficient.",
expected_facts=[
"reduceByKey aggregates data before shuffling",
"groupByKey shuffles all data",
]
)
print(assessment)
応答が間違っている場合はどうすればよいですか?
エージェントが事実に反する回答を返した場合、次のことを行う必要があります。
エージェントによって取得されたコンテキストが無関係または不正確であるかどうかを理解します。 RAGアプリケーションの場合、 コンテキスト充足ジャ ッジを使用して、コンテキストが
expected_facts
またはexpected_response
を生成するのに十分かどうかを判断できます。十分なコンテキストがある場合は、関連情報を含めるようにプロンプトを調整します。
クエリとの関連性
定義: 応答は入力要求に関連していますか?
グラウンドトゥルースが必要:いいえ。
関連性により、エージェントの応答は、無関係なトピックに逸脱することなく、ユーザーの入力に直接対処できます。
例:
評価セットの関連性を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris."
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["relevance_to_query"]
}
}
)
呼び出し可能なジャッジSDKとの関連性を使用します。
from databricks.agents.evals import judges
assessment = judges.relevance_to_query(
request="What is the capital of France?",
response="The capital of France is Paris."
)
print(assessment)
コンテキストの十分性
定義:取得したドキュメントは、期待される応答を生成するのに十分ですか?
グラウンドトゥルースが必要です:はい、 expected_facts
または expected_response
。
コンテキストの十分性は、取得されたドキュメントが期待される応答を生成するために必要なすべての情報を提供しているかどうかを評価します。
必須入力
入力評価セットには、次の列が必要です。
request
response
model
パラメーターをmlflow.evaluate()
に指定していない場合 .expected_facts
またはexpected_response
。 expected_factsガイドラインとexpected_responseガイドラインを参照してください。retrieved_context[].content
model
パラメーターをmlflow.evaluate()
に指定していない場合 .
例:
評価セットからコンテキストの十分性を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris.",
"retrieved_context": [
{"content": "Paris is the capital city of France."}
],
"expected_facts": [
"Paris"
]
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["context_sufficiency"]
}
}
)
呼び出し可能なジャッジSDKでコンテキストの十分性を使用します。
from databricks.agents.evals import judges
assessment = judges.context_sufficiency(
request="What is the capital of France?",
retrieved_context=[
{"content": "Paris is the capital city of France."}
]
)
print(assessment)
安全
定義: 回答は有害または有害なコンテンツを避けていますか?
グラウンドトゥルースが必要:いいえ。
安全性とは、エージェントの応答に有害、攻撃的、または有毒な内容が含まれていないことを保証します。
例:
評価セットから安全性を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris."
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["safety"]
}
}
)
callable judge SDKでsafetyを使用します。
from databricks.agents.evals import judges
assessment = judges.safety(
request="What is the capital of France?",
response="The capital of France is Paris."
)
print(assessment)
グラウンディング性
定義:応答は、取得したコンテキストと事実上一貫していますか?
グラウンドトゥルースが必要:いいえ。
グラウンディングネスは、エージェントの応答が、取得したコンテキストで提供される情報と一致しているかどうかを評価します。
必須入力
入力評価セットには、次の列が必要です。
request
response
model
パラメーターをmlflow.evaluate()
に指定していない場合 .retrieved_context[].content
mlflow.evaluate()
. の呼び出しでmodel
引数を使用しない場合 .
例:
評価セットの接地性を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris.",
"retrieved_context": [
{"content": "Paris is the capital city of France."}
]
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["groundedness"]
}
}
)
callable judge SDKでgroundednessを使用します。
from databricks.agents.evals import judges
assessment = judges.groundedness(
request="What is the capital of France?",
response="The capital of France is Paris.",
retrieved_context=[
{"content": "Paris is the capital city of France."}
]
)
print(assessment)
チャンクの関連性
定義: 取得したチャンクは入力要求に関連していますか?
グラウンドトゥルースが必要:いいえ。
チャンクの関連性は、各チャンクが入力要求に関連しているかどうかを測定します。
必須入力
入力評価セットには、次の列が必要です。
request
retrieved_context[].content
model
パラメーターをmlflow.evaluate()
に指定していない場合 .
mlflow.evaluate()
の呼び出しで model
引数を使用しない場合は、 retrieved_context[].content
または trace
も指定する必要があります。
例:
この例では、カスタム精度メトリクスを持つチャンク関連性ジャッジを使用して、行レベルの精度スコアをコンピュートします。 カスタムメトリクスの詳細については、「カスタムメトリクス」を参照してください
import mlflow
from mlflow.evaluation import Assessment
eval_set = [{
"request": "What is the capital of France?",
"response": "The capital of France is Paris.",
"retrieved_context": [
{"content": "Paris is the capital city of France."},
{"content": "The best baguettes are in Nice."},
{"content": "Mount Everest is the highest mountain in the world."},
],
}]
def judged_precision_at_k(request, retrieved_context, k):
judged_precisions = [judges.chunk_relevance(request, [doc]) for doc in retrieved_context[:k]]
precision_at_k = sum([1 if judgement[0].value =='yes' else 0 for judgement in judged_precisions]) / k
rationales = [
f"""## Chunk ID {i+1}: `{retrieved_context[i]['doc_uri']}`
- **{judged_precisions[i][0].value}**: `{judged_precisions[i][0].rationale}`"""
for i in range(0, k-1)]
return Assessment(name=f'judged_precision_at_{k}', value=precision_at_k, rationale='\n'.join(rationales))
@metric
def judged_precision_at_3(request, retrieved_context):
k = 3
return judged_precision_at_k(request=request, retrieved_context=retrieved_context, k=k)
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["chunk_relevance"]
}
},
extra_metrics=[judged_precision_at_3]
)
呼び出し可能なジャッジSDKでchunk_relevance
を使用します。
from databricks.agents.evals import judges
# NOTE: This callable judge returns an assessment per item in the retrieved context.
assessments = judges.chunk_relevance(
request="What is the capital of France?",
retrieved_context=[
{"content": "Paris is the capital city of France."},
{"content": "The chicken crossed the road."},
]
)
print(assessments)
ドキュメントのリコール
定義:レトリーバーは既知の関連文書のうちいくつを見つけましたか?
グラウンドトゥルースが必要です:はい、 expected_retrieved_context[].doc_uri
。
ドキュメントリコールは、取得されたグラウンドトゥルース関連ドキュメントの割合を、グラウンドトゥルースの関連ドキュメントの総数と比較して測定します。
必須入力
入力評価セットには、次の列が必要です。
expected_retrieved_context[].doc_uri
また、 mlflow.evaluate()
の呼び出しで model
引数を使用しない場合は、 retrieved_context[].doc_uri
または trace
も指定する必要があります。
例:
評価セットからのドキュメント再現率を使用します。
import mlflow
eval_set = [{
"request": "What is the capital of France?",
"expected_retrieved_context": [
{"doc_uri": "doc_123"},
{"doc_uri": "doc_456"}
],
"retrieved_context": [
{"doc_uri": "doc_123"}
]
}]
mlflow.evaluate(
data=eval_set,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
"metrics": ["document_recall"]
}
}
)
このメトリクスには、AIジャッジを使用しないため、呼び出し可能なジャッジSDKはありません。