スコアラー ライフサイクル管理 API リファレンス
ベータ版
この機能は ベータ版です。
このページでは、本番運用モニタリングの実装方法について説明します。 Databricksでの本番運用モニタリングのガイドについては、 「GenAI の本番運用モニタリング」を参照してください。
スコアラーインスタンスメソッド
Scorer.register()
API リファレンス: Scorer.register
カスタムスコアラー関数をサーバーに登録します。 @scorer
デコレータで作成されたスコアラーに使用されます。
@scorer
def custom_scorer(outputs):
return len(str(outputs.get("response", "")))
# Register the custom scorer
my_scorer = custom_scorer.register(name="response_length")
パラメーター:
name
(str): エクスペリメント内のスコアラーの一意の名前。 デフォルトはスコアラーの既存の名前です。
戻り値: サーバー登録を含む新しい Scorer
インスタンス
Scorer.start()
API リファレンス: Scorer.start
指定されたサンプリング構成でオンライン評価を開始します。
from mlflow.genai.scorers import ScorerSamplingConfig
# Start monitoring with sampling
active_scorer = registered_scorer.start(
sampling_config=ScorerSamplingConfig(
sample_rate=0.5,
filter_string="trace.status = 'OK'"
),
)
パラメーター:
name
(str): スコアラーの名前。指定しない場合、デフォルトはスコアラーの現在の名前になります。sampling_config
(ScorerSamplingConfig
): トレースサンプリング構成sample_rate
(float): 評価するトレースの割合 (0.0-1.0)。デフォルト: 1.0filter_string
(str、省略可能): トレース選択用の MLflow 互換フィルター
戻り値: アクティブな状態の新しい Scorer
インスタンス
Scorer.update()
API リファレンス: Scorer.update
アクティブなスコアラーのサンプリング構成を変更します。これは不変の操作です。
# Update sampling rate (returns new scorer instance)
updated_scorer = active_scorer.update(
sampling_config=ScorerSamplingConfig(
sample_rate=0.8,
),
)
# Original scorer remains unchanged
print(f"Original: {active_scorer.sample_rate}") # 0.5
print(f"Updated: {updated_scorer.sample_rate}") # 0.8
パラメーター:
name
(str): スコアラーの名前。指定しない場合、デフォルトはスコアラーの現在の名前になります。sampling_config
(ScorerSamplingConfig
): トレースサンプリング構成sample_rate
(float): 評価するトレースの割合 (0.0-1.0)。デフォルト: 1.0filter_string
(str、省略可能): トレース選択用の MLflow 互換フィルター
戻り値: 設定が更新された新しい Scorer
インスタンス
Scorer.stop()
API リファレンス: Scorer.stop
サンプルレートを0に設定して、オンライン評価を停止します。スコアラーを登録したままにします。
# Stop monitoring but keep scorer registered
stopped_scorer = active_scorer.stop()
print(f"Sample rate: {stopped_scorer.sample_rate}") # 0
パラメーター:
name
(str): スコアラーの名前。指定しない場合、デフォルトはスコアラーの現在の名前になります。
戻り値: sample_rate=0 の新しい Scorer
インスタンス
スコアラーレジストリ機能
mlflow.genai.scorers.get_scorer()
API リファレンス: get_scorer
登録済みのスコアラーを名前で取得します。
from mlflow.genai.scorers import get_scorer
# Get existing scorer by name
existing_scorer = get_scorer(name="safety_monitor")
print(f"Current sample rate: {existing_scorer.sample_rate}")
パラメーター:
name
(str): 登録されたスコアラーの名前
戻り値: Scorer
インスタンス
mlflow.genai.scorers.list_scorers()
現在のエクスペリメントに登録されているすべてのスコアラーをリストします。
from mlflow.genai.scorers import list_scorers
# List all registered scorers
all_scorers = list_scorers()
for scorer in all_scorers:
print(f"Name: {scorer._server_name}")
print(f"Sample rate: {scorer.sample_rate}")
print(f"Filter: {scorer.filter_string}")
戻り値: Scorer
インスタンスのリスト
mlflow.genai.scorers.delete_scorer()
API リファレンス: delete_scorer
登録したスコアラーを名前で削除します。
from mlflow.genai.scorers import delete_scorer
# Delete existing scorer by name
delete_scorer(name="safety_monitor")
パラメーター:
name
(str): 登録されたスコアラーの名前
戻り値: None
スコアラーのプロパティ
Scorer.sample_rate
現在のサンプリングレート(0.0-1.0)。停止したスコアラーに対して 0 を返します。
print(f"Sampling {scorer.sample_rate * 100}% of traces")
Scorer.filter_string
MLflow トレース選択用の現在のトレース フィルター文字列。
print(f"Filter: {scorer.filter_string}")
構成クラス
ScorerSamplingConfig
API リファレンス: ScorerSamplingConfig
スコアラーのサンプリング構成を保持するデータクラス。
from mlflow.genai import ScorerSamplingConfig
config = ScorerSamplingConfig(
sample_rate=0.5,
filter_string="trace.status = 'OK'"
)
属性:
sample_rate
(float、オプション): サンプリングレート 0.0 から 1.0 までfilter_string
(str、省略可能): MLflow トレース フィルター
メトリクス バックフィル
backfill_scorers()
from databricks.agents.scorers import backfill_scorers, BackfillScorerConfig
job_id = backfill_scorers(
experiment_id="your-experiment-id",
scorers=[
BackfillScorerConfig(scorer=safety_scorer, sample_rate=0.8),
BackfillScorerConfig(scorer=response_length, sample_rate=0.9)
],
start_time=datetime(2024, 1, 1),
end_time=datetime(2024, 1, 31)
)
パラメーター:
すべてのパラメーターはキーワードのみです。
experiment_id
(str、オプション): バックフィルするエクスペリメントの ID。指定しない場合は、現在のエクスペリメントコンテキストを使用しますscorers
(Union[List[BackfillScorerConfig], List[str]], required): カスタムサンプルレートを持つBackfillScorerConfig
オブジェクトのリスト (BackfillScorerConfig でsample_rateが指定されていない場合、デフォルトは登録されたスコアラーのサンプルレートに)、またはエクスペリメントのスケジュールされたスコアラーからの現在のサンプルレートを使用するスコアラー名 (文字列) のリスト。空にすることはできません。start_time
(datetime、オプション): バックフィル評価の開始時刻。指定しない場合、開始時間の制約は適用されませんend_time
(datetime、オプション): バックフィル評価の終了時刻。指定しない場合、終了時間の制約は適用されません
戻り値: ステータス追跡用に作成されたバックフィルジョブのジョブ ID (str)