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 of the features contained in a Feature
Definition.
Attributes​
The attributes are the same as the __init__
method parameters. See below.
Methods​
Name | Description |
---|---|
__init__(...) | Initialize self. |
with_join_key_map(...) | Rebind join keys for a Feature View used in a Feature Service. |
with_name(...) | Rename a Feature View used in a Feature Service. |
__init__(...)​
Initialize self. See help(type(self)) for accurate signature.
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
)
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"]],
],
)
with_join_key_map(...)​
Rebind join keys for a Feature View used in a Feature Service.
The keys in join_key_map should be the feature view join keys, and the values should be the feature service overrides.
Parameters​
join_key_map
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(...)​
Parameters​
namespace
Rename a Feature View used in a Feature Service.
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"}),
],
)