重要
此功能为 Beta 版,可在以下区域使用: us-east-1 和 us-west-2。
创建声明性功能定义(存储在 Unity 目录中)后,可以使用功能定义从源表生成特征数据。 此过程称为特征具体化。 Azure Databricks 创建和管理 Lakeflow Spark 声明性管道,以填充 Unity 目录中的表,以便进行模型训练和批量评分或联机服务。
要求
- 必须使用声明性功能 API 创建功能,并将其存储在 Unity 目录中。
- 有关版本要求,请参阅 要求。
API 数据结构
OfflineStoreConfig
用于存储物化特征的离线存储配置。 物化数据管道在此存储区中创建新表。
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
)
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 表,并将这些表流式传输到具有相同名称的 Lakebase 表。
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 表或在线特征存储。
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 - currently must be "ACTIVE"
cron_schedule: Optional[str] = None, # Materialization schedule, specified in quartz cron syntax. Currently must be provided.
) -> List[MaterializedFeature]:
此方法返回一个具体化特征的列表,其中包含更新特征值时的元数据,如计划任务时间表,以及有关这些特征被具体化到 Unity Catalog 表中的信息。
如果同时提供一个 OnlineStoreConfig 和一个 OfflineStoreConfig ,则为每个提供的功能返回两个具体化特征,每个类型的存储都有一个。
list_materialized_features()
返回用户 Unity Catalog 元数据存储中所有已具体化特性的列表。
默认情况下,最多返回 100 个功能。 可以使用参数更改此限制 max_results 。
若要按特征名称筛选返回的具体化特征,请使用可选 feature_name 参数。
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 中的该表,并删除包含该特性的表。 使用“ 世系 ”选项卡标识任何关联的管道并删除它们。 最后,确保在删除联机表时,也删除脱机流水线和表。
在 beta 版中,不支持删除 API。 如果需要,可以通过 Databricks UI 手动删除功能管道和功能表。
在实时应用程序中使用联机功能
若要为实时应用程序和服务提供功能,请创建功能服务终结点。 请参阅 功能服务终结点。
使用 Databricks 中的特征训练的模型会自动跟踪世系,以跟踪他们训练的特征。 部署为端点时,这些模型使用 Unity Catalog 从在线商店中查找适当的特征。 有关详细信息,请参阅 联机工作流中的“使用功能”。
局限性
- 无法实体化连续特征。
- 您只能在创建了实体化特征的工作区中使用它们。
- 必须在管道级别手动管理删除和暂停功能。