您可以在创建特征组并将 BigQuery 表或 BigQuery 视图与其关联后创建特征。您可以为一个特征组创建多个特征,并将每个特征与 BigQuery 数据源中的特定列相关联。如需了解如何使用 BigQuery,请参阅 BigQuery 文档。
例如,如果特征组 featuregroup1
与在 fval1
和 fval2
列中包含特征值的 BigQuery 表 datasource_1
相关联,则您可以在 featuregroup1
下创建特征 feature_1
并将其与列 fval1
中的特征值相关联。同样,您可以创建另一个名为 feature_2
的特征,并将其与 fval2
列中的特征值相关联。
使用特征组和特征注册数据源具有以下优势:
您可以使用来自多个 BigQuery 数据源的特定特征列来定义用于在线传送的特征视图。
您可以通过添加
feature_timestamp
列将数据格式化为时序格式。Vertex AI Feature Store 仅传送特征数据中的最新特征值,不包括历史值。在 Data Catalog 中搜索特征资源时,您可以发现 BigQuery 源作为关联的特征数据源。
您可以设置特征监控,以检索特征统计信息并检测特征偏移。
准备工作
向 Vertex AI 进行身份验证,除非您已完成此操作。
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
Python
如需在本地开发环境中使用本页面上的 Python 示例,请安装并初始化 gcloud CLI,然后使用您的用户凭据设置应用默认凭据。
-
Install the Google Cloud CLI.
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
如需了解详情,请参阅 Set up authentication for a local development environment。 如需了解详情,请参阅身份验证文档中的为本地开发环境设置 ADC。
REST
如需在本地开发环境中使用本页面上的 REST API 示例,请使用您提供给 gcloud CLI 的凭据。
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
如需了解详情,请参阅 Google Cloud 身份验证文档中的使用 REST 时进行身份验证。
在特征组中创建特征
使用以下示例可在特征组中创建特征,并关联一个列,其中包含为特征组注册的 BigQuery 数据源中的特征值。
控制台
请按照以下说明使用 Google Cloud 控制台向现有特征组添加特征。
在 Google Cloud 控制台的“Vertex AI”部分,前往 Feature Store 页面。
在特征组部分中,点击要在其中添加特征的特征组对应的行中的
,然后点击添加特征。对于每个特征,请输入特征名称,然后点击列表中相应的 BigQuery 源列名称。如需添加更多特征,请点击添加其他特征。
点击创建。
Python 版 Vertex AI SDK
如需了解如何安装或更新 Vertex AI SDK for Python,请参阅安装 Vertex AI SDK for Python。 如需了解详情,请参阅 Python 版 Vertex AI SDK API 参考文档。
project
:您的项目 ID。location
:特征组所在的区域,例如us-central1
。existing_feature_group_id
:要在其中创建特征的现有特征组的名称。version_column_name
(可选):您要与特征关联的 BigQuery 表或视图中的列。如果未指定此参数,则默认设置为 FEATURE_NAME。feature_id
:您要创建的新特征的名称
REST
如需创建 Feature
资源,请使用 features.create 方法发送 POST
请求。
在使用任何请求数据之前,请先进行以下替换:
- LOCATION_ID:特征组所在的区域,例如
us-central1
。 - PROJECT_ID:您的项目 ID。
- FEATUREGROUP_NAME:要在其中创建特征的特征组的名称。
- FEATURE_NAME:您要创建的新特征的名称。
- VERSION_COLUMN_NAME(可选):您要与特征关联的 BigQuery 表或视图中的列。如果未指定此参数,则默认设置为 FEATURE_NAME。
HTTP 方法和网址:
POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureGroups/FEATUREGROUP_NAME/features?feature_id=FEATURE_NAME
请求 JSON 正文:
{ "version_column_name": "VERSION_COLUMN_NAME" }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
curl -X POST \
-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/featureGroups/FEATUREGROUP_NAME/features?feature_id=FEATURE_NAME"
PowerShell
将请求正文保存在名为 request.json
的文件中,然后执行以下命令:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-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/featureGroups/FEATUREGROUP_NAME/features?feature_id=FEATURE_NAME" | Select-Object -Expand Content
您应该收到类似以下内容的 JSON 响应:
{ "name": "projects/PROJECT_NUMBER/locations/LOCATION_ID/featureGroups/FEATUREGROUP_NAME/features/FEATURE_NAME/operations/OPERATION_ID", "metadata": { "@type": "type.googleapis.com/google.cloud.aiplatform.v1.UpdateFeatureOperationMetadata", "genericMetadata": { "createTime": "2023-09-18T02:36:22.870679Z", "updateTime": "2023-09-18T02:36:22.870679Z" } } }
后续步骤
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-09。