メインコンテンツまでスキップ

宣言的機能を具体化して提供する

備考

ベータ版

この機能はベータ版であり、次のリージョンで利用できます: us-east-1およびus-west-2

Unity Catalogに保存される宣言的な機能定義を作成したら、機能定義を使用して ソース テーブルから機能データを生成できます。 このプロセスは、機能の具体化と呼ばれます。Databricks 、 LakeFlow Spark宣言型パイプラインを作成および管理し、モデルのトレーニングとバッチ スコアリングまたはオンライン サービスのためにUnity Catalogにテーブルを設定します。

要件

  • 機能は宣言型機能APIを使用して作成し、 Unity Catalogに保存する必要があります。
  • バージョン要件については、 「要件」を参照してください。

APIデータ構造

OfflineStoreConfig

具体化された機能が書き込まれるオフラインストアの設定。materialize_featuresが呼び出されると、Feature Storeのバックエンドはこのプレフィックスを使用してテーブルを作成します。 各パイプライン実行時に、最新のフィーチャー値が実装スケジュールに従ってテーブルに実装されます。

Python
OfflineStoreConfig(
catalog_name: str, # Catalog name for the offline table where materialized features will be stored
schema_name: str, # Schema name for the offline table
table_name_prefix: str # Table name prefix for the offline table. The pipeline may create multiple tables with this prefix, each updated at different cadences
)
Python
from databricks.feature_engineering.entities import OfflineStoreConfig

offline_store = OfflineStoreConfig(
catalog_name="main",
schema_name="feature_store",
table_name_prefix="customer_features"
)

OnlineStoreConfig

モデルサービングで使用される機能を保存するオンラインストアの設定。 マテリアライゼーションにより、 catalog.schema.table_name_prefixを使用してDeltaテーブルが作成され、同じ名前でオンラインFeature Storeにテーブルがストリーム配信されます。

Python
from databricks.feature_engineering.entities import OnlineStoreConfig

online_store = OnlineStoreConfig(
catalog_name="main",
schema_name="feature_store",
table_name_prefix="customer_features_serving",
online_store_name="customer_features_store"
)

MaterializedFeature

マテリアライズされた、つまりUnity Catalogで使用できる事前計算済みの表現を持つ宣言型機能を表します。 オフライン テーブルとオンライン テーブルには、別個のマテリアライズド フィーチャがあります。通常、ユーザーはMaterializedFeatureを直接インスタンス化しません。

API関数呼び出し

materialize_features()

宣言的機能のリストをオフラインDeltaテーブルまたはオンラインFeature Storeに具体化します。

Python
FeatureEngineeringClient.materialize_features(
features: List[Feature], # List of declarative features to materialize
offline_config: OfflineStoreConfig, # Offline store config if materializing offline
online_config: Optional[OnlineStoreConfig] = None, # Online store config if materializing online
pipeline_state: Union[MaterializedFeaturePipelineScheduleState, str], # Materialization pipeline state - must be "ACTIVE"
cron_schedule: Optional[str] = None, # Materialization schedule, specified in quartz cron syntax. Currently must be provided.
) -> List[MaterializedFeature]:

このメソッドは、具体化された機能のリストを返します。これには、機能値が更新されたときの cron スケジュールなどのメタデータと、機能が具体化されたUnity Catalogテーブルに関する情報が含まれます。

OnlineStoreConfigOfflineStoreConfigの両方が指定されている場合は、指定された機能ごとに 2 つの具体化された機能が返され、ストアの種類ごとに 1 つずつになります。

オフラインストアに具体化

Python
from databricks.feature_engineering import FeatureEngineeringClient
from databricks.feature_engineering.entities import OfflineStoreConfig

fe = FeatureEngineeringClient()

materialized = fe.materialize_features(
features=features,
offline_config=OfflineStoreConfig(
catalog_name="main",
schema_name="feature_store",
table_name_prefix="customer_features"
),
pipeline_state="ACTIVE",
cron_schedule="0 0 * * * ?" # Hourly
)

