vebench / feast_sample.jsonl
lexuanbach's picture
Upload feast_sample.jsonl with huggingface_hub
7638c52 verified
Raw
History Blame Contribute Delete
71.7 kB
{"template": "aws", "path": "sdk/python/feast/templates/aws/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n PushSource,\n RedshiftSource,\n RequestSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Defines a data source from which feature values can be retrieved. Sources are queried when building training\n# datasets or materializing features into an online store.\ndriver_stats_source = RedshiftSource(\n # The Redshift table where features can be found\n table=\"feast_driver_hourly_stats\",\n # The event timestamp is used for point-in-time joins and for ensuring only\n # features within the TTL are returned\n timestamp_field=\"event_timestamp\",\n # The (optional) created timestamp is used to ensure there are no duplicate\n # feature rows in the offline store or when building training datasets\n created_timestamp_column=\"created\",\n # Database to redshift source.\n database=\"%REDSHIFT_DATABASE%\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "cassandra", "path": "sdk/python/feast/templates/cassandra/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n FileSource,\n PushSource,\n RequestSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Read data from parquet files. Parquet is convenient for local development mode. For\n# production, you can use your favorite DWH, such as BigQuery. See Feast documentation\n# for more info.\ndriver_stats_source = FileSource(\n name=\"driver_hourly_stats_source\",\n path=\"%PARQUET_PATH%\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "couchbase", "path": "sdk/python/feast/templates/couchbase/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import Entity, FeatureService, FeatureView, Field, PushSource, RequestSource\nfrom feast.infra.offline_stores.contrib.couchbase_offline_store.couchbase_source import (\n CouchbaseColumnarSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\ndriver_stats_source = CouchbaseColumnarSource(\n name=\"driver_hourly_stats_source\",\n query=\"SELECT * FROM Default.Default.`feast_driver_hourly_stats`\",\n database=\"Default\",\n scope=\"Default\",\n collection=\"feast_driver_hourly_stats\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "gcp", "path": "sdk/python/feast/templates/gcp/feature_repo/feature_definitions.py", "src": "from datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n BigQuerySource,\n Entity,\n FeatureService,\n FeatureView,\n Field,\n PushSource,\n RequestSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Defines a data source from which feature values can be retrieved. Sources are queried when building training\n# datasets or materializing features into an online store.\ndriver_stats_source = BigQuerySource(\n name=\"driver_hourly_stats_source\",\n # The BigQuery table where features can be found\n table=\"feast-oss.demo_data.driver_hourly_stats_2\",\n # The event timestamp is used for point-in-time joins and for ensuring only\n # features within the TTL are returned\n timestamp_field=\"event_timestamp\",\n # The (optional) created timestamp is used to ensure there are no duplicate\n # feature rows in the offline store or when building training datasets\n created_timestamp_column=\"created\",\n)\n\n# Feature views are a grouping based on how features are stored in either the\n# online or offline store.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n # The list of entities specifies the keys required for joining or looking\n # up features from this feature view. The reference provided in this field\n # correspond to the name of a defined entity (or entities)\n entities=[driver],\n # The timedelta is the maximum age that each feature value may have\n # relative to its lookup time. For historical features (used in training),\n # TTL is relative to each timestamp provided in the entity dataframe.\n # TTL also allows for eviction of keys from online stores and limits the\n # amount of historical scanning required for historical feature values\n # during retrieval\n ttl=timedelta(weeks=52 * 10), # Set to be very long for example purposes only\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(weeks=52 * 10), # Set to be very long for example purposes only\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "hazelcast", "path": "sdk/python/feast/templates/hazelcast/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n FileSource,\n PushSource,\n RequestSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Read data from parquet files. Parquet is convenient for local development mode. For\n# production, you can use your favorite DWH, such as BigQuery. See Feast documentation\n# for more info.\ndriver_stats_source = FileSource(\n name=\"driver_hourly_stats_source\",\n path=\"%PARQUET_PATH%\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "hbase", "path": "sdk/python/feast/templates/hbase/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n FileSource,\n PushSource,\n RequestSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Read data from parquet files. Parquet is convenient for local development mode. For\n# production, you can use your favorite DWH, such as BigQuery. See Feast documentation\n# for more info.\ndriver_stats_source = FileSource(\n name=\"driver_hourly_stats_source\",\n path=\"%PARQUET_PATH%\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "local", "path": "sdk/python/feast/templates/local/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n FileSource,\n Project,\n PushSource,\n RequestSource,\n)\nfrom feast.feature_logging import LoggingConfig\nfrom feast.infra.offline_stores.file_source import FileLoggingDestination\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64, Json, Map, String, Struct\n\n# Define a project for the feature repo\nproject = Project(name=\"%PROJECT_NAME%\", description=\"A project for driver statistics\")\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Read data from parquet files. Parquet is convenient for local development mode. For\n# production, you can use your favorite DWH, such as BigQuery. See Feast documentation\n# for more info.\ndriver_stats_source = FileSource(\n name=\"driver_hourly_stats_source\",\n path=\"%PARQUET_PATH%\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64, description=\"Average daily trips\"),\n Field(\n name=\"driver_metadata\",\n dtype=Map,\n description=\"Driver metadata as key-value pairs\",\n ),\n Field(\n name=\"driver_config\", dtype=Json, description=\"Driver configuration as JSON\"\n ),\n Field(\n name=\"driver_profile\",\n dtype=Struct({\"name\": String, \"age\": String}),\n description=\"Driver profile as a typed struct\",\n ),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n enable_validation=True,\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n logging_config=LoggingConfig(\n destination=FileLoggingDestination(path=\"%LOGGING_PATH%\")\n ),\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n Field(name=\"driver_metadata\", dtype=Map),\n Field(name=\"driver_config\", dtype=Json),\n Field(name=\"driver_profile\", dtype=Struct({\"name\": String, \"age\": String})),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "milvus", "path": "sdk/python/feast/templates/milvus/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n FileSource,\n Project,\n PushSource,\n RequestSource,\n)\nfrom feast.feature_logging import LoggingConfig\nfrom feast.infra.offline_stores.file_source import FileLoggingDestination\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define a project for the feature repo\nproject = Project(name=\"%PROJECT_NAME%\", description=\"A project for driver statistics\")\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\n# Read data from parquet files. Parquet is convenient for local development mode. For\n# production, you can use your favorite DWH, such as BigQuery. See Feast documentation\n# for more info.\ndriver_stats_source = FileSource(\n name=\"driver_hourly_stats_source\",\n path=\"%PARQUET_PATH%\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64, description=\"Average daily trips\"),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n logging_config=LoggingConfig(\n destination=FileLoggingDestination(path=\"%LOGGING_PATH%\")\n ),\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "postgres", "path": "sdk/python/feast/templates/postgres/feature_repo/feature_definitions.py", "src": "# This is an example feature definition file\n\nfrom datetime import timedelta\n\nimport pandas as pd\n\nfrom feast import Entity, FeatureService, FeatureView, Field, PushSource, RequestSource\nfrom feast.infra.offline_stores.contrib.postgres_offline_store.postgres_source import (\n PostgreSQLSource,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Define an entity for the driver. You can think of an entity as a primary key used to\n# fetch features.\ndriver = Entity(name=\"driver\", join_keys=[\"driver_id\"])\n\ndriver_stats_source = PostgreSQLSource(\n name=\"driver_hourly_stats_source\",\n query=\"SELECT * FROM feast_driver_hourly_stats\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Our parquet files contain sample data that includes a driver_id column, timestamps and\n# three feature column. Here we define a Feature View that will allow us to serve this\n# data to our model online.\ndriver_stats_fv = FeatureView(\n # The unique name of this feature view. Two feature views in a single\n # project cannot have the same name\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=1),\n # The list of features defined below act as a schema to both define features\n # for both materialization of features into a store, and are used as references\n # during retrieval for building a training dataset or serving features\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_source,\n # Tags are user defined key/value pairs that are attached to each\n # feature view\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n# Define a request data source which encodes features / information only\n# available at request time (e.g. part of the user initiated HTTP request)\ninput_request = RequestSource(\n name=\"vals_to_add\",\n schema=[\n Field(name=\"val_to_add\", dtype=Int64),\n Field(name=\"val_to_add_2\", dtype=Int64),\n ],\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fv, input_request],\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\n# This groups features into a model version\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_stats_fv[[\"conv_rate\"]], # Sub-selects a feature from a feature view\n transformed_conv_rate, # Selects all features from the feature view\n ],\n)\ndriver_activity_v2 = FeatureService(\n name=\"driver_activity_v2\", features=[driver_stats_fv, transformed_conv_rate]\n)\n\n# Defines a way to push data (to be available offline, online or both) into Feast.\ndriver_stats_push_source = PushSource(\n name=\"driver_stats_push_source\",\n batch_source=driver_stats_source,\n)\n\n# Defines a slightly modified version of the feature view from above, where the source\n# has been changed to the push source. This allows fresh features to be directly pushed\n# to the online store for this feature view.\ndriver_stats_fresh_fv = FeatureView(\n name=\"driver_hourly_stats_fresh\",\n entities=[driver],\n ttl=timedelta(days=1),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_stats_push_source, # Changed from above\n tags={\"team\": \"driver_performance\"},\n version=\"latest\",\n)\n\n\n# Define an on demand feature view which can generate new features based on\n# existing feature views and RequestSource features\n@on_demand_feature_view(\n sources=[driver_stats_fresh_fv, input_request], # relies on fresh version of FV\n schema=[\n Field(name=\"conv_rate_plus_val1\", dtype=Float64),\n Field(name=\"conv_rate_plus_val2\", dtype=Float64),\n ],\n)\ndef transformed_conv_rate_fresh(inputs: pd.DataFrame) -> pd.DataFrame:\n df = pd.DataFrame()\n df[\"conv_rate_plus_val1\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add\"]\n df[\"conv_rate_plus_val2\"] = inputs[\"conv_rate\"] + inputs[\"val_to_add_2\"]\n return df\n\n\ndriver_activity_v3 = FeatureService(\n name=\"driver_activity_v3\",\n features=[driver_stats_fresh_fv, transformed_conv_rate_fresh],\n)\n"}
{"template": "pytorch_nlp", "path": "sdk/python/feast/templates/pytorch_nlp/feature_repo/example_repo.py", "src": "\"\"\"\nPyTorch NLP Sentiment Analysis Feature Repository\n\nThis template demonstrates sentiment analysis using:\n- Text feature engineering for NLP\n- PyTorch + Hugging Face transformers integration\n- On-demand sentiment prediction features\n- Online and offline feature serving patterns\n\"\"\"\n\nfrom datetime import timedelta\nfrom pathlib import Path\n\nimport pandas as pd\n\nfrom feast import (\n Entity,\n FeatureService,\n FeatureView,\n Field,\n FileSource,\n RequestSource,\n ValueType,\n)\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Array, Float32, Int64, String\n\ntry:\n # Import static artifacts helpers (available when feature server loads artifacts)\n from static_artifacts import get_lookup_tables, get_sentiment_model\nexcept ImportError:\n # Fallback for when static_artifacts.py is not available\n get_sentiment_model = None\n get_lookup_tables = None\n\n# Global references for static artifacts (set by feature server)\n_sentiment_model = None\n_lookup_tables: dict = {}\n\n# Configuration\nrepo_path = Path(__file__).parent\ndata_path = repo_path / \"data\"\n\n# Define entities - primary keys for joining data\ntext_entity = Entity(\n name=\"text\",\n join_keys=[\"text_id\"],\n value_type=ValueType.STRING,\n description=\"Unique identifier for text samples\",\n)\n\nuser_entity = Entity(\n name=\"user\",\n join_keys=[\"user_id\"],\n value_type=ValueType.STRING,\n description=\"User who created the text content\",\n)\n\n# Data source - points to the parquet file created by bootstrap\nsentiment_source = FileSource(\n name=\"sentiment_data_source\",\n path=str(data_path / \"sentiment_data.parquet\"),\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Feature view for text metadata and engineered features\ntext_features_fv = FeatureView(\n name=\"text_features\",\n entities=[text_entity],\n ttl=timedelta(days=7), # Keep features for 7 days\n schema=[\n Field(name=\"text_content\", dtype=String, description=\"Raw text content\"),\n Field(\n name=\"sentiment_label\",\n dtype=String,\n description=\"Ground truth sentiment label\",\n ),\n Field(\n name=\"sentiment_score\",\n dtype=Float32,\n description=\"Ground truth sentiment score\",\n ),\n Field(name=\"text_length\", dtype=Int64, description=\"Character count of text\"),\n Field(name=\"word_count\", dtype=Int64, description=\"Word count of text\"),\n Field(\n name=\"exclamation_count\",\n dtype=Int64,\n description=\"Number of exclamation marks\",\n ),\n Field(name=\"caps_ratio\", dtype=Float32, description=\"Ratio of capital letters\"),\n Field(\n name=\"emoji_count\", dtype=Int64, description=\"Number of emoji characters\"\n ),\n ],\n online=True,\n source=sentiment_source,\n tags={\"team\": \"nlp\", \"domain\": \"sentiment_analysis\"},\n version=\"latest\",\n)\n\n# Feature view for user-level aggregations\nuser_stats_fv = FeatureView(\n name=\"user_stats\",\n entities=[user_entity],\n ttl=timedelta(days=30), # User stats change less frequently\n schema=[\n Field(\n name=\"user_avg_sentiment\",\n dtype=Float32,\n description=\"User's average sentiment score\",\n ),\n Field(\n name=\"user_text_count\",\n dtype=Int64,\n description=\"Total number of texts by user\",\n ),\n Field(\n name=\"user_avg_text_length\",\n dtype=Float32,\n description=\"User's average text length\",\n ),\n ],\n online=True,\n source=sentiment_source,\n tags={\"team\": \"nlp\", \"domain\": \"user_behavior\"},\n version=\"latest\",\n)\n\n# Request source for real-time inference\ntext_input_request = RequestSource(\n name=\"text_input\",\n schema=[\n Field(\n name=\"input_text\",\n dtype=String,\n description=\"Text to analyze at request time\",\n ),\n Field(\n name=\"model_name\", dtype=String, description=\"Model to use for prediction\"\n ),\n ],\n)\n\n\n# On-demand feature view for real-time sentiment prediction\n@on_demand_feature_view(\n sources=[text_input_request],\n schema=[\n Field(name=\"predicted_sentiment\", dtype=String),\n Field(name=\"sentiment_confidence\", dtype=Float32),\n Field(name=\"positive_prob\", dtype=Float32),\n Field(name=\"negative_prob\", dtype=Float32),\n Field(name=\"neutral_prob\", dtype=Float32),\n Field(name=\"text_embedding\", dtype=Array(Float32)),\n ],\n)\ndef sentiment_prediction(inputs: pd.DataFrame) -> pd.DataFrame:\n \"\"\"\n Real-time sentiment prediction using pre-loaded static artifacts.\n\n This function demonstrates how to use static artifacts (pre-loaded models,\n lookup tables) for efficient real-time inference. Models are loaded once\n at feature server startup rather than on each request.\n \"\"\"\n try:\n import numpy as np\n except ImportError:\n # Fallback to dummy predictions if numpy isn't available\n\n df = pd.DataFrame()\n df[\"predicted_sentiment\"] = [\"neutral\"] * len(inputs)\n df[\"sentiment_confidence\"] = [0.5] * len(inputs)\n df[\"positive_prob\"] = [0.33] * len(inputs)\n df[\"negative_prob\"] = [0.33] * len(inputs)\n df[\"neutral_prob\"] = [0.34] * len(inputs)\n df[\"text_embedding\"] = [[0.0] * 384] * len(inputs)\n return df\n\n # Get pre-loaded static artifacts from global references\n # These are loaded once at startup via static_artifacts.py\n global _sentiment_model, _lookup_tables\n\n sentiment_model = _sentiment_model\n lookup_tables = _lookup_tables\n\n # Use lookup table for label mapping (from static artifacts)\n label_map = lookup_tables.get(\n \"sentiment_labels\",\n {\"LABEL_0\": \"negative\", \"LABEL_1\": \"neutral\", \"LABEL_2\": \"positive\"},\n )\n\n results = []\n\n for text in inputs[\"input_text\"]:\n try:\n if sentiment_model is not None:\n # Use pre-loaded model for prediction\n predictions = sentiment_model(text)\n\n # Parse results using static lookup tables\n scores = {\n label_map.get(pred[\"label\"], pred[\"label\"]): pred[\"score\"]\n for pred in predictions\n }\n\n # Get best prediction\n best_pred = max(predictions, key=lambda x: x[\"score\"])\n predicted_sentiment = label_map.get(\n best_pred[\"label\"], best_pred[\"label\"]\n )\n confidence = best_pred[\"score\"]\n else:\n # Fallback when model is not available\n predicted_sentiment = \"neutral\"\n confidence = 0.5\n scores = {\"positive\": 0.33, \"negative\": 0.33, \"neutral\": 0.34}\n\n # Generate dummy embeddings (in production, use pre-loaded embeddings)\n embedding = np.random.rand(384).tolist()\n\n results.append(\n {\n \"predicted_sentiment\": predicted_sentiment,\n \"sentiment_confidence\": np.float32(confidence),\n \"positive_prob\": np.float32(scores.get(\"positive\", 0.0)),\n \"negative_prob\": np.float32(scores.get(\"negative\", 0.0)),\n \"neutral_prob\": np.float32(scores.get(\"neutral\", 0.0)),\n \"text_embedding\": [np.float32(x) for x in embedding],\n }\n )\n\n except Exception:\n # Fallback for individual text processing errors\n results.append(\n {\n \"predicted_sentiment\": \"neutral\",\n \"sentiment_confidence\": np.float32(0.5),\n \"positive_prob\": np.float32(0.33),\n \"negative_prob\": np.float32(0.33),\n \"neutral_prob\": np.float32(0.34),\n \"text_embedding\": [np.float32(0.0)] * 384,\n }\n )\n\n return pd.DataFrame(results)\n\n\n# Feature services group related features for model serving\nsentiment_analysis_v1 = FeatureService(\n name=\"sentiment_analysis_v1\",\n features=[\n text_features_fv[[\"text_content\", \"text_length\", \"word_count\"]],\n sentiment_prediction,\n ],\n description=\"Basic sentiment analysis features for model v1\",\n)\n\nsentiment_analysis_v2 = FeatureService(\n name=\"sentiment_analysis_v2\",\n features=[\n text_features_fv, # All text features\n user_stats_fv[[\"user_avg_sentiment\", \"user_text_count\"]], # User context\n sentiment_prediction, # Real-time predictions\n ],\n description=\"Advanced sentiment analysis with user context for model v2\",\n)\n\n# Feature service for training data (historical features only)\nsentiment_training_features = FeatureService(\n name=\"sentiment_training_features\",\n features=[\n text_features_fv,\n user_stats_fv,\n ],\n description=\"Historical features for model training and evaluation\",\n)\n"}
{"template": "ray", "path": "sdk/python/feast/templates/ray/feature_repo/feature_definitions.py", "src": "# # # # # # # # # # # # # # # # # # # # # # # #\n# This is an example feature definition file #\n# showcasing Ray offline store and compute #\n# engine capabilities #\n# # # # # # # # # # # # # # # # # # # # # # # #\n\nfrom datetime import timedelta\nfrom pathlib import Path\n\nfrom feast import Entity, FeatureService, FeatureView, Field, ValueType\nfrom feast.infra.offline_stores.contrib.ray_offline_store.ray_source import RaySource\nfrom feast.on_demand_feature_view import on_demand_feature_view\nfrom feast.types import Float32, Float64, Int64\n\n# Constants related to the generated data sets\nCURRENT_DIR = Path(__file__).parent\n\n# Entity definitions\ndriver = Entity(\n name=\"driver\",\n description=\"driver id\",\n value_type=ValueType.INT64,\n join_keys=[\"driver_id\"],\n)\n\ncustomer = Entity(\n name=\"customer\",\n description=\"customer id\",\n value_type=ValueType.INT64,\n join_keys=[\"customer_id\"],\n)\n\n# Data sources \u2014 RaySource is the recommended data source for the Ray offline\n# store. It tells Feast how to load a Ray Dataset from any Ray Data-supported\n# format (Parquet, CSV, JSON, HuggingFace datasets, MongoDB, SQL, and more).\n# Here we read local Parquet files that are generated by bootstrap.py.\ndriver_hourly_stats = RaySource(\n name=\"driver_hourly_stats\",\n reader_type=\"parquet\",\n path=f\"{CURRENT_DIR}/%PARQUET_PATH%\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\ncustomer_daily_profile = RaySource(\n name=\"customer_daily_profile\",\n reader_type=\"parquet\",\n path=f\"{CURRENT_DIR}/data/customer_daily_profile.parquet\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Feature Views - These leverage Ray compute engine for distributed processing\ndriver_hourly_stats_view = FeatureView(\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=7),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_hourly_stats,\n tags={\"team\": \"driver_performance\", \"processing\": \"ray\"},\n version=\"latest\",\n)\n\ncustomer_daily_profile_view = FeatureView(\n name=\"customer_daily_profile\",\n entities=[customer],\n ttl=timedelta(days=7),\n schema=[\n Field(name=\"current_balance\", dtype=Float32),\n Field(name=\"avg_passenger_count\", dtype=Float32),\n Field(name=\"lifetime_trip_count\", dtype=Int64),\n ],\n online=True,\n source=customer_daily_profile,\n tags={\"team\": \"customer_analytics\", \"processing\": \"ray\"},\n version=\"latest\",\n)\n\n\n# On-demand feature view showcasing Ray compute engine capabilities\n# This demonstrates real-time feature transformations using Ray\n@on_demand_feature_view(\n sources=[driver_hourly_stats_view],\n schema=[\n Field(name=\"conv_rate_plus_acc_rate\", dtype=Float64),\n Field(name=\"trips_per_day_normalized\", dtype=Float64),\n ],\n)\ndef driver_activity_v2(inputs: dict):\n \"\"\"\n On-demand feature transformations processed by Ray compute engine.\n These calculations happen in real-time and can leverage Ray's\n distributed processing capabilities.\n \"\"\"\n import pandas as pd\n\n conv_rate = inputs[\"conv_rate\"]\n acc_rate = inputs[\"acc_rate\"]\n avg_daily_trips = inputs[\"avg_daily_trips\"]\n\n # Feature engineering using Ray's distributed processing\n conv_rate_plus_acc_rate = conv_rate + acc_rate\n\n # Normalize trips per day (example of more complex transformation)\n max_trips = avg_daily_trips.max() if len(avg_daily_trips) > 0 else 1\n trips_per_day_normalized = avg_daily_trips / max_trips\n\n return pd.DataFrame(\n {\n \"conv_rate_plus_acc_rate\": conv_rate_plus_acc_rate,\n \"trips_per_day_normalized\": trips_per_day_normalized,\n }\n )\n\n\n# Feature Service - Groups related features for serving\n# Ray compute engine optimizes the retrieval of these feature combinations\ndriver_activity_v1 = FeatureService(\n name=\"driver_activity_v1\",\n features=[\n driver_hourly_stats_view,\n customer_daily_profile_view,\n ],\n tags={\"version\": \"v1\", \"compute_engine\": \"ray\"},\n)\n\ndriver_activity_v2_service = FeatureService(\n name=\"driver_activity_v2\",\n features=[\n driver_hourly_stats_view,\n customer_daily_profile_view,\n driver_activity_v2, # Includes on-demand transformations\n ],\n tags={\"version\": \"v2\", \"compute_engine\": \"ray\", \"transformations\": \"on_demand\"},\n)\n"}
{"template": "ray_rag", "path": "sdk/python/feast/templates/ray_rag/feature_repo/feature_definitions.py", "src": "\"\"\"\nRAG Feature Repository - Movie Embeddings with Ray Native Processing\n\nThis template demonstrates distributed embedding generation using:\n- Ray offline store for scalable data I/O\n- Ray compute engine for parallel processing\n- Milvus online store with vector search capabilities\n\"\"\"\n\nfrom datetime import timedelta\nfrom pathlib import Path\n\nimport pandas as pd\n\nfrom feast import BatchFeatureView, Entity, Field, FileSource, ValueType\nfrom feast.types import Array, Float32, String\n\n# Configuration\nrepo_path = Path(__file__).parent\ndata_path = repo_path / \"data\"\ndata_path.mkdir(exist_ok=True)\n\nEMBED_MODEL_ID = \"sentence-transformers/all-MiniLM-L6-v2\"\n\n# Entity definition\ndocument = Entity(\n name=\"document_id\",\n join_keys=[\"document_id_pk\"],\n value_type=ValueType.STRING,\n description=\"Document identifier for RAG retrieval\",\n)\n\n# Data source\nmovies_source = FileSource(\n path=str(data_path / \"raw_movies.parquet\"),\n timestamp_field=\"DatePublished\",\n)\n\n\n# Embedding processor for distributed Ray processing\nclass EmbeddingProcessor:\n \"\"\"\n Generate embeddings using SentenceTransformer model.\n Model is loaded once per worker and reused for all batches.\n \"\"\"\n\n def __init__(self):\n \"\"\"Initialize model once per worker.\"\"\"\n import torch\n from sentence_transformers import SentenceTransformer\n\n device = \"cuda\" if torch.cuda.is_available() else \"cpu\"\n self.model = SentenceTransformer(EMBED_MODEL_ID, device=device)\n\n def __call__(self, batch: pd.DataFrame) -> pd.DataFrame:\n \"\"\"Process batch and generate embeddings.\"\"\"\n if \"id\" in batch.columns:\n batch[\"document_id\"] = \"movie_\" + batch[\"id\"].astype(str)\n batch[\"document_id_pk\"] = batch[\"document_id\"]\n\n # Generate embeddings from descriptions\n if \"Description\" in batch.columns:\n descriptions = batch[\"Description\"].fillna(\"\").tolist()\n model_batch_size = min(128, max(32, len(descriptions)))\n embeddings = self.model.encode(\n descriptions,\n show_progress_bar=False,\n batch_size=model_batch_size,\n normalize_embeddings=True,\n convert_to_numpy=True,\n )\n batch[\"embedding\"] = embeddings.tolist()\n batch[\"embedding_model\"] = EMBED_MODEL_ID\n\n # Standardize movie-related metadata\n if \"Name\" in batch.columns:\n batch[\"movie_name\"] = batch[\"Name\"].fillna(\"\")\n if \"Director\" in batch.columns:\n batch[\"movie_director\"] = batch[\"Director\"].fillna(\"\")\n if \"Genres\" in batch.columns:\n batch[\"movie_genres\"] = batch[\"Genres\"].fillna(\"\")\n if \"RatingValue\" in batch.columns:\n batch[\"movie_rating\"] = batch[\"RatingValue\"].fillna(0.0)\n\n return batch\n\n\n# Ray native UDF - Fully adaptive to cluster resources\ndef generate_embeddings_ray_native(ds):\n \"\"\"\n Distributed embedding generation using Ray Data.\n \"\"\"\n # Ray transformation mode providing control to user over the resources\n # Optimize the resources for the transformation\n num_blocks = ds.num_blocks()\n max_workers = 9\n batch_size = 2500\n try:\n sample = ds.take(1)\n has_data = len(sample) > 0\n except Exception:\n has_data = False\n if has_data and num_blocks < max_workers:\n ds = ds.repartition(max_workers)\n\n result = ds.map_batches(\n EmbeddingProcessor,\n batch_format=\"pandas\",\n concurrency=max_workers,\n batch_size=batch_size,\n )\n return result\n\n\n# Batch feature view for embeddings with metadata\ndocument_embeddings_view = BatchFeatureView(\n name=\"document_embeddings\",\n entities=[document],\n mode=\"ray\", # Native Ray Dataset mode for distributed processing\n ttl=timedelta(days=365 * 100),\n schema=[\n Field(name=\"document_id\", dtype=String),\n Field(name=\"document_id_pk\", dtype=String),\n Field(name=\"embedding\", dtype=Array(Float32), vector_index=True),\n Field(name=\"embedding_model\", dtype=String),\n Field(name=\"movie_name\", dtype=String),\n Field(name=\"movie_director\", dtype=String),\n Field(name=\"movie_genres\", dtype=String),\n Field(name=\"movie_rating\", dtype=Float32),\n ],\n source=movies_source,\n udf=generate_embeddings_ray_native,\n online=True,\n tags={\n \"team\": \"ml_platform\",\n \"use_case\": \"rag\",\n \"transformation_mode\": \"ray_native\",\n },\n)\n"}
{"template": "spark", "path": "sdk/python/feast/templates/spark/feature_repo/feature_definitions.py", "src": "# # # # # # # # # # # # # # # # # # # # # # # #\n# This is an example feature definition file #\n# # # # # # # # # # # # # # # # # # # # # # # #\n\nfrom datetime import timedelta\nfrom pathlib import Path\n\nfrom feast import Entity, FeatureService, FeatureView, Field\nfrom feast.infra.offline_stores.contrib.spark_offline_store.spark_source import (\n SparkSource,\n)\nfrom feast.types import Float32, Int64\n\n# Constants related to the generated data sets\nCURRENT_DIR = Path(__file__).parent\n\n\n# Entity definitions\ndriver = Entity(\n name=\"driver\",\n description=\"driver id\",\n)\ncustomer = Entity(\n name=\"customer\",\n description=\"customer id\",\n)\n\n# Sources\ndriver_hourly_stats = SparkSource(\n name=\"driver_hourly_stats\",\n path=f\"{CURRENT_DIR}/data/driver_hourly_stats.parquet\",\n file_format=\"parquet\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\ncustomer_daily_profile = SparkSource(\n name=\"customer_daily_profile\",\n path=f\"{CURRENT_DIR}/data/customer_daily_profile.parquet\",\n file_format=\"parquet\",\n timestamp_field=\"event_timestamp\",\n created_timestamp_column=\"created\",\n)\n\n# Feature Views\ndriver_hourly_stats_view = FeatureView(\n name=\"driver_hourly_stats\",\n entities=[driver],\n ttl=timedelta(days=7),\n schema=[\n Field(name=\"conv_rate\", dtype=Float32),\n Field(name=\"acc_rate\", dtype=Float32),\n Field(name=\"avg_daily_trips\", dtype=Int64),\n ],\n online=True,\n source=driver_hourly_stats,\n tags={},\n version=\"latest\",\n)\ncustomer_daily_profile_view = FeatureView(\n name=\"customer_daily_profile\",\n entities=[customer],\n ttl=timedelta(days=7),\n schema=[\n Field(name=\"current_balance\", dtype=Float32),\n Field(name=\"avg_passenger_count\", dtype=Float32),\n Field(name=\"lifetime_trip_count\", dtype=Int64),\n ],\n online=True,\n source=customer_daily_profile,\n tags={},\n version=\"latest\",\n)\n\ndriver_stats_fs = FeatureService(\n name=\"driver_activity\",\n features=[driver_hourly_stats_view, customer_daily_profile_view],\n)\n"}