Create a feature

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.

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.

  1. In the Vertex AI section of the Google Cloud console, go to the Feature Store page.

    Go to the Feature Store page

  2. 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.

  3. 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.

  4. Click 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