Skip to main content
Version: 0.8

tecton.on_demand_feature_view

Summary​

Declare an On-Demand Feature View

Parameters​

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

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

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

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

  • prevent_destroy (bool) – If True, this Tecton object will be blocked from being deleted or re-created (i.e. a destructive update) during tecton plan/apply. To remove or update this object, prevent_destroy must be first set to False via the same tecton apply or a separate tecton apply. prevent_destroy can be used to prevent accidental changes such as inadvertantly deleting a Feature Service used in production or recreating a Feature View that triggers expensive rematerialization jobs. prevent_destroy also blocks changes to dependent Tecton objects that would trigger a recreate of the tagged object, e.g. if prevent_destroy is set on a Feature Service, that will also prevent deletions or re-creates of Feature Views used in that service. prevent_destroy is only enforced in live (i.e. non-dev) workspaces. (Default: False)

  • 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, FeatureView, FeatureReference]]) – 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 the transformation.

  • environments (Optional[List[str]]) – The environments in which this feature view can run. Defaults to a None, which means the feature view can run in any environment. If specified, the feature view will only run in the specified environments. Learn more about environments at Environments. (Default: None)

Returns​

An object of type tecton.OnDemandFeatureView.

Examples​

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

# 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="python",
schema=output_schema,
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,
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

Was this page helpful?

🧠 Hi! Ask me anything about Tecton!

Floating button icon