You can create a feature after you create a feature group and associate a BigQuery table or BigQuery view with it. You can create multiple features for a feature group and associate each feature with a specific column in the BigQuery data source. For information about how to use BigQuery, refer to the BigQuery documentation.
For example, if the feature group featuregroup1
is associated with the
BigQuery table datasource_1
containing feature values in columns
fval1
and fval2
, then you can create feature feature_1
under
featuregroup1
and associate it with the feature values in column fval1
.
Similarly, you can create another feature named feature_2
and associate it
with the feature values in column fval2
.
Registering your data source using feature groups and features has the following advantages:
You can define a feature view for online serving by using specific feature columns from multiple BigQuery data sources.
You can format your data as a time series by including the
feature_timestamp
column. Vertex AI Feature Store serves only the latest feature values from the feature data and excludes historical values.You can discover the BigQuery source as the associated feature data source, when you search for the feature resource in Data Catalog.
Before you begin
Authenticate to Vertex AI, unless you've done so already.
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
To use the Python samples on this page in a local development environment, install and initialize the gcloud CLI, and then set up Application Default Credentials with your user credentials.
- Install the Google Cloud CLI.
-
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.
For more information, see Set up authentication for a local development environment.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
Install the Google Cloud CLI, then initialize it by running the following command:
gcloud init
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
Create a feature within a feature group
Use the following samples to create a feature within a feature group and associate a column containing feature values from the BigQuery data source registered for the feature group.
Console
Use the following instructions to add features to an existing feature group using the Google Cloud console.
In the Vertex AI section of the Google Cloud console, go to the Feature Store page.
In the Feature groups section, click
in the row corresponding to the feature group where you want to add a feature, and then click Add features.For each feature, enter a Feature name and click the corresponding BigQuery source column name in the list. To add more features, click Add another feature.
Click Create.
Python
To learn how to install or update the Vertex AI SDK for Python, see Install the Vertex AI SDK for Python. For more information, see the Python API reference documentation.
project
: Your project ID.location
: Region where the feature group is located, such asus-central1
.existing_feature_group_id
: The name of the existing feature group where you want to create the feature.version_column_name
: Optional: The column from the BigQuery table or view that you want to associate with the feature. If you don't specify this parameter, it's set to FEATURE_NAME, by default.feature_id
: The name of the new feature you want to create
REST
To create a Feature
resource, send a POST
request by using the
features.create
method.
Before using any of the request data, make the following replacements:
- LOCATION_ID: Region where the feature group is located, such as
us-central1
. - PROJECT_ID: Your project ID.
- FEATUREGROUP_NAME: The name of the feature group where you want to create the feature.
- FEATURE_NAME: The name of the new feature you want to create.
- VERSION_COLUMN_NAME: Optional: The column from the BigQuery table or view that you want to associate with the feature. If you don't specify this parameter, it's set to FEATURE_NAME, by default.
HTTP method and URL:
POST https://LOCATION_ID-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION_ID/featureGroups/FEATUREGROUP_NAME/features?feature_id=FEATURE_NAME
Request JSON body:
{ "version_column_name": "VERSION_COLUMN_NAME" }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
,
and execute the following command:
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
Save the request body in a file named request.json
,
and execute the following command:
$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
You should receive a JSON response similar to the following:
{ "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" } } }
What's next
Learn how to list all features in a feature group.
Learn how to update a feature.
Learn how to delete a feature.
Learn how to update a feature group.
Online serving types in Vertex AI Feature Store.