Agent Evaluation から MLflow 3 への移行
エージェント評価が Databricks 上の MLflow 3 と統合されました。エージェント評価SDKメソッドは、 mlflow[databricks]>=3.1 SDKを介して mlflow.genai 名前空間で公開されるようになりました。MLflow 3 では、次の機能が導入されています。
- すべての SDK 機能をミラーリングする 更新された UI
- 評価の実行、人間によるラベリング、および評価データセットの管理のための簡素化されたAPIsを備えた 新しいSDK
mlflow.genai - リアルタイムオブザーバビリティを提供する本番運用規模のトレースインジェストバックエンドによる トレースの強化
- 人間によるフィードバック収集の効率化
- 組み込みスコアラーとしての LLMジャッジの改善
このガイドは、エージェント評価 (MLflow 2.x with databricks-agents<1.0) から MLflow 3 への移行に役立ちます。この詳細なガイドは、 クイックリファレンス 形式でも入手できます。
Agent Evaluation を使用した MLflow 3 は、マネージド MLflowでのみ機能し、オープンソース MLflowでは機能しません。マネージドとオープンソースのMLflowページを表示して、マネージドMLflowとオープンソースの違いをより深く理解してください。
移行チェックリスト
このチェックリストを使用して開始します。各項目は、以下のセクションの詳細にリンクしています。
評価API
LLMジャッジ
- 可能な場合は、ジャッジの直接のコールを事前定義されたスコアラーに置き換える
-
judges.guideline_adherence()をjudges.meets_guidelines()またはGuidelines()スコアラーに更新 - 新しいAPIと一致するように judge 関数パラメーター名を更新します
- グラウンドトゥルースに基づくガイドラインに
ExpectationsGuidelines()の使用を検討する
人間のフィードバック
- ラベリングセッションの更新とアプリのインポートの
mlflow.genai.labelingへのレビュー - ラベルスキーマのインポートを
mlflow.genai.label_schemasに更新する - フィードバックをデータセットに同期するための更新ロジック
避けるべき一般的な落とし穴
- DataFramesのデータフィールド名を更新することを忘れないでください
model_type="databricks-agent"はもう必要ありません- カスタムスコアラーが有効な値を返すことを確認します (合格/不合格の場合は「はい」/「いいえ」)
- 結果テーブルに直接アクセスする代わりに
search_traces()を使用します - コード内のハードコーディングされた名前空間参照を更新する
- すべてのスコアラーを明示的に指定することを忘れないでください - MLflow 3 では、ジャッジは自動的に実行されません
global_guidelinesをコンフィグから明示的なGuidelines()スコアラーに変換する
評価 API の移行
更新プログラムのインポート
以下のリストは、更新するインポートをまとめたもので、以下の各サブセクションに詳細と例があります。
# Old imports
from mlflow import evaluate
from databricks.agents.evals import metric
from databricks.agents.evals import judges
# New imports
from mlflow.genai import evaluate
from mlflow.genai.scorers import scorer
from mlflow.genai import judges
# For predefined scorers:
from mlflow.genai.scorers import (
Correctness, Guidelines, ExpectationsGuidelines,
RelevanceToQuery, Safety, RetrievalGroundedness,
RetrievalRelevance, RetrievalSufficiency
)
mlflow.evaluate()から mlflow.genai.evaluate()
コア評価 API は、よりクリーンなパラメーター名を持つ専用の GenAI 名前空間に移動しました。
MLflow 2.x | MLflow 3.x | 注 |
|---|---|---|
|
| 新しい名前空間 |
|
| よりわかりやすい名前 |
| 不要 | 自動的に検出される |
|
| より明確な用語 |
| 不要 | スコアラーの一部 |
MLflow 2.x フィールド | MLflow 3.x フィールド | 説明 |
|---|---|---|
|
| エージェント入力 |
|
| エージェントの出力 |
|
| グラウンドトゥルース |
| トレース経由でアクセス | トレースからのコンテキスト |
| スコアラー設定の一部 | スコアラーレベルに移動 |
例:基本評価
MLflow 2.x の場合:
import mlflow
import pandas as pd
eval_data = [
{
"request": "What is MLflow?",
"response": "MLflow is an open-source platform for managing ML lifecycle.",
"expected_response": "MLflow is an open-source platform for managing ML lifecycle.",
},
{
"request": "What is Databricks?",
"response": "Databricks is a unified analytics platform.",
"expected_response": "Databricks is a unified analytics platform for big data and AI.",
},
]
# Note: By default, MLflow 2.x runs all applicable judges automatically
results = mlflow.evaluate(
data=eval_data,
model=my_agent,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
# Optional: limit to specific judges
# "metrics": ["correctness", "safety"],
# Optional: add global guidelines
"global_guidelines": {
"clarity": ["Response must be clear and concise"]
}
}
}
)
# Access results
eval_df = results.tables['eval_results']
MLflow 3.x の場合:
import mlflow
import pandas as pd
from mlflow.genai.scorers import Guidelines
eval_data = [
{
"inputs": {"request": "What is MLflow?"},
"outputs": {
"response": "MLflow is an open-source platform for managing ML lifecycle."
},
"expectations": {
"expected_response":
"MLflow is an open-source platform for managing ML lifecycle.",
},
},
{
"inputs": {"request": "What is Databricks?"},
"outputs": {"response": "Databricks is a unified analytics platform."},
"expectations": {
"expected_response":
"Databricks is a unified analytics platform for big data and AI.",
},
},
]
# Define guidelines for scorer
guidelines = {
"clarity": ["Response must be clear and concise"],
# supports str or list[str]
"accuracy": "Response must be factually accurate",
}
print("Running evaluation with mlflow.genai.evaluate()...")
with mlflow.start_run(run_name="basic_evaluation_test") as run:
# Run evaluation with new API
# Note: Must explicitly specify which scorers to run (no automatic selection)
results = mlflow.genai.evaluate(
data=eval_data,
scorers=[
Correctness(), # Requires expectations.expected_response
RelevanceToQuery(), # No ground truth needed
Guidelines(name="clarity", guidelines=guidelines["clarity"]),
Guidelines(name="accuracy", guidelines=guidelines["accuracy"]),
# ExpectationsGuidelines(),
# Add more scorers as needed: Safety(), RetrievalGroundedness(), etc.
],
)
# Access results using search_traces
traces = mlflow.search_traces(
run_id=results.run_id,
)
評価結果へのアクセス
MLflow 3 では、評価結果は評価と共にトレースとして格納されます。mlflow.search_traces()を使用して、詳細な結果にアクセスします。
# Access results using search_traces
traces = mlflow.search_traces(
run_id=results.run_id,
)
# Access assessments for each trace
for trace in traces:
assessments = trace.info.assessments
for assessment in assessments:
print(f"Scorer: {assessment.name}")
print(f"Value: {assessment.value}")
print(f"Rationale: {assessment.rationale}")
MLflow LoggedModel の評価
MLflow 2.x では、ログに記録された MLflow モデル (PyFunc モデルや Agent Framework によってログ記録されたモデルなど) を直接 mlflow.evaluate()に渡すことができます。MLflow 3.x では、パラメーター マッピングを処理するために、モデルを predict 関数でラップする必要があります。
このラッパーが必要なのは、 mlflow.genai.evaluate() データセットの inputs dict のキーをキーワード引数として受け取る predict 関数を期待しているのに対し、ほとんどの記録済みモデルは単一の入力パラメーター (PyFuncモデルの場合は model_inputs 、 LangChain モデルの場合は同様のインターフェース) を受け入れるためです。
predict 関数は、評価フレームワークの名前付きパラメーターとモデルの想定される入力形式との間の変換レイヤーとして機能します。
import mlflow
from mlflow.genai.scorers import Safety
# Make sure to load your logged model outside of the predict_fn so MLflow only loads it once!
model = mlflow.pyfunc.load_model("models:/chatbot/staging")
def evaluate_model(question: str) -> dict:
return model.predict({"question": question})
results = mlflow.genai.evaluate(
data=[{"inputs": {"question": "Tell me about MLflow"}}],
predict_fn=evaluate_model,
scorers=[Safety()]
)
カスタムメトリクスからスコアラーへの移行
カスタム評価関数 (@metric) は、簡略化された署名を持つ @scorer デコレーターを使用するようになりました。
MLflow 2.x | MLflow 3.x | 注 |
|---|---|---|
|
| 新規名 |
|
| 簡易 |
複数の expected_* パラメータ | dict である 1 つの | 連結 |
|
| 簡易 |
|
| 一貫した命名 |
|
| 一貫した命名 |
例:合格/不合格スコアラー
MLflow 2.x の場合:
from databricks.agents.evals import metric
@metric
def response_length_check(request, response, expected_response=None):
"""Check if response is within acceptable length."""
length = len(response)
return "yes" if 50 <= length <= 500 else "no"
# Use in evaluation
results = mlflow.evaluate(
data=eval_data,
model=my_agent,
model_type="databricks-agent",
extra_metrics=[response_length_check]
)
MLflow 3.x の場合:
import mlflow
from mlflow.genai.scorers import scorer
# Sample agent function
@mlflow.trace
def my_agent(request: str):
"""Simple mock agent for testing - MLflow 3 expects dict input"""
responses = {
"What is MLflow?": "MLflow is an open-source platform for managing ML lifecycle.",
"What is Databricks?": "Databricks is a unified analytics platform.",
}
return {"response": responses.get(request, "I don't have information about that.")}
@scorer
def response_length_check(inputs, outputs, expectations=None, traces=None):
"""Check if response is within acceptable length."""
length = len(outputs)
return "yes" if 50 <= length <= 500 else "no"
# Use in evaluation
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[response_length_check]
)
例: 評価付きの数値スコアラー
MLflow 2.x の場合:
from databricks.agents.evals import metric, Assessment
def calculate_similarity(response, expected_response):
return 1
@metric
def semantic_similarity(response, expected_response):
"""Calculate semantic similarity score."""
# Your similarity logic here
score = calculate_similarity(response, expected_response)
return Assessment(
name="semantic_similarity",
value=score,
rationale=f"Similarity score based on embedding distance: {score:.2f}"
)
MLflow 3.x の場合:
from mlflow.genai.scorers import scorer
from mlflow.entities import Feedback
@scorer
def semantic_similarity(outputs, expectations):
"""Calculate semantic similarity score."""
# Your similarity logic here
expected = expectations.get("expected_response", "")
score = calculate_similarity(outputs, expected)
return Feedback(
name="semantic_similarity",
value=score,
rationale=f"Similarity score based on embedding distance: {score:.2f}"
)
LLMは移行を判断
ジャッジの行動の主な違い
MLflow 2.x | MLflow 3.x |
|---|---|
データに基づいて該当するすべてのジャッジを自動的に実行します | 使用するスコアラーを明示的に指定する必要があります |
|
|
|
|
利用可能なデータフィールドに基づいて選ばれるジャッジ | どのスコアラーを実行するかを正確に制御します |
MLflow 2.x の自動ジャッジ選択:
- グラウンドトゥルースなし:実行
chunk_relevance、groundedness、relevance_to_query、safety、guideline_adherence - グラウンドトゥルース付き:また、
context_sufficiencyを実行します、correctness
MLflow 3.x の明示的なスコアラー選択:
- 実行するスコアラーを明示的にリストする必要があります
- より詳細な制御が可能ですが、評価のニーズを明確にする必要があります
移行パス
ユースケース | MLflow 2.x | MLflow 3.x 推奨 |
|---|---|---|
基本的な正確性チェック |
|
|
安全性評価 |
|
|
グローバルガイドライン |
|
|
評価セット行ごとのガイドライン |
|
|
事実に基づく裏付けを確認する |
|
|
コンテキストの関連性を確認する |
|
|
コンテキストチャンクの関連性を確認する |
|
|
コンテキストの完全性を確認する |
|
|
複雑なカスタムロジック | 直接のジャッジコール | 事前定義されたスコアラーまたはジャッジコールによる |
MLflow 3 には、LLM ジャッジを使用する 2 つの方法があります。
- Predefined Scorers - 自動トレース解析でジャッジをラップする、すぐに使えるスコアラー
- 直接ジャッジコール - カスタムスコアラー内でジャッジに直接電話をかけ、よりコントロールを強化します
実行するジャッジの制御
例:実行するジャッジの指定
MLflow 2.x (デフォルトのジャッジの制限):
import mlflow
# By default, runs all applicable judges
# Use evaluator_config to limit which judges run
results = mlflow.evaluate(
data=eval_data,
model=my_agent,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
# Only run these specific judges
"metrics": ["groundedness", "relevance_to_query", "safety"]
}
}
)
MLflow 3.x (スコアラーの明示的な選択):
from mlflow.genai.scorers import (
RetrievalGroundedness,
RelevanceToQuery,
Safety
)
# Must explicitly specify which scorers to run
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[
RetrievalGroundedness(),
RelevanceToQuery(),
Safety()
]
)
包括的な移行の例
次の例は、カスタム構成で複数のジャッジを使用する評価を移行する方法を示しています。
MLflow 2.x の場合:
from databricks.agents.evals import judges, metric
import mlflow
# Custom metric using judge
@metric
def check_no_pii(request, response, retrieved_context):
"""Check if retrieved context contains PII."""
context_text = '\n'.join([c['content'] for c in retrieved_context])
return judges.guideline_adherence(
request=request,
guidelines=["The context must not contain personally identifiable information."],
guidelines_context={"retrieved_context": context_text}
)
# Define global guidelines
global_guidelines = {
"tone": ["Response must be professional and courteous"],
"format": ["Response must use bullet points for lists"]
}
# Run evaluation with multiple judges
results = mlflow.evaluate(
data=eval_data,
model=my_agent,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {
# Specify subset of built-in judges
"metrics": ["correctness", "groundedness", "safety"],
# Add global guidelines
"global_guidelines": global_guidelines
}
},
# Add custom judge
extra_metrics=[check_no_pii]
)
MLflow 3.x の場合:
from mlflow.genai.scorers import (
Correctness,
RetrievalGroundedness,
Safety,
Guidelines,
scorer
)
from mlflow.genai import judges
import mlflow
# Custom scorer using judge
@scorer
def check_no_pii(inputs, outputs, traces):
"""Check if retrieved context contains PII."""
# Extract retrieved context from trace
retrieved_context = traces.data.spans[0].attributes.get("retrieved_context", [])
context_text = '\n'.join([c['content'] for c in retrieved_context])
return judges.meets_guidelines(
name="no_pii",
context={
"request": inputs,
"retrieved_context": context_text
},
guidelines=["The context must not contain personally identifiable information."]
)
# Run evaluation with explicit scorers
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[
# Built-in scorers (explicitly specified)
Correctness(),
RetrievalGroundedness(),
Safety(),
# Global guidelines as scorers
Guidelines(name="tone", guidelines="Response must be professional and courteous"),
Guidelines(name="format", guidelines="Response must use bullet points for lists"),
# Custom scorer
check_no_pii
]
)
事前定義されたジャッジスコアラーへの移行
MLflow 3 には、LLM ジャッジをラップする定義済みのスコアラーが用意されているため、 mlflow.genai.evaluate()で使いやすくなっています。
例:正しさの判断
MLflow 2.x の場合:
from databricks.agents.evals import judges, metric
@metric
def check_correctness(request, response, expected_response):
"""Check if response is correct."""
return judges.correctness(
request=request,
response=response,
expected_response=expected_response
)
# Use in evaluation
results = mlflow.evaluate(
data=eval_data,
model=my_agent,
model_type="databricks-agent",
extra_metrics=[check_correctness]
)
MLflow 3.x (オプション 1: 定義済みのスコアラーを使用):
from mlflow.genai.scorers import Correctness
# Use predefined scorer directly
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[Correctness()]
)
MLflow 3.x (オプション 2: ジャッジ付きのカスタム スコアラー):
from mlflow.genai.scorers import scorer
from mlflow.genai import judges
@scorer
def check_correctness(inputs, outputs, expectations):
"""Check if response is correct."""
return judges.correctness(
request=inputs,
response=outputs,
expected_response=expectations.get("expected_response", "")
)
# Use in evaluation
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[check_correctness]
)
例:安全ジャッジ
MLflow 2.x の場合:
from databricks.agents.evals import judges, metric
@metric
def check_safety(request, response):
"""Check if response is safe."""
return judges.safety(
request=request,
response=response
)
MLflow 3.x の場合:
from mlflow.genai.scorers import Safety
# Use predefined scorer
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[Safety()]
)
例: 関連性ジャッジ
MLflow 2.x の場合:
from databricks.agents.evals import judges, metric
@metric
def check_relevance(request, response):
"""Check if response is relevant to query."""
return judges.relevance_to_query(
request=request,
response=response
)
MLflow 3.x の場合:
from mlflow.genai.scorers import RelevanceToQuery
# Use predefined scorer
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[RelevanceToQuery()]
)
例:グラウンディングネスジャッジ
MLflow 2.x の場合:
from databricks.agents.evals import judges, metric
@metric
def check_groundedness(response, retrieved_context):
"""Check if response is grounded in context."""
context_text = '\n'.join([c['content'] for c in retrieved_context])
return judges.groundedness(
response=response,
context=context_text
)
MLflow 3.x の場合:
from mlflow.genai.scorers import RetrievalGroundedness
# Use predefined scorer (automatically extracts context from trace)
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[RetrievalGroundedness()]
)
ガイドラインの遵守をmeets_guidelinesに移行する
guideline_adherence ジャッジの名前がより明確なAPIである meets_guidelines に変更されました。
MLflow 2.x の場合:
from databricks.agents.evals import judges, metric
@metric
def check_tone(request, response):
"""Check if response follows tone guidelines."""
return judges.guideline_adherence(
request=request,
response=response,
guidelines=["The response must be professional and courteous."]
)
@metric
def check_policies(request, response, retrieved_context):
"""Check if response follows company policies."""
context_text = '\n'.join([c['content'] for c in retrieved_context])
return judges.guideline_adherence(
request=request,
guidelines=["Response must comply with return policy in context."],
guidelines_context={
"response": response,
"retrieved_context": context_text
}
)
MLflow 3.x (オプション 1: 定義済みのガイドライン スコアラーを使用):
from mlflow.genai.scorers import Guidelines
# For simple guidelines that only need request/response
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[
Guidelines(
name="tone",
guidelines="The response must be professional and courteous."
)
]
)
MLflow 3.x (オプション 2: meets_guidelines を使用したカスタム スコアラー):
from mlflow.genai.scorers import scorer
from mlflow.genai import judges
@scorer
def check_policies(inputs, outputs, traces):
"""Check if response follows company policies."""
# Extract retrieved context from trace
retrieved_context = traces.data.spans[0].attributes.get("retrieved_context", [])
context_text = '\n'.join([c['content'] for c in retrieved_context])
return judges.meets_guidelines(
name="policy_compliance",
guidelines="Response must comply with return policy in context.",
context={
"request": inputs,
"response": outputs,
"retrieved_context": context_text
}
)
例: ExpectationsGuidelines の移行
評価セット内の各例のガイドラインを設定する場合 (特定のトピックを取り上げることや、応答が特定のスタイルに従うことを要求する場合など) は、MLflow 3.x の ExpectationsGuidelines スコアラーを使用します。
MLflow 2.x の場合:
MLflow 2.x では、次のようなガイドラインを実装します。
import pandas as pd
eval_data = {
"request": "What is MLflow?",
"response": "MLflow is an open-source platform for managing ML lifecycle.",
"guidelines": [
["The response must mention these topics: platform, observability, testing"]
],
}
eval_df = pd.DataFrame(eval_data)
mlflow.evaluate(
data=eval_df,
model_type="databricks-agent",
evaluator_config={
"databricks-agent": {"metrics": ["guideline_adherence"]}
}
)
MLflow 3.x の場合:
MLflow 3.x では、評価データを異なる方法で整理します。評価データの各エントリには expectations キーが必要であり、その中に guidelinesなどのフィールドを含めることができます。
評価データは次のようになります。
eval_data = [
{
"inputs": {"input": "What is MLflow?"},
"outputs": {"response": "MLflow is an open-source platform for managing ML lifecycle."},
"expectations": {
"guidelines": [
"The response should mention the topics: platform, observability, and testing."
]
}
}
]
次に、 ExpectationsGuidelines スコアラーを使用します。
import mlflow
from mlflow.genai.scorers import ExpectationsGuidelines
expectations_guideline = ExpectationsGuidelines()
# Use predefined scorer
results = mlflow.genai.evaluate(
data=eval_data, # Make sure each row has expectations.guidelines
predict_fn=my_app,
scorers=[
expectations_guideline
]
)
具体的な事実内容(例:「MLflow はオープンソースです」)を確認する必要がある場合は、ガイドラインの代わりにexpected_factsフィールドを持つ正確性スコアラーを使用します。正確性判定を参照してください。
MLflow 2.x の自動判定動作のレプリケート
該当するすべてのジャッジを実行する MLflow 2.x の動作をレプリケートするには、すべてのスコアラーを明示的に含めます。
MLflow 2.x (自動):
# Automatically runs all applicable judges based on data
results = mlflow.evaluate(
data=eval_data, # Contains expected_response and retrieved_context
model=my_agent,
model_type="databricks-agent"
)
MLflow 3.x (明示的):
from mlflow.genai.scorers import (
Correctness, RetrievalSufficiency, # Require ground truth
RelevanceToQuery, Safety, RetrievalGroundedness, RetrievalRelevance # No ground truth
)
# Manually specify all judges you want to run
results = mlflow.genai.evaluate(
data=eval_data,
predict_fn=my_agent,
scorers=[
# With ground truth judges
Correctness(),
RetrievalSufficiency(),
# Without ground truth judges
RelevanceToQuery(),
Safety(),
RetrievalGroundedness(),
RetrievalRelevance(),
]
)
直接のジャッジ使用
テストのためにジャッジを直接呼び出すこともできます。
from mlflow.genai import judges
# Test a judge directly (same in both versions)
result = judges.correctness(
request="What is MLflow?",
response="MLflow is an open-source platform for ML lifecycle.",
expected_response="MLflow is an open-source platform for managing the ML lifecycle."
)
print(f"Judge result: {result.value}")
print(f"Rationale: {result.rationale}")
人間のフィードバックの移行
ラベリングセッションとスキーマ
レビューアプリの機能は、 databricks.agents から mlflow.genai.labelingに移動しました。
名前空間の変更:
MLflow 2.x | MLflow 3.x |
|---|---|
|
|
|
|
|
|
|
|
例: ラベリング・セッションの作成
MLflow 2.x の場合:
from databricks.agents import review_app
import mlflow
# Get review app
my_app = review_app.get_review_app()
# Create custom label schema
quality_schema = my_app.create_label_schema(
name="response_quality",
type="feedback",
title="Rate the response quality",
input=review_app.label_schemas.InputCategorical(
options=["Poor", "Fair", "Good", "Excellent"]
)
)
# Create labeling session
session = my_app.create_labeling_session(
name="quality_review_jan_2024",
agent="my_agent",
assigned_users=["user1@company.com", "user2@company.com"],
label_schemas=[
review_app.label_schemas.EXPECTED_FACTS,
"response_quality"
]
)
# Add traces for labeling
traces = mlflow.search_traces(run_id=run_id)
session.add_traces(traces)
MLflow 3.x の場合:
import mlflow
import mlflow.genai.labeling as labeling
import mlflow.genai.label_schemas as schemas
# Create custom label schema
quality_schema = schemas.create_label_schema(
name="response_quality",
type=schemas.LabelSchemaType.FEEDBACK,
title="Rate the response quality",
input=schemas.InputCategorical(
options=["Poor", "Fair", "Good", "Excellent"]
),
overwrite=True
)
# Previously built in schemas must be created before use
# However, constant for their names are provided to ensure your schemas work with built-in scorers
expected_facts_schema = schemas.create_label_schema(
name=schemas.EXPECTED_FACTS,
type=schemas.LabelSchemaType.EXPECTATION,
title="Expected facts",
input=schemas.InputTextList(max_length_each=1000),
instruction="Please provide a list of facts that you expect to see in a correct response.",
overwrite=True
)
# Create labeling session
session = labeling.create_labeling_session(
name="quality_review_jan_2024",
assigned_users=["user1@company.com", "user2@company.com"],
label_schemas=[
schemas.EXPECTED_FACTS,
"response_quality"
]
)
# Add traces for labeling
traces = mlflow.search_traces(
run_id=session.mlflow_run_id
)
session.add_traces(traces)
# Get review app URL
app = labeling.get_review_app()
print(f"Review app URL: {app.url}")
フィードバックをデータセットに同期する
MLflow 2.x の場合:
# Sync expectations back to dataset
session.sync(to_dataset="catalog.schema.eval_dataset")
# Use dataset for evaluation
dataset = spark.read.table("catalog.schema.eval_dataset")
results = mlflow.evaluate(
data=dataset,
model=my_agent,
model_type="databricks-agent"
)
MLflow 3.x の場合:
from mlflow.genai import datasets
import mlflow
# Sample agent function
@mlflow.trace
def my_agent(request: str):
"""Simple mock agent for testing - MLflow 3 expects dict input"""
responses = {
"What is MLflow?": "MLflow is an open-source platform for managing ML lifecycle.",
"What is Databricks?": "Databricks is a unified analytics platform.",
}
return {"response": responses.get(request, "I don't have information about that.")}
# Sync expectations back to dataset
session.sync(to_dataset="catalog.schema.eval_dataset")
# Use dataset for evaluation
dataset = datasets.get_dataset("catalog.schema.eval_dataset")
results = mlflow.genai.evaluate(
data=dataset,
predict_fn=my_agent
)
追加のリソース
移行中のその他のサポートについては、MLflow のドキュメントを参照するか、Databricks サポート チームにお問い合わせください。