From 23e2c5a0888e46d326e50e81dde0ccc2a51b6ace Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 6 May 2022 15:39:33 -0700 Subject: [PATCH 1/3] add templates Signed-off-by: Kevin Zhang --- docs/getting-started/quickstart.md | 63 ++++++++++++++++--- sdk/python/feast/templates/aws/driver_repo.py | 7 ++- sdk/python/feast/templates/gcp/driver_repo.py | 7 ++- sdk/python/feast/templates/local/example.py | 7 ++- .../feast/templates/snowflake/driver_repo.py | 7 ++- sdk/python/feast/templates/spark/example.py | 7 ++- 6 files changed, 84 insertions(+), 14 deletions(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index e9a294d5fc..5f0bc9de6d 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -116,6 +116,11 @@ driver_hourly_stats_view = FeatureView( source=driver_hourly_stats, tags={}, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_hourly_stats_view] +) ``` {% endtab %} {% endtabs %} @@ -186,6 +191,11 @@ driver_hourly_stats_view = FeatureView( source=driver_hourly_stats, tags={}, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_hourly_stats_view] +) ``` {% endtab %} {% endtabs %} @@ -223,7 +233,7 @@ entity_df = pd.DataFrame.from_dict( "driver_id": [1001, 1002, 1003], # label name -> label values - "label_driver_reported_satisfaction": [1, 5, 3], + "label_driver_reported_satisfaction": [1, 5, 3], # "event_timestamp" (reserved key) -> timestamps "event_timestamp": [ @@ -263,14 +273,14 @@ print(training_df.head()) Int64Index: 3 entries, 0 to 2 Data columns (total 6 columns): - # Column Non-Null Count Dtype ---- ------ -------------- ----- + # Column Non-Null Count Dtype +--- ------ -------------- ----- 0 event_timestamp 3 non-null datetime64[ns, UTC] - 1 driver_id 3 non-null int64 - 2 label_driver_reported_satisfaction 3 non-null int64 - 3 conv_rate 3 non-null float32 - 4 acc_rate 3 non-null float32 - 5 avg_daily_trips 3 non-null int32 + 1 driver_id 3 non-null int64 + 2 label_driver_reported_satisfaction 3 non-null int64 + 3 conv_rate 3 non-null float32 + 4 acc_rate 3 non-null float32 + 5 avg_daily_trips 3 non-null int32 dtypes: datetime64[ns, UTC](1), float32(2), int32(1), int64(2) memory usage: 132.0 bytes None @@ -303,7 +313,7 @@ feast materialize-incremental $CURRENT_TIME {% tabs %} {% tab title="Output" %} ```bash -Materializing 1 feature views to 2021-08-23 16:25:46+00:00 into the sqlite online +Materializing 1 feature views to 2021-08-23 16:25:46+00:00 into the sqlite online store. driver_hourly_stats from 2021-08-22 16:25:47+00:00 to 2021-08-23 16:25:46+00:00: @@ -355,6 +365,41 @@ pprint(feature_vector) {% endtab %} {% endtabs %} +## Step 7: Using a featureservice to fetch online features instead. + +You can also use the feature service to manage multiple features and be a central source of truth for a series of feature views. The feature store can also be used to fetch either online or historical features using the same api below. More information can be found [here](https://docs.feast.dev/getting-started/concepts/feature-service). + +{% tabs %} +{% tab title="Python" %} +```python +from feast import FeatureStore +feature_store = FeatureStore('.') # Initialize the feature store + +feature_service = feature_store.get_feature_service("driver_activity") +features = feature_store.get_online_features( + features=feature_service, + entity_rows=[ + # {join_key: entity_value} + {"driver_id": 1004}, + {"driver_id": 1005}, + ], +).to_dict() +``` + +{% tabs %} +{% tab title="Output" %} +```bash +{ + 'acc_rate': [0.5732735991477966, 0.7828438878059387], + 'avg_daily_trips': [33, 984], + 'conv_rate': [0.15498852729797363, 0.6263588070869446], + 'driver_id': [1004, 1005] +} +``` +{% endtab %} +{% endtabs %} + + ## Next steps * Read the [Concepts](concepts/) page to understand the Feast data model. diff --git a/sdk/python/feast/templates/aws/driver_repo.py b/sdk/python/feast/templates/aws/driver_repo.py index 5188f57cf8..8f19624e53 100644 --- a/sdk/python/feast/templates/aws/driver_repo.py +++ b/sdk/python/feast/templates/aws/driver_repo.py @@ -1,6 +1,6 @@ from datetime import timedelta -from feast import Entity, FeatureView, Field, RedshiftSource, ValueType +from feast import Entity, FeatureView, Field, RedshiftSource, ValueType, FeatureService from feast.types import Float32, Int64 # Define an entity for the driver. Entities can be thought of as primary keys used to @@ -65,3 +65,8 @@ # feature view tags={"team": "driver_performance"}, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_stats_fv] +) \ No newline at end of file diff --git a/sdk/python/feast/templates/gcp/driver_repo.py b/sdk/python/feast/templates/gcp/driver_repo.py index 7d137f996b..55405d5a35 100644 --- a/sdk/python/feast/templates/gcp/driver_repo.py +++ b/sdk/python/feast/templates/gcp/driver_repo.py @@ -1,6 +1,6 @@ from datetime import timedelta -from feast import BigQuerySource, Entity, FeatureView, Field, ValueType +from feast import BigQuerySource, Entity, FeatureView, Field, ValueType, FeatureService from feast.types import Float32, Int64 # Define an entity for the driver. Entities can be thought of as primary keys used to @@ -63,3 +63,8 @@ # feature view tags={"team": "driver_performance"}, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_stats_fv] +) \ No newline at end of file diff --git a/sdk/python/feast/templates/local/example.py b/sdk/python/feast/templates/local/example.py index 1d441e0e99..45e8be89fa 100644 --- a/sdk/python/feast/templates/local/example.py +++ b/sdk/python/feast/templates/local/example.py @@ -2,7 +2,7 @@ from datetime import timedelta -from feast import Entity, FeatureView, Field, FileSource, ValueType +from feast import Entity, FeatureView, Field, FileSource, ValueType, FeatureService from feast.types import Float32, Int64 # Read data from parquet files. Parquet is convenient for local development mode. For @@ -34,3 +34,8 @@ source=driver_hourly_stats, tags={}, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_hourly_stats_view] +) \ No newline at end of file diff --git a/sdk/python/feast/templates/snowflake/driver_repo.py b/sdk/python/feast/templates/snowflake/driver_repo.py index ecccb9863b..b0ec49dcf4 100644 --- a/sdk/python/feast/templates/snowflake/driver_repo.py +++ b/sdk/python/feast/templates/snowflake/driver_repo.py @@ -2,7 +2,7 @@ import yaml -from feast import Entity, FeatureView, Field, SnowflakeSource +from feast import Entity, FeatureView, Field, SnowflakeSource, FeatureService from feast.types import Float32, Int64 # Define an entity for the driver. Entities can be thought of as primary keys used to @@ -64,3 +64,8 @@ # features batch_source=driver_stats_source, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_stats_fv] +) diff --git a/sdk/python/feast/templates/spark/example.py b/sdk/python/feast/templates/spark/example.py index 58f3df740f..bc48e82ee0 100644 --- a/sdk/python/feast/templates/spark/example.py +++ b/sdk/python/feast/templates/spark/example.py @@ -5,7 +5,7 @@ from datetime import timedelta from pathlib import Path -from feast import Entity, FeatureView, Field, ValueType +from feast import Entity, FeatureView, Field, ValueType, FeatureService from feast.infra.offline_stores.contrib.spark_offline_store.spark_source import ( SparkSource, ) @@ -64,3 +64,8 @@ source=customer_daily_profile, tags={}, ) + +driver_stats_fs = FeatureService( + name="driver_activity", + features=[driver_hourly_stats_view, customer_daily_profile_view] +) From 55e64af5b1dd170dc0ebe607e9c80532a1af2ebf Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Fri, 6 May 2022 15:40:18 -0700 Subject: [PATCH 2/3] Lint Signed-off-by: Kevin Zhang --- sdk/python/feast/templates/aws/driver_repo.py | 7 ++----- sdk/python/feast/templates/gcp/driver_repo.py | 7 ++----- sdk/python/feast/templates/local/example.py | 7 +++---- sdk/python/feast/templates/snowflake/driver_repo.py | 7 ++----- sdk/python/feast/templates/spark/example.py | 4 ++-- 5 files changed, 11 insertions(+), 21 deletions(-) diff --git a/sdk/python/feast/templates/aws/driver_repo.py b/sdk/python/feast/templates/aws/driver_repo.py index 8f19624e53..8ebe0b6e92 100644 --- a/sdk/python/feast/templates/aws/driver_repo.py +++ b/sdk/python/feast/templates/aws/driver_repo.py @@ -1,6 +1,6 @@ from datetime import timedelta -from feast import Entity, FeatureView, Field, RedshiftSource, ValueType, FeatureService +from feast import Entity, FeatureService, FeatureView, Field, RedshiftSource, ValueType from feast.types import Float32, Int64 # Define an entity for the driver. Entities can be thought of as primary keys used to @@ -66,7 +66,4 @@ tags={"team": "driver_performance"}, ) -driver_stats_fs = FeatureService( - name="driver_activity", - features=[driver_stats_fv] -) \ No newline at end of file +driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv]) diff --git a/sdk/python/feast/templates/gcp/driver_repo.py b/sdk/python/feast/templates/gcp/driver_repo.py index 55405d5a35..a4517516b5 100644 --- a/sdk/python/feast/templates/gcp/driver_repo.py +++ b/sdk/python/feast/templates/gcp/driver_repo.py @@ -1,6 +1,6 @@ from datetime import timedelta -from feast import BigQuerySource, Entity, FeatureView, Field, ValueType, FeatureService +from feast import BigQuerySource, Entity, FeatureService, FeatureView, Field, ValueType from feast.types import Float32, Int64 # Define an entity for the driver. Entities can be thought of as primary keys used to @@ -64,7 +64,4 @@ tags={"team": "driver_performance"}, ) -driver_stats_fs = FeatureService( - name="driver_activity", - features=[driver_stats_fv] -) \ No newline at end of file +driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv]) diff --git a/sdk/python/feast/templates/local/example.py b/sdk/python/feast/templates/local/example.py index 45e8be89fa..7633947e6e 100644 --- a/sdk/python/feast/templates/local/example.py +++ b/sdk/python/feast/templates/local/example.py @@ -2,7 +2,7 @@ from datetime import timedelta -from feast import Entity, FeatureView, Field, FileSource, ValueType, FeatureService +from feast import Entity, FeatureService, FeatureView, Field, FileSource, ValueType from feast.types import Float32, Int64 # Read data from parquet files. Parquet is convenient for local development mode. For @@ -36,6 +36,5 @@ ) driver_stats_fs = FeatureService( - name="driver_activity", - features=[driver_hourly_stats_view] -) \ No newline at end of file + name="driver_activity", features=[driver_hourly_stats_view] +) diff --git a/sdk/python/feast/templates/snowflake/driver_repo.py b/sdk/python/feast/templates/snowflake/driver_repo.py index b0ec49dcf4..ceaf0ba8de 100644 --- a/sdk/python/feast/templates/snowflake/driver_repo.py +++ b/sdk/python/feast/templates/snowflake/driver_repo.py @@ -2,7 +2,7 @@ import yaml -from feast import Entity, FeatureView, Field, SnowflakeSource, FeatureService +from feast import Entity, FeatureService, FeatureView, Field, SnowflakeSource from feast.types import Float32, Int64 # Define an entity for the driver. Entities can be thought of as primary keys used to @@ -65,7 +65,4 @@ batch_source=driver_stats_source, ) -driver_stats_fs = FeatureService( - name="driver_activity", - features=[driver_stats_fv] -) +driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv]) diff --git a/sdk/python/feast/templates/spark/example.py b/sdk/python/feast/templates/spark/example.py index bc48e82ee0..da334dd83c 100644 --- a/sdk/python/feast/templates/spark/example.py +++ b/sdk/python/feast/templates/spark/example.py @@ -5,7 +5,7 @@ from datetime import timedelta from pathlib import Path -from feast import Entity, FeatureView, Field, ValueType, FeatureService +from feast import Entity, FeatureService, FeatureView, Field, ValueType from feast.infra.offline_stores.contrib.spark_offline_store.spark_source import ( SparkSource, ) @@ -67,5 +67,5 @@ driver_stats_fs = FeatureService( name="driver_activity", - features=[driver_hourly_stats_view, customer_daily_profile_view] + features=[driver_hourly_stats_view, customer_daily_profile_view], ) From 26770b9e7e01e415cc907c49487b3c2007d932d0 Mon Sep 17 00:00:00 2001 From: Kevin Zhang Date: Mon, 9 May 2022 17:05:15 -0700 Subject: [PATCH 3/3] Fix Signed-off-by: Kevin Zhang --- docs/getting-started/quickstart.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index 5f0bc9de6d..f2446b4c1c 100644 --- a/docs/getting-started/quickstart.md +++ b/docs/getting-started/quickstart.md @@ -367,7 +367,7 @@ pprint(feature_vector) ## Step 7: Using a featureservice to fetch online features instead. -You can also use the feature service to manage multiple features and be a central source of truth for a series of feature views. The feature store can also be used to fetch either online or historical features using the same api below. More information can be found [here](https://docs.feast.dev/getting-started/concepts/feature-service). +You can also use feature services to manage multiple features, and decouple feature view definitions and the features needed by end applications. The feature store can also be used to fetch either online or historical features using the same api below. More information can be found [here](https://docs.feast.dev/getting-started/concepts/feature-service). {% tabs %} {% tab title="Python" %}