diff --git a/docs/getting-started/quickstart.md b/docs/getting-started/quickstart.md index e9a294d5fce..f2446b4c1c6 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 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" %} +```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 5188f57cf83..8ebe0b6e927 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, 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 @@ -65,3 +65,5 @@ # feature view tags={"team": "driver_performance"}, ) + +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 7d137f996b6..a4517516b56 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, 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 @@ -63,3 +63,5 @@ # feature view tags={"team": "driver_performance"}, ) + +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 1d441e0e995..7633947e6e4 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, FeatureService, FeatureView, Field, FileSource, ValueType from feast.types import Float32, Int64 # Read data from parquet files. Parquet is convenient for local development mode. For @@ -34,3 +34,7 @@ source=driver_hourly_stats, tags={}, ) + +driver_stats_fs = FeatureService( + 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 ecccb9863bc..ceaf0ba8de8 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, 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 @@ -64,3 +64,5 @@ # 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 58f3df740f3..da334dd83ca 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, FeatureService, FeatureView, Field, ValueType 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], +)