Adding searchable metadata to your features
In Amazon SageMaker Feature Store, you can search through all of your features. To make your features more discoverable, you can add metadata to them. You can add the following types of metadata:
-
Description – A searchable description of the feature.
-
Parameters – Searchable key-value pairs.
The description can have up to 255 characters. For parameters, you must specify a key-value pair in your search. You can add up to 25 parameters.
To update the metadata of a feature, you can use either the console or the UpdateFeatureMetadata
operation.
How to add searchable metadata to your features
You can use the console or the Amazon SageMaker Feature Store API to add searchable metadata to your features. Instructions for using Feature Store through the console depend on whether you have enabled Amazon SageMaker Studio or Amazon SageMaker Studio Classic as your default experience.
-
Open the Studio console by following the instructions in Launch Amazon SageMaker Studio.
-
Choose Data in the left navigation pane, to expand the dropdown list.
-
From the dropdown list, choose Feature Store.
-
(Optional) To view your features, choose My account. To view shared features, choose Cross account.
-
To view your feature groups, under the Feature Catalog tab, choose My account.
-
Under the Feature Catalog tab, choose Cross account to view feature groups that others make discoverable to you. Under Created by, you can view the resource owner account ID of the feature group.
-
You can search for your feature in the Search dropdown list.
-
(Optional) To filter your search, choose the filter icon next to the Search dropdown list. You can use filters to specify parameters or date ranges in your search results. If you search for a parameter, specify both its key and value. To find your features more easily, you can specify time ranges or deselect columns that you don't want to query.
-
For shared resources, you can only edit feature group metadata or feature definitions if you have the proper access permission granted from the resource owner account. Having the discoverability permission alone doesn't allow you to edit metadata or feature definitions. For more information about granting access permissions, seeEnabling cross account access.
-
-
Choose your feature.
-
Choose Edit metadata.
-
In the Description field, add or update the description.
-
In the Parameters field under Parameters, specify a key-value pair for the parameter.
-
(Optional) Choose Add new parameter to add another parameter.
-
Choose Save changes.
-
Choose Confirm.
-
Open the Studio Classic console by following the instructions in Launch Studio Classic Using the Amazon SageMaker AI Console.
-
In the left navigation pane, choose the Home icon ( ).
-
Choose Data.
-
From the dropdown list, choose Feature Store.
-
(Optional) To view your features, choose My account. To view shared features, choose Cross account.
-
To view your feature groups, under the Feature Catalog tab, choose My account.
-
Under the Feature Catalog tab, choose Cross account to view feature groups that other accounts made discoverable to you. Under Created by, you can view the resource owner account ID of the feature group.
-
You can search for your feature in the Search dropdown list.
-
(Optional) To filter your search, choose the filter icon next to the Search dropdown list. You can use filters to specify parameters or date ranges in your search results. If you search for a parameter, specify both its key and value. To find your features more easily, you can specify time ranges or deselect columns that you don't want to query.
-
For shared resources, you can only edit feature group metadata or feature definitions if you have the proper access permission granted from the resource owner account. Having the discoverability permission alone doesn't allow you to edit metadata or feature definitions. For more information about granting access permissions, seeEnabling cross account access.
-
-
Choose your feature.
-
Choose Edit metadata.
-
In the Description field, add or update the description.
-
In the Parameters field under Parameters, specify a key-value pair for the parameter.
-
(Optional) Choose Add new parameter to add another parameter.
-
Choose Save changes.
-
Choose Confirm.
The code in this section uses the UpdateFeatureMetadata
operation in the
AWS SDK for Python (Boto3) to add searchable metadata to your features for different
scenarios. For information about the other languages to submit a query, see
See Also in the Amazon SageMaker API
Reference.
For more Feature Store examples and resources, see Amazon SageMaker Feature Store resources.
Example code
After you've updated the metadata for a feature, you can use the DescribeFeatureMetadata
operation to see the
updates that you've made.
The following code goes through an example workflow using the AWS SDK for Python (Boto3). The example code does the following:
-
Sets up your SageMaker AI environment.
-
Creates a feature group.
-
Adds features to the group.
-
Adds metadata to the features.
For more Feature Store examples and resources, see Amazon SageMaker Feature Store resources.
Step 1: Setup
To start using Feature Store, create SageMaker AI, boto3 and Feature Store sessions. Then set up the S3 bucket you want to use for your features. This is your offline store. The following code uses the SageMaker AI default bucket and adds a custom prefix to it.
Note
The role that you use must have the following managed policies
attached to it: AmazonS3FullAccess
and
AmazonSageMakerFeatureStoreAccess
.
# SageMaker Python SDK version 2.x is required %pip install 'sagemaker>=2.0.0' import sagemaker import sys
import boto3 import pandas as pd import numpy as np import io from sagemaker.session import Session from sagemaker import get_execution_role from botocore.exceptions import ClientError prefix = 'sagemaker-featurestore-introduction' role = get_execution_role() sagemaker_session = sagemaker.Session() region = sagemaker_session.boto_region_name s3_bucket_name = sagemaker_session.default_bucket() sagemaker_client = boto_session.client(service_name='sagemaker', region_name=region)
Step 2: Create a feature group and add features
The following code is an example of creating a feature group with feature definitions.
feature_group_name = "test-for-feature-metadata" feature_definitions = [ {"FeatureName": "feature-1", "FeatureType": "String"}, {"FeatureName": "feature-2", "FeatureType": "String"}, {"FeatureName": "feature-3", "FeatureType": "String"}, {"FeatureName": "feature-4", "FeatureType": "String"}, {"FeatureName": "feature-5", "FeatureType": "String"} ] try: sagemaker_client.create_feature_group( FeatureGroupName=feature_group_name, RecordIdentifierFeatureName="feature-1", EventTimeFeatureName="feature-2", FeatureDefinitions=feature_definitions, OnlineStoreConfig={"EnableOnlineStore": True} ) except ClientError as e: if e.response["Error"]["Code"] == "ResourceInUse": pass else: raise e
Step 3: Add metadata
Before you add metadata, use the DescribeFeatureGroup
operation to make
sure that the status of the feature group is
Created
.
sagemaker_client.describe_feature_group( FeatureGroupName=feature_group_name )
Add a description to the feature.
sagemaker_client.update_feature_metadata( FeatureGroupName=feature_group_name, FeatureName="feature-1", Description="new description" )
You can use the DescribeFeatureMetadata
operation to see
if you successfully updated the description for the feature
group.
sagemaker_client.describe_feature_metadata( FeatureGroupName=feature_group_name, FeatureName="feature-1" )
You can also use it to add parameters to the feature group.
sagemaker_client.update_feature_metadata( FeatureGroupName=feature_group_name, FeatureName="feature-1", ParameterAdditions=[ {"Key": "team", "Value": "featurestore"}, {"Key": "org", "Value": "sagemaker"}, ] )
You can use the DescribeFeatureMetadata
operation again to
see if you have successfully added the parameters.
sagemaker_client.describe_feature_metadata( FeatureGroupName=feature_group_name, FeatureName="feature-1" )