オンラインストアに具体化

注記

機能をオンライン ストアに具体化するには、オフライン ストアにも具体化する必要があります。 offline_configonline_config両方が必須です。

Python
from databricks.feature_engineering import FeatureEngineeringClient
from databricks.feature_engineering.entities import OfflineStoreConfig, OnlineStoreConfig

fe = FeatureEngineeringClient()

materialized = fe.materialize_features(
features=features,
offline_config=OfflineStoreConfig(
catalog_name="main",
schema_name="feature_store",
table_name_prefix="customer_features"
),
online_config=OnlineStoreConfig(
catalog_name="main",
schema_name="feature_store",
table_name_prefix="customer_features_serving",
online_store_name="customer_features_store"
),
pipeline_state="ACTIVE",
cron_schedule="0 0 * * * ?" # Hourly
)

list_materialized_features()

ユーザーのUnity Catalogメタストア内のすべての具体化された機能のリストを返します。

デフォルトでは、最大 100 個の機能が返されます。この制限は、 max_results問題を使用して変更できます。

返された具体化された機能を機能名でフィルタリングするには、オプションのfeature_name問題を使用します。

Python
FeatureEngineeringClient.list_materialized_features(
feature_name: Optional[str] = None, # Optional feature name to filter by
max_results: int = 100, # Maximum number of features to be returned
) -> List[MaterializedFeature]:

マテリアライズドフィーチャを削除する方法

マテリアライズドフィーチャを削除するには、 list_materialized_features()を使用します。table_name属性を確認し、 Unity Catalog内のそのテーブルに移動して、その機能を含むテーブルを削除します。 [リネージ] タブを使用して、関連するパイプラインを特定し、それらも削除します。 最後に、オンライン テーブルの場合は、オフライン パイプラインとテーブルも削除されていることを確認します。

ベータ版では、削除APIsサポートされていません。 必要に応じて、 Databricks UI を使用してフィーチャ パイプラインと特徴量テーブルを手動で削除できます。

リアルタイムアプリケーションでのオンライン特徴量の使用

重要

Feature Servingエンドポイントは、宣言型機能エンジニアリングではサポートされていません。 機能をオンラインで提供するには、 Unity Catalogを通じて記録されたモデルを使用してモデルサービング エンドポイントをデプロイします。

Databricksの特徴を使用してトレーニングされたモデルは、トレーニングに使用された特徴に自動的に追跡します。 モデルビングサー エンドポイントとしてデプロイされる場合、これらのモデルはUnity Catalog使用してオンライン ストアから機能を検索します。

モデルサービングエンドポイントをデプロイする

MLflow Deployments SDKを使用して、 Unity Catalogに登録されているモデルのモデルサービング エンドポイントを作成します。

Python
import mlflow.deployments

client = mlflow.deployments.get_deploy_client("databricks")

# Create a serving endpoint for a UC model
endpoint = client.create_endpoint(
name="fraud-detection-endpoint",
config={
"served_entities": [
{
"entity_name": "main.ecommerce.fraud_model",
"entity_version": "1",
"workload_size": "Small",
"scale_to_zero_enabled": True,
}
]
},
)

モデルサービング エンドポイントの構成の詳細については、 「カスタム モデルサービング エンドポイントの作成」を参照してください。

エンドポイントをクエリする

Python
import mlflow.deployments

client = mlflow.deployments.get_deploy_client("databricks")

response = client.predict(
endpoint="fraud-detection-endpoint",
inputs={
"dataframe_records": [
{"user_id": "user_123", "transaction_time": "2026-03-01T12:00:00"},
]
},
)

制限事項

  • 連続したフィーチャを具体化することはできません。時間の正確さの忠実度が高いため、オフライン トレーニングまたはバッチ推論のための連続的な特徴が各データポイントに対してオンザフライで生成されます。
  • 機能の削除と一時停止は、パイプライン レベルで手動で管理する必要があります。