提供声明性功能

重要

此功能在 Beta 版中。 工作区管理员可以从 预览 页控制对此功能的访问。 请参阅 Manage Azure Databricks 预览版

重要

声明性特征工程不支持功能服务终结点。 为了在线提供功能,请使用通过 Unity Catalog 记录的模型部署模型服务终端节点。

使用 Databricks 中的特征训练的模型会自动跟踪世系,以跟踪他们训练的特征。 模型作为服务终结点进行部署时,这些模型使用 Unity Catalog 从在线商店检索特征。

部署模型服务端点

使用提供终结点的现有模型,或使用 Databricks SDK 创建新的模型。 模型必须在 Unity 目录中注册。

以下代码演示如何创建新的模型服务终结点。

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 列。 这些列添加到 MLflow 模型签名期间 log_model,因此终结点的 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)
        },
    ],
)

实体键用于从在线存储中查找基于表的功能。 RequestSource 列直接传递到模型。

也可使用 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"
      }
    ]
  }'