Skip to main content
Version: Beta 🚧

FeatureReference

Summary​

A reference to a Feature Definition used in Feature Service construction.
 
By default, you can add all of the features in a Feature Definition (i.e. a Feature View or Feature Table) to a Feature Service by passing the Feature Definition into the features parameter of a Feature Service. However, if you want to specify a subset, you can use this class.
 
You can use the double-bracket notation my_feature_view[[<features>]] as a short-hand for generating a FeatureReference from a Feature Definition. This is the preferred way to select a subset of the features contained in a Feature Definition.

Example

from tecton import FeatureService
from feature_repo.features import my_feature_view_1, my_feature_view_2
my_feature_service = FeatureService(
name='my_feature_service',
features=[
# Add all features from my_feature_view_1 to this FeatureService
my_feature_view_1,
# Add a single feature from my_feature_view_2, 'my_feature'
my_feature_view_2[['my_feature']]
]
)

Attributes​

The attributes are the same as the __init__ method parameters. See below.

Methods​

NameDescription
__init__(...)Initialize FeatureReference
with_join_key_map(...)Rebind join keys for a Feature View or Feature Table used in a Feature Service.
with_name(...)Rename a Feature View or Feature Table used in a Feature Service.

__init__(...)​

Parameters

  • feature_definition (FeatureView) - The Feature View or Feature Table.

  • namespace (Optional[str]) - A namespace used to prefix the features joined from this FeatureView. By default, namespace is set to the FeatureView name. Default: None

  • features (Optional[List[str]]) - The subset of features to select from the FeatureView. If empty, all features will be included. Default: None

  • override_join_keys (Optional[Dict[str, str]]) - A map from feature view join key to spine join key override. Default: None

with_join_key_map(...)​

Rebind join keys for a Feature View or Feature Table used in a Feature Service.
 
The keys in join_key_map should be the join keys, and the values should be the feature service overrides.

Parameters

  • join_key_map (Dict[str, str]) - Dictionary remapping the join key names. Dictionary keys are join keys, values are the feature service override values.

Returns

'FeatureReference'

Example

from tecton import FeatureService
# The join key for this feature service will be "feature_service_user_id".
feature_service = FeatureService(
name="feature_service",
features=[
my_feature_view.with_join_key_map({"user_id" : "feature_service_user_id"}),
],
)
# Here is a more sophisticated example. The join keys for this feature service will be "transaction_id",
# "sender_id", and "recipient_id" and will contain three feature views named "transaction_features",
# "sender_features", and "recipient_features".
transaction_fraud_service = FeatureService(
name="transaction_fraud_service",
features=[
# Select a subset of features from a feature view.
transaction_features[["amount"]],
# Rename a feature view and/or rebind its join keys. In this example, we want user features for both the
# transaction sender and recipient, so include the feature view twice and bind it to two different feature
# service join keys.
user_features.with_name("sender_features").with_join_key_map({"user_id" : "sender_id"}),
user_features.with_name("recipient_features").with_join_key_map({"user_id" : "recipient_id"}),
],
)

with_name(...)​

Rename a Feature View or Feature Table used in a Feature Service.

Parameters

  • namespace (str) - The namespace used to prefix the features joined from this FeatureView. By default, namespace is set to the FeatureView name.

Returns

'FeatureReference'

Examples

from tecton import FeatureService
# The feature view in this feature service will be named "new_named_feature_view" in training data dataframe
# columns and other metadata.
feature_service = FeatureService(
name="feature_service",
features=[
my_feature_view.with_name("new_named_feature_view")
],
)
# Here is a more sophisticated example. The join keys for this feature service will be "transaction_id",
# "sender_id", and "recipient_id" and will contain three feature views named "transaction_features",
# "sender_features", and "recipient_features".
transaction_fraud_service = FeatureService(
name="transaction_fraud_service",
features=[
# Select a subset of features from a feature view.
transaction_features[["amount"]],
# Rename a feature view and/or rebind its join keys. In this example, we want user features for both the
# transaction sender and recipient, so include the feature view twice and bind it to two different feature
# service join keys.
user_features.with_name("sender_features").with_join_key_map({"user_id" : "sender_id"}),
user_features.with_name("recipient_features").with_join_key_map({"user_id" : "recipient_id"}),
],
)

Was this page helpful?