tecton.declarative.on_demand_feature_view

tecton.declarative.on_demand_feature_view(*, mode, sources, schema, description=None, owner=None, tags=None, name=None)

Declare an On-Demand Feature View

Parameters
  • mode (str) – Whether the annotated function is a pipeline function (“pipeline” mode) or a transformation function (“python” or “pandas” mode). For the non-pipeline mode, an inferred transformation will also be registered.

  • sources (List[Union[RequestSource, FeatureDefinition, FeaturesConfig]]) – The data source inputs to the feature view. An input can be a RequestSource or a materialized Feature View.

  • schema (List[Field]) – Tecton schema matching the expected output (of either a dictionary or a Pandas DataFrame).

  • description (Optional[str]) – A human readable description.

  • owner (Optional[str]) – Owner name (typically the email of the primary maintainer).

  • tags (Optional[Dict[str, str]]) – Tags associated with this Tecton Object (key-value pairs of arbitrary metadata).

  • name (Optional[str]) – Unique, human friendly name that identifies the FeatureView. Defaults to the function name.

Returns

An object of type tecton.feature_views.OnDemandFeatureView.

An example declaration of an on-demand feature view using Python mode. With Python mode, the function sources will be dictionaries, and the function is expected to return a dictionary matching the schema from output_schema. Tecton recommends using Python mode for improved online serving performance.

from tecton import RequestSource, on_demand_feature_view
from tecton.types import Field, Float64, Int64
import pandas

# Define the request schema
transaction_request = RequestSource(schema=[Field("amount", Float64)])

# Define the output schema
output_schema = [Field("transaction_amount_is_high", Int64)]

# This On-Demand Feature View evaluates a transaction amount and declares it as "high", if it's higher than 10,000
@on_demand_feature_view(
    sources=[transaction_request],
    mode='pandas',
    schema=output_schema,
    owner='matt@tecton.ai',
    tags={'release': 'production', 'prevent-destroy': 'true', 'prevent-recreate': 'true'},
    description='Whether the transaction amount is considered high (over $10000)'
)

def transaction_amount_is_high(transaction_request):
    result = {}
    result['transaction_amount_is_high'] = int(transaction_request['amount'] >= 10000)
    return result

An example declaration of an on-demand feature view using Pandas mode. With Pandas mode, the function sources will be Pandas Dataframes, and the function is expected to return a Dataframe matching the schema from output_schema.

from tecton import RequestSource, on_demand_feature_view
from tecton.types import Field, Float64, Int64
import pandas

# Define the request schema
transaction_request = RequestSource(schema=[Field("amount", Float64)])

# Define the output schema
output_schema = [Field("transaction_amount_is_high", Int64)]

# This On-Demand Feature View evaluates a transaction amount and declares it as "high", if it's higher than 10,000
@on_demand_feature_view(
    sources=[transaction_request],
    mode='pandas',
    schema=output_schema,
    owner='matt@tecton.ai',
    tags={'release': 'production', 'prevent-destroy': 'true', 'prevent-recreate': 'true'},
    description='Whether the transaction amount is considered high (over $10000)'
)
def transaction_amount_is_high(transaction_request):
    import pandas as pd

    df = pd.DataFrame()
    df['transaction_amount_is_high'] = (transaction_request['amount'] >= 10000).astype('int64')
    return df