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 the get_historical_features() method, and online requests (e.g. for online serving) using the get_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

get_feature_dataframe

Deprecated.

get_feature_vector

Deprecated.

get_historical_features

Fetch a DataFrame of feature values from this FeatureService.

get_online_features

Returns a single Tecton FeatureVector from the Online Store.

query_features

[Advanced Feature] Queries the FeatureService with a partial set of join_keys defined in the online_serving_index of the included FeatureViews.

summary

Returns various information about this FeatureService, including the most critical metadata such as the FeatureService’s name, owner, features, etc.

wait_until_ready

Blocks until the service is ready to serve real-time requests.

get_feature_dataframe(spine, timestamp_key=None, include_feature_view_timestamp_columns=False, use_materialized_data=True, save=None, save_as=None)

Deprecated. Fetch a 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 use_materialized_data==False, feature values will instead be computed on the fly from raw data.

Parameters
  • spine (Union[DataFrame, DataFrame, None]) – A dataframe of join keys and timestamps that specify which feature values to fetch.

  • timestamp_key (Optional[str]) – Name of the time column in the spine dataframe. This column must be of type Spark timestamp.

  • include_feature_view_timestamp_columns (bool) – (Optional) Include timestamp columns for each FeatureView in the FeatureService.

  • use_materialized_data (bool) – (Optional) Use materialized data if materialization is enabled.

  • save (Optional[bool]) – (Optional) set to True to persist DataFrame as a Dataset object

  • save_as (Optional[str]) – (Optional) name to save the DataFrame as. Not applicable when save=False. If unspecified and save=True, a name will be generated.

Returns

A Tecton DataFrame.

get_feature_vector(join_keys=None, include_join_keys_in_response=False, request_context_map=None)

Deprecated. Returns a single Tecton FeatureVector from the Online Store. At least one of join_keys or request_context_map is required.

Parameters
Returns

A FeatureVector of the results.

get_historical_features(spine, timestamp_key=None, include_feature_view_timestamp_columns=False, from_source=False, save=False, save_as=None)

Fetch a 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) – (Optional) 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) – (Optional) Whether to include timestamp columns for each FeatureView in the FeatureService. Default is False.

  • from_source (bool) – (Optional) Whether feature values should be recomputed from the original data source. If False, we will read the values from the materialized Offline store.

  • save (bool) – (Optional) Whether to persistthe DataFrame as a Dataset object. Default is False.

  • save_as (str) – (Optional) Name to save the DataFrame as. If unspecified and save=True, a name will be generated.

Examples

A FeatureService fs that contains a BatchFeatureView and StreamFeatureView with join keys user_id and ad_id.

1) fs.get_historical_features(spine) where spine=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) where spine=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 name my_dataset.

3) fv.get_historical_features(spine, timestamp_key='date_1') where spine=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 the date_1 column in the spine.

A FeatureService fs_on_demand that contains only OnDemandFeatureViews and expects request time data for the key amount.

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) where spine=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 key amount.

1) fs_all.get_historical_features(spine) where spine=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 DataFrame.

get_online_features(join_keys=None, include_join_keys_in_response=False, request_data=None)

Returns a single 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 keys user_id and ad_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 key amount.

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 key user_id and expects request time data for key amount.

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 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 Tecton DataFrame of all matched records.

Parameters

join_keys (Mapping[str, Union[int, int64, str, bytes]]) – Query join keys, i.e., a union of join keys in the online_serving_index of all enclosed FeatureViews.

Returns

A Tecton DataFrame

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

The family of this Tecton Object, used to group Objects.

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.