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
tecton.DataFrame
of feature values from this FeatureService.Returns a single Tecton
tecton.FeatureVector
from the Online Store.[Advanced Feature] Queries the FeatureService with a partial set of join_keys defined in the
online_serving_index
of 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
tecton.DataFrame
of 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, tecton.DataFrame]) – 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
fs
that contains a BatchFeatureView and StreamFeatureView with join keysuser_id
andad_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_1
column in the spine.A FeatureService
fs_on_demand
that 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_all
that 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
tecton.DataFrame
.
-
get_online_features
(join_keys=None, include_join_keys_in_response=False, request_data=None)¶ Returns a single Tecton
tecton.FeatureVector
from 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
fs
that contains a BatchFeatureView and StreamFeatureView with join keysuser_id
andad_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_demand
that 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.get_online_features(request_data={'amount': 30})
Fetch the latest features from the online store with amount = 30.A FeatureService
fs_all
that contains feature views of all types with join keyuser_id
and expects request time data for keyamount
.1)
fs.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.FeatureVector
of the results.
-
query_features
(join_keys)¶ [Advanced Feature] Queries the FeatureService with a partial set of join_keys defined in the
online_serving_index
of the included FeatureViews. Returns a Tectontecton.DataFrame
of 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_at
Returns the creation date of this Tecton Object.
defined_in
Returns filename where this Tecton Object has been declared.
description
The description of this Tecton Object, set by user.
family
Deprecated.
feature_views
Returns the Feature Views enclosed in this FeatureService.
features
Returns the features generated by the enclosed feature views.
id
Legacy attribute.
logging
Returns the logging configuration of this FeatureService.
name
The name of this Tecton Object.
owner
The owner of this Tecton Object (typically the email of the primary maintainer.)
tags
Tags associated with this Tecton Object (key-value pairs of arbitrary metadata set by user.)
workspace
Returns the workspace this Tecton Object was created in.
-