フィーチャービューを提供する
プレビュー
この機能は パブリック プレビュー段階です。ワークスペース管理者は、 プレビュー ページからこの機能へのアクセスを制御できます。Databricksのプレビューを管理するを参照してください。
Feature Viewsをオンラインで提供するには、2つの方法があります:
- モデルサービング : フィービューでトレーニングされたモデルをデプロイします。Endpointは、モデルのログ記録時に追跡されたリネージを使用して、特徴量の値を自動的に検索またはコンピュートします。モデルの予測を提供するには、これを使用します。
- Feature Serving : モデルを持たずに、Feature Viewを直接参照する
FeatureSpecをデプロイします。Endpointは要求された特徴量出力を返します。アプリケーションがモデルの予測ではなく特徴量の値を必要とする場合に使用します。
Both approaches support precomputed and on-demand features.Table- and ストリーム-backed leaf features must have supported online materializations.RequestSource supplies values from the request, and CustomUDF computes features on demand.For a CustomUDF with FeatureViewSource, serving resolves upstream dependencies and evaluates the feature dependency graph automatically.
リクエストされた特徴量と、そのすべての推移的上流特徴量を Unity Catalog に登録します。リクエスト時または派生した CustomUDF 特徴量ではなく、テーブルおよびストリームを基盤とするリーフのみをマテリアライズします。
権限
特徴量をサーブするには、モデルサービングエンドポイントを作成するプリンシパルは、マテリアライズされた特徴量をバックアップするUnity Catalogテーブルに対してSELECTを持っている必要があります。オンラインルックアップはマテリアライズされたテーブルから直接読み取るため、テーブルレベルのSELECTがサービングアクセスを付与します。特権の説明については、SELECTを参照してください。
マテリアライズされたテーブルは複数の特徴量を含むことができるため、それに対してSELECTを付与すると、サーブを意図する特徴量だけでなく、そのテーブル内のすべての特徴量へのアクセスも付与されます。サービングアクセスを付与する前に、テーブルを共有するすべての特徴量がプリンシパルと共有できることを確認してください。リスクを軽減するため、機密性の高い特徴量を個別にマテリアライズします。
手動でテーブルを解決せずにこのアクセスを付与するには、FeatureEngineeringClient.grant_feature_serving_accessを使用します。モデルまたはフィーチャースペックが指定されると、各特徴量がオンラインテーブルに解決され、指定したプリンシパルに、それらのテーブルに対するSELECT(USE CATALOGとUSE SCHEMAとともに)が付与され、各テーブルとこの付与によって公開される追加機能のレポートが返されます。付与する前にレポートをプレビューするには、dry_run=Trueを渡します。
from databricks.feature_engineering import FeatureEngineeringClient
fe = FeatureEngineeringClient()
# Preview the tables and the features each grant would expose.
report = fe.grant_feature_serving_access(
grant_to=["serving-principal@example.com"],
model_uri="models:/main.ecommerce.fraud_model/1",
dry_run=True,
)
print(report)
# Grant SELECT on the resolved online tables.
fe.grant_feature_serving_access(
grant_to=["serving-principal@example.com"],
model_uri="models:/main.ecommerce.fraud_model/1",
)
モデルサービングエンドポイントをデプロイする
既存のモデルビングサー エンドポイントを使用するか、 Databricks SDKを使用して新しいエンドポイントを作成します。 モデルはUnity Catalogに登録する必要があります。
CustomUDF が Python パッケージをインポートするユーザー定義関数 (UDF) を使用する場合は、log_model を呼び出すときに extra_pip_requirements を介してそれらを明示的に渡します。カスタム UDF 依存関係を参照してください。
次のコードは、新しいモデルサービング エンドポイントを作成する方法を示しています。 詳細については、 「カスタム モデルサービング エンドポイントの作成」を参照してください。
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.serving import EndpointCoreConfigInput, ServedEntityInput
w = WorkspaceClient()
endpoint_name = "fraud-detection-endpoint"
model_name = "main.ecommerce.fraud_model"
w.serving_endpoints.create(
name=endpoint_name,
config=EndpointCoreConfigInput(
name=endpoint_name,
served_entities=[
ServedEntityInput(
entity_name=model_name,
entity_version=1,
max_provisioned_concurrency=4,
min_provisioned_concurrency=0,
)
],
),
)
エンドポイントにクエリを実行する
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
response = w.serving_endpoints.query(
name="fraud-detection-endpoint",
dataframe_records=[
{"user_id": "user_123", "transaction_time": "2026-03-01T12:00:00"},
],
)
RequestSource機能を使用してエンドポイントを照会する
モデルがRequestSource特徴量でトレーニングされている場合、リクエストペイロードにはすべてのRequestSource列も含まれている必要があります。これらの列はlog_model際にMLflowモデルの署名に追加されたため、エンドポイントのAPIスキーマは必要なリクエストフィールドを反映しています。
response = w.serving_endpoints.query(
name="fraud-detection-endpoint",
dataframe_records=[
{
"user_id": "user_123",
"transaction_time": "2026-03-01T12:00:00",
"transaction_amount": 275.30, # RequestSource column
"vendor_id": "v_42", # RequestSource column (also used as entity key)
},
],
)
エンティティキーは、オンラインストアからテーブルを基盤とする特徴量を検索するために使用されます。ColumnSelection 特徴量は、RequestSource の値をモデルに渡すことができます。CustomUDF 特徴量は、モデルが結果を使用する前にリクエスト入力を変換します。
curlも使用できます。
curl -X POST "https://<workspace>.cloud.databricks.com/serving-endpoints/<endpoint>/invocations" \
-H "Authorization: Bearer $DATABRICKS_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"dataframe_records": [
{
"user_id": "user_123",
"transaction_time": "2026-03-01T12:00:00",
"transaction_amount": 275.30,
"vendor_id": "v_42"
}
]
}'
特徴を配信します FeatureSpec
モデルなしでFeature Viewsを提供するには、特徴量を参照するFeatureSpecを作成し、それをFeature Serving Endpointにデプロイします。Endpointは、スペックで要求された特徴量出力のみを返します。それらの特徴量も要求しない限り、中間値を返さずに自動的にコンピュートします。
Unity Catalogにすべての特徴量を登録し、Endpointを作成する前に、テーブルおよびストリームを基盤とするリーブのサポートされているオンラインマテリアライゼーションを作成します。
フィーチャービューを含むFeatureSpecには、FeatureLookupまたはFeatureFunctionの定義を含めることはできません。フィーチャービューを同じFeatureSpec内のそれらの定義と混在させることはできません。
from databricks.feature_engineering import FeatureEngineeringClient
from databricks.feature_engineering.entities.feature_serving_endpoint import (
EndpointCoreConfig,
ServedEntity,
)
fe = FeatureEngineeringClient()
# 1. Retrieve a registered Feature View
agg_feature = fe.get_feature(full_name="main.ecommerce.amount_sum_sliding_7d_1d")
# 2. Create a FeatureSpec that includes the Feature View
feature_spec_name = "main.ecommerce.transaction_feature_spec"
fe.create_feature_spec(name=feature_spec_name, features=[agg_feature])
# 3. Deploy a Feature Serving endpoint backed by the FeatureSpec
fe.create_feature_serving_endpoint(
name="transaction-features",
config=EndpointCoreConfig(
served_entities=ServedEntity(
feature_spec_name=feature_spec_name,
workload_size="Small",
scale_to_zero_enabled=True,
)
),
)
実体化された特徴量をルックアップするために使用されるエンティティキーでエンドポイントをクエリします:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
response = w.serving_endpoints.query(
name="transaction-features",
dataframe_records=[{"user_id": "user_123"}],
)
Feature Servingエンドポイントの詳細については、Feature Servingエンドポイントを参照してください。
CustomUDF の特徴量とその依存関係を提供する
この例では、CustomUDF および FeatureViewSource の各例で定義されているトランザクションおよびマージンの特徴量を提供します。これらの特徴量ビュー APIs には、databricks-feature-engineering バージョン 0.18.0 以降を使用してください。
log_transaction_amountNumPy を使用して、リクエストのtransaction_amount値にmain.ecommerce.log_amount_udfを適用します。marginFeatureViewSourceを使用して、revenue_sum_7dとcost_sum_7dからマージンをコンピュートします。これらのアップストリーム特徴量は、customer_idをエンティティキーとして、event_time時系列カラムとして使用します。
仕様を作成する前に、出力特徴量と上流の特徴量の両方を登録します。この例では、revenue_sum_7d および cost_sum_7d のリーフのみをオンラインマテリアライズします。サービングではそれらの値が検索され、リクエストごとに margin がコンピュートされます。
登録済みの Feature オブジェクトを取得し、create_feature_spec に渡します。UDF の ENVIRONMENT 句にすでに記載されている場合でも、オンライン実行用に NumPy を宣言します。
from databricks.feature_engineering import FeatureEngineeringClient
fe = FeatureEngineeringClient()
log_transaction_amount = fe.get_feature(
full_name="main.ecommerce.log_transaction_amount"
)
margin = fe.get_feature(full_name="main.ecommerce.margin")
fe.create_feature_spec(
name="main.ecommerce.derived_transaction_features",
features=[log_transaction_amount, margin],
extra_pip_requirements=["numpy==1.26.4"],
)
feature_spec_name="main.ecommerce.derived_transaction_features"とderived-transaction-featuresなどのEndpoint名を使用して、上記のEndpoint作成ステップに従ってください。After the Endpoint is ready, supply the lookup key and request-time value:
from databricks.sdk import WorkspaceClient
w = WorkspaceClient()
response = w.serving_endpoints.query(
name="derived-transaction-features",
dataframe_records=[
{"customer_id": "customer_123", "transaction_amount": 99.0},
],
)
The response contains only the requested log_transaction_amount and margin outputs, not the intermediate revenue and cost values.For dependency formats, wheel permissions, and installation troubleshooting, see Add Python dependencies.