tecton.interactive.FeatureService¶
-
class
tecton.interactive.FeatureService¶ FeatureService class.
FeatureServices are used to serve feature values from
FeatureView. Users can use FeatureServices to make offline requests (e.g. to fetch a training dataset) using theget_historical_features()method, and online requests (e.g. for online serving) using theget_online_features()method. A FeatureService consists of a set of FeatureViews, plus configuration options.To get a FeatureService instance, call
tecton.get_feature_service().Methods
Fetch a
TectonDataFrameof feature values from this FeatureService.Returns a single Tecton
tecton.FeatureVectorfrom the Online Store.[Advanced Feature] Queries the FeatureService with a partial set of join_keys defined in the
online_serving_indexof the included FeatureViews.Returns various information about this FeatureService, including the most critical metadata such as the FeatureService’s name, owner, features, etc.
Blocks until the service is ready to serve real-time requests.
-
get_historical_features(spine, timestamp_key=None, include_feature_view_timestamp_columns=False, from_source=False, save=False, save_as=None)¶ Fetch a
TectonDataFrameof feature values from this FeatureService.This method will return feature values for each row provided in the spine DataFrame. The feature values returned by this method will respect the timestamp provided in the timestamp column of the spine DataFrame.
This method fetches features from the Offline Store. If
from_source=True, feature values will instead be computed on the fly from raw data.- Parameters
spine (Union[pyspark.sql.DataFrame, pandas.DataFrame, TectonDataFrame]) – A dataframe of possible join keys, request data keys, and timestamps that specify which feature values to fetch.To distinguish between spine columns and feature columns, feature columns are labeled as feature_view_name__feature_name in the returned DataFrame.
timestamp_key (str) – Name of the time column in the spine DataFrame. This method will fetch the latest features computed before the specified timestamps in this column. Not applicable if the FeatureService stricly contains OnDemandFeatureViews with no feature view dependencies.
include_feature_view_timestamp_columns (bool) – Whether to include timestamp columns for each FeatureView in the FeatureService. Default is False.
from_source (bool) – Whether feature values should be recomputed from the original data source. If False, we will read the values from the materialized Offline store. Defaults to False.
save (bool) – Whether to persist the DataFrame as a Dataset object. Default is False. This parameter is not supported in Tecton on Snowflake.
save_as (str) – Name to save the DataFrame as. If unspecified and save=True, a name will be generated. This parameter is not supported in Tecton on Snowflake.
Examples
A FeatureService
fsthat contains a BatchFeatureView and StreamFeatureView with join keysuser_idandad_id.1)
fs.get_historical_features(spine)wherespine=pandas.Dataframe({'user_id': [1,2,3], 'ad_id': ['a234', 'b256', 'c9102'], 'date': [datetime(...), datetime(...), datetime(...)]})Fetch historical features from the offline store for users 1, 2, and 3 for the specified timestamps and ad ids in the spine.2)
fs.get_historical_features(spine, save_as='my_dataset)wherespine=pandas.Dataframe({'user_id': [1,2,3], 'ad_id': ['a234', 'b256', 'c9102'], 'date': [datetime(...), datetime(...), datetime(...)]})Fetch historical features from the offline store for users 1, 2, and 3 for the specified timestamps and ad ids in the spine. Save the DataFrame as dataset with the namemy_dataset.3)
fv.get_historical_features(spine, timestamp_key='date_1')wherespine=pandas.Dataframe({'user_id': [1,2,3], 'ad_id': ['a234', 'b256', 'c9102'], 'date_1': [datetime(...), ...], 'date_2': [datetime(...), ...]})Fetch historical features from the offline store for users 1, 2, and 3 for the ad ids and specified timestamps in thedate_1column in the spine.A FeatureService
fs_on_demandthat contains only OnDemandFeatureViews and expects request time data for the keyamount.The request time data is defined in the feature definition as such:request_schema = StructType()request_schema.add(StructField(‘amount’, DoubleType()))transaction_request = RequestDataSource(request_schema=request_schema)1)
fs_on_demand.get_historical_features(spine)wherespine=pandas.Dataframe({'amount': [30, 50, 10000]})Fetch historical features from the offline store with request data inputs 30, 50, and 10000.A FeatureService
fs_allthat contains feature views of all types with join key ‘user_id’ and expects request time data for the keyamount.1)
fs_all.get_historical_features(spine)wherespine=pandas.Dataframe({'user_id': [1,2,3], 'amount': [30, 50, 10000], 'date': [datetime(...), datetime(...), datetime(...)]})Fetch historical features from the offline store for users 1, 2, and 3 for the specified timestamps and request data inputs in the spine.- Returns
A Tecton
TectonDataFrame.
-
get_online_features(join_keys=None, include_join_keys_in_response=False, request_data=None)¶ Returns a single Tecton
tecton.FeatureVectorfrom the Online Store. At least one of join_keys or request_data is required.- Parameters
join_keys (
Optional[Mapping[str,Union[int,int64,str,bytes]]]) – Join keys of the enclosed FeatureViews.include_join_keys_in_response (
bool) – Whether to include join keys as part of the response FeatureVector.request_data (
Optional[Mapping[str,Union[int,int64,str,bytes,float]]]) – Dictionary of request context values. Only applicable when the FeatureService contains OnDemandFeatureViews.
Examples
A FeatureService
fsthat contains a BatchFeatureView and StreamFeatureView with join keysuser_idandad_id.1)
fs.get_online_features(join_keys={'user_id': 1, 'ad_id': 'c234'})Fetch the latest features from the online store for user 1 and ad ‘c234’.2)
fv.get_online_features(join_keys={'user_id': 1, 'ad_id': 'c234'}, include_join_keys_in_respone=True)Fetch the latest features from the online store for user 1 and ad id ‘c234’. Include the join key information (user_id=1, ad_id=’c234’) in the returned FeatureVector.A FeatureService
fs_on_demandthat contains only OnDemandFeatureViews and expects request time data for keyamount.The request time data is defined in the feature definition as such:request_schema = StructType()request_schema.add(StructField(‘amount’, DoubleType()))transaction_request = RequestDataSource(request_schema=request_schema)1)
fs_on_demand.get_online_features(request_data={'amount': 30})Fetch the latest features from the online store with amount = 30.A FeatureService
fs_allthat contains feature views of all types with join keyuser_idand expects request time data for keyamount.1)
fs_all.get_online_features(join_keys={'user_id': 1}, request_data={'amount': 30})Fetch the latest features from the online store for user 1 with amount = 30.- Returns
A
tecton.FeatureVectorof the results.
-
query_features(join_keys)¶ [Advanced Feature] Queries the FeatureService with a partial set of join_keys defined in the
online_serving_indexof the included FeatureViews. Returns a TectonTectonDataFrameof all matched records.
-
summary()¶ Returns various information about this FeatureService, including the most critical metadata such as the FeatureService’s name, owner, features, etc.
-
wait_until_ready(timeout='15m', wait_for_materialization=True, verbose=False)¶ Blocks until the service is ready to serve real-time requests.
The FeatureService is considered ready once every FeatureView that has been added to it has had at least once successful materialization run.
- Parameters
timeout – Timeout string.
wait_for_materialization – If False, does not wait for batch materialization to complete.
Attributes
created_atReturns the creation date of this Tecton Object.
defined_inReturns filename where this Tecton Object has been declared.
descriptionThe description of this Tecton Object, set by user.
familyDeprecated.
feature_viewsReturns the Feature Views enclosed in this FeatureService.
featuresReturns the features generated by the enclosed feature views.
idLegacy attribute.
loggingReturns the logging configuration of this FeatureService.
nameThe name of this Tecton Object.
ownerThe owner of this Tecton Object (typically the email of the primary maintainer.)
tagsTags associated with this Tecton Object (key-value pairs of arbitrary metadata set by user.)
workspaceReturns the workspace this Tecton Object was created in.
-