Prompt
Private Preview
Tecton managed Prompts are in Private Preview.
Summary​
A Tecton Prompt.Â
The Prompt should not be instantiated directly and the
tecton.prompt
decorator is recommended instead.
Example​
@prompt(
sources=[offer_email_request, last_product_viewed, last_order_metrics, weekly_spend],
description="Contextual prompt for offer generation email",
)
def offer_email_prompt(offer_email_request, last_product_viewed, last_order_metrics, weekly_spend):
offer_email_prompt_template = """\
Generate a personalized offer email for user {name} given the following information about them:
last product viewed: {last_product_viewed}
total spend over last 7 days: {last_week_spend}
time since last order: {time_since_last_order}
"""
return offer_email_prompt_template.format(
name=offer_email_request["user_name"],
last_product_viewed=last_product_viewed["product_name_last_7d_10m"],
last_week_spend=weekly_spend["amt_sum_7d_1d"],
time_since_last_order=last_order_metrics["time_since_last_order"],
)
@prompt (Decorator)​
Declare a PromptParameters
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 set to False via the same tecton apply or a separate tecton apply.prevent_destroy
can be used to prevent accidental changes such as inadvertently deleting a Feature Service used in production or recreating a Feature View that triggers expensive re-materialization jobs.prevent_destroy
also blocks changes to dependent Tecton objects that would trigger a recreation of the tagged object, e.g. ifprevent_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
sources
(Optional
[List
[Union
[configs.RequestSource
,FeatureView
,'FeatureReference'
]]]) - The data source inputs to the feature view. An input can be a RequestSource, a BatchFeatureView, or a StreamFeatureView Default:None
environment
(Optional
[str
]) - The environment in which this feature view can run. Defaults toNone
, which means the feature view can run in any environment. If specified, the feature view will only run in the specified environment. Learn more about environments at On Demand Feature View Environments Default:None
context_parameter_name
(Optional
[str
]) - Name of the function parameter that Tecton injects Realtime Context to. This context is a RealtimeContext object for Python mode FVs and a pandas.DataFrame object for Pandas mode FVs. Default:None
Returns
An object of typePrompt
.
Prompt (Class)​
Attributes​
Name | Data Type | Description |
---|---|---|
context_parameter_name | Optional[str] | Name of the function parameter that Tecton injects Realtime Context to. |
created_at | Optional[datetime.datetime] | Returns the time that this Tecton object was created or last updated. None for locally defined objects. |
defined_in | Optional[str] | The repo filename where this object was declared. None for locally defined objects. |
description | Optional[str] | Returns the description of the Tecton object. |
environment | Optional[str] | The environment in which this feature view runs. |
feature_metadata | List[FeatureMetadata] | Metadata of the Features generated by this Feature View. Includes data type, descriptions, and tags. |
id | str | Returns the unique id of the Tecton object. |
info | ||
join_keys | List[str] | The join key column names. |
name | str | Returns the name of the Tecton object. |
online_serving_index | List[str] | The set of join keys that will be indexed and queryable during online serving. Â defaults to the complete set of join keys. |
owner | Optional[str] | Returns the owner of the Tecton object. |
prevent_destroy | bool | If set to True, Tecton will block destructive actions taken on this Feature View or Feature Table. |
sources | ||
tags | Dict[str, str] | Returns the tags of the Tecton object. |
transformations | ||
url | str | Returns a link to the Tecton Web UI. |
wildcard_join_key | Optional[set] | Returns a wildcard join key column name if it exists; Otherwise returns None. |
workspace | Optional[str] | Returns the workspace that this Tecton object belongs to. None for locally defined objects. |
Methods​
Name | Description |
---|---|
get_online_prompt(...) | Returns a Prompt that's generated using an Online Transformation for the given request data and the |
get_prompts_for_events(...) | Returns a Tecton TectonDataFrame of the prompts that would be generated for each set of events, plus |
print_transformation_schema() | Prints the schema of the output of the transformation. |
run_prompt(...) | Get the prompt using mock inputs. |
summary() | Displays a human-readable summary. |
transformation_schema() | Returns the schema of the output of the transformation. |
with_join_key_map(...) | Rebind join keys for a Feature View or Feature Table used in a Feature Service. |
with_name(...) | Rename a Feature View or Feature Table used in a Feature Service. |
get_online_prompt(...)​
Returns a Prompt that's generated using an Online Transformation for the given request data and the latest feature values from the Online Store for the given join keys (if using dependent Feature Views).Parameters
join_keys
(Optional
[Mapping
[str
,Union
[int
,numpy.int_
,str
,bytes
]]]) - Join keys of any dependent Feature Views of the Prompt. Default:None
include_join_keys_in_response
(bool
) - Whether to include join keys as part of the response FeatureVector. Default:false
request_data
(Optional
[Mapping
[str
,Union
[int
,numpy.int_
,str
,bytes
,float
]]]) - Dictionary of Request-Time key-values that provide the data for the RequestSource of the Prompt. Default:None
Returns
FeatureVector
: A tecton.FeatureVector
of the results.
get_prompts_for_events(...)​
Returns a TectonTectonDataFrame
of the prompts that would be generated for each set of events, plus
the events that generated each prompts.Parameters
events
(Union
[pyspark_dataframe.DataFrame
,pandas.DataFrame
,TectonDataFrame
,str
]) - A dataframe of input feature values, request data keys, and timestamps that determine the prompt. The returned data frame will contain rollups for all (feature values, request data key) combinations that are required to compute a full frame from theevents
dataframe.timestamp_key
(Optional
[str
]) - Name of the timestamp column. This method will fetch the latest features computed before the specified timestamps in this column. If there is only 1 column of type timestamp in the input events, it will be thetimestamp_key
by default. Default:None
from_source
(Optional
[bool
]) - Whether feature values should be recomputed from the original data source. IfNone
, input feature values will be fetched from the Offline Store for Feature Views that have offline materialization enabled and otherwise computes feature values on the fly from raw data. Usefrom_source=True
to force computing from raw data andfrom_source=False
to error if any input Feature Views are not materialized. Defaults to None. Default:None
compute_mode
(Optional
[Union
[ComputeMode
,str
]]) - Compute mode to use to produce the data frame, one of "rift" or "spark" Default:None
Returns
TectonDataFrame
: A Tecton TectonDataFrame
.
print_transformation_schema(...)​
Prints the schema of the output of the transformation.Returns
None
run_prompt(...)​
Get the prompt using mock inputs.Parameters
input_data
(Optional
[Dict
[str
,Any
]]) - Required. Dict with the same expected keys as the Prompt's inputs parameters. Each value must be a Dictionary representing a single row. Default:None
Returns
str
: The resulting prompt as a string.
summary()​
Displays a human-readable summary.transformation_schema(...)​
Returns the schema of the output of the transformation.Returns
List
[types.Field
]
with_join_key_map(...)​
Rebind join keys for a Feature View or Feature Table used in a Feature Service.Â
The keys in join_key_map should be the join keys, and the values should be the feature service overrides.
Parameters
join_key_map
(Dict
[str
,str
]) - Dictionary remapping the join key names. Dictionary keys are join keys, values are the feature service override values.
Returns
FeatureReference
Example
from tecton import FeatureService# The join key for this feature service will be "feature_service_user_id".feature_service = FeatureService(name="feature_service",features=[my_feature_view.with_join_key_map({"user_id" : "feature_service_user_id"}),],)# Here is a more sophisticated example. The join keys for this feature service will be "transaction_id",# "sender_id", and "recipient_id" and will contain three feature views named "transaction_features",# "sender_features", and "recipient_features".transaction_fraud_service = FeatureService(name="transaction_fraud_service",features=[# Select a subset of features from a feature view.transaction_features[["amount"]],# Rename a feature view and/or rebind its join keys. In this example, we want user features for both the# transaction sender and recipient, so include the feature view twice and bind it to two different feature# service join keys.user_features.with_name("sender_features").with_join_key_map({"user_id" : "sender_id"}),user_features.with_name("recipient_features").with_join_key_map({"user_id" : "recipient_id"}),],)
with_name(...)​
Rename a Feature View or Feature Table used in a Feature Service.Parameters
namespace
(str
) - The namespace used to prefix the features joined from this FeatureView. By default, namespace is set to the FeatureView name.
Returns
FeatureReference
Examples
from tecton import FeatureService# The feature view in this feature service will be named "new_named_feature_view" in training data dataframe# columns and other metadata.feature_service = FeatureService(name="feature_service",features=[my_feature_view.with_name("new_named_feature_view")],)
# Here is a more sophisticated example. The join keys for this feature service will be "transaction_id",# "sender_id", and "recipient_id" and will contain three feature views named "transaction_features",# "sender_features", and "recipient_features".transaction_fraud_service = FeatureService(name="transaction_fraud_service",features=[# Select a subset of features from a feature view.transaction_features[["amount"]],# Rename a feature view and/or rebind its join keys. In this example, we want user features for both the# transaction sender and recipient, so include the feature view twice and bind it to two different feature# service join keys.user_features.with_name("sender_features").with_join_key_map({"user_id" : "sender_id"}),user_features.with_name("recipient_features").with_join_key_map({"user_id" : "recipient_id"}),],)