更新特征视图

您可以更新特征视图以修改与其关联的特征数据源列表。例如,您可能需要进行以下更新:

  • 关联不同的特征组和特征,或关联来自同一特征组的不同特征集。

  • 指定包含特征数据的其他 BigQuery 表或视图。请注意,在这种情况下,您还需要从更新后的数据源指定一个或多个实体 ID 列。

  • 指定来自同一 BigQuery 数据源的一组不同的实体 ID 列。

创建或更新特征视图时,您可以选择以标签形式向特征视图添加用户定义的元数据。如需详细了解如何更新特征视图的用户定义标签,请参阅更新特征视图的标签

准备工作

向 Vertex AI 进行身份验证,除非您已完成此操作。

如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。

    Install the Google Cloud CLI, then initialize it by running the following command:

    gcloud init

如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证

根据特征组更新特征视图

以下示例展示了如何通过指定现有特征组中的特征来更新特征视图。

REST

如需更新 FeatureView 资源,请使用 featureViews.patch 方法发送 PATCH 请求。

在使用任何请求数据之前,请先进行以下替换:

  • LOCATION_ID:在线存储区所在的区域,例如 us-central1
  • PROJECT_ID:您的项目 ID。
  • FEATUREONLINESTORE_NAME:包含特征视图的在线存储区的名称。
  • FEATUREVIEW_NAME:要更新的特征视图的名称。
  • FEATUREGROUP_NAME:要与特征视图关联的特征组的名称。
  • FEATURE_ID_1FEATURE_ID_2:要从 FEATUREGROUP_NAME 特征组添加到特征视图的特征 ID。

HTTP 方法和网址:

PATCH https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME

请求 JSON 正文:

{
  "feature_registry_source":
    { "feature_groups": [
      {
        "feature_group_id": "FEATUREGROUP_NAME",
        "feature_ids": [ "FEATURE_ID_1", "FEATURE_ID_2" ]
      }
    ]
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME"

PowerShell

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.UpdateFeatureViewOperationMetadata",
    "genericMetadata": {
      "createTime": "2023-09-15T04:53:22.794004Z",
      "updateTime": "2023-09-15T04:53:22.794004Z"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.FeatureView",
    "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME"
  }
}

根据 BigQuery 源更新特征视图

以下示例展示了如何通过从 BigQuery 表或视图指定特征列来更新特征视图。

REST

若要根据 BigQuery 数剧源更新 FeatureView 实例,请使用 featureViews.patch 方法发送 PATCH 请求。

在使用任何请求数据之前,请先进行以下替换:

  • LOCATION_ID:在线存储区所在的区域,例如 us-central1
  • PROJECT_ID:您的项目 ID。
  • FEATUREONLINESTORE_NAME:包含特征视图的在线存储区的名称。
  • FEATUREVIEW_NAME:要更新的特征视图的名称。
  • BIGQUERY_SOURCE_URI:包含特征数据的 BigQuery 表或视图的 URI。
  • ENTITY_ID_COLUMNS
  • ENTITY_ID_COLUMNS:包含实体 ID 的列名称。您可以指定一列或多列。
    • 如需仅指定一个实体 ID 列,请按以下格式指定列名称:
      "entity_id_column_name"
    • 如需指定多个实体 ID 列,请按以下格式指定列名称:
      ["entity_id_column_1_name", "entity_id_column_2_name", ...]

HTTP 方法和网址:

PATCH https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME

请求 JSON 正文:

{
  "big_query_source":
  {
    "uri": "BIGQUERY_SOURCE_URI",
    "entity_id_columns": "ENTITY_ID_COLUMNS"
  }
}

如需发送请求,请选择以下方式之一:

curl

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME"

PowerShell

将请求正文保存在名为 request.json 的文件中,然后执行以下命令:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME" | Select-Object -Expand Content

您应该收到类似以下内容的 JSON 响应:

{
  "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.UpdateFeatureViewOperationMetadata",
    "genericMetadata": {
      "createTime": "2023-09-15T04:53:34.832192Z",
      "updateTime": "2023-09-15T04:53:34.832192Z"
    }
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.aiplatform.v1.FeatureView",
    "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featureOnlineStores/FEATUREONLINESTORE_NAME/featureViews/FEATUREVIEW_NAME"
  }
}

后续步骤