Skip to content

Commit 1e02066

Browse files
authored
fix: Feature service to templates (#2649)
* add templates Signed-off-by: Kevin Zhang <[email protected]> * Lint Signed-off-by: Kevin Zhang <[email protected]> * Fix Signed-off-by: Kevin Zhang <[email protected]>
1 parent 640ff12 commit 1e02066

File tree

6 files changed

+74
-14
lines changed

6 files changed

+74
-14
lines changed

docs/getting-started/quickstart.md

Lines changed: 54 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ driver_hourly_stats_view = FeatureView(
116116
source=driver_hourly_stats,
117117
tags={},
118118
)
119+
120+
driver_stats_fs = FeatureService(
121+
name="driver_activity",
122+
features=[driver_hourly_stats_view]
123+
)
119124
```
120125
{% endtab %}
121126
{% endtabs %}
@@ -186,6 +191,11 @@ driver_hourly_stats_view = FeatureView(
186191
source=driver_hourly_stats,
187192
tags={},
188193
)
194+
195+
driver_stats_fs = FeatureService(
196+
name="driver_activity",
197+
features=[driver_hourly_stats_view]
198+
)
189199
```
190200
{% endtab %}
191201
{% endtabs %}
@@ -223,7 +233,7 @@ entity_df = pd.DataFrame.from_dict(
223233
"driver_id": [1001, 1002, 1003],
224234

225235
# label name -> label values
226-
"label_driver_reported_satisfaction": [1, 5, 3],
236+
"label_driver_reported_satisfaction": [1, 5, 3],
227237

228238
# "event_timestamp" (reserved key) -> timestamps
229239
"event_timestamp": [
@@ -263,14 +273,14 @@ print(training_df.head())
263273
<class 'pandas.core.frame.DataFrame'>
264274
Int64Index: 3 entries, 0 to 2
265275
Data columns (total 6 columns):
266-
# Column Non-Null Count Dtype
267-
--- ------ -------------- -----
276+
# Column Non-Null Count Dtype
277+
--- ------ -------------- -----
268278
0 event_timestamp 3 non-null datetime64[ns, UTC]
269-
1 driver_id 3 non-null int64
270-
2 label_driver_reported_satisfaction 3 non-null int64
271-
3 conv_rate 3 non-null float32
272-
4 acc_rate 3 non-null float32
273-
5 avg_daily_trips 3 non-null int32
279+
1 driver_id 3 non-null int64
280+
2 label_driver_reported_satisfaction 3 non-null int64
281+
3 conv_rate 3 non-null float32
282+
4 acc_rate 3 non-null float32
283+
5 avg_daily_trips 3 non-null int32
274284
dtypes: datetime64[ns, UTC](1), float32(2), int32(1), int64(2)
275285
memory usage: 132.0 bytes
276286
None
@@ -303,7 +313,7 @@ feast materialize-incremental $CURRENT_TIME
303313
{% tabs %}
304314
{% tab title="Output" %}
305315
```bash
306-
Materializing 1 feature views to 2021-08-23 16:25:46+00:00 into the sqlite online
316+
Materializing 1 feature views to 2021-08-23 16:25:46+00:00 into the sqlite online
307317
store.
308318

309319
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)
355365
{% endtab %}
356366
{% endtabs %}
357367

368+
## Step 7: Using a featureservice to fetch online features instead.
369+
370+
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).
371+
372+
{% tabs %}
373+
{% tab title="Python" %}
374+
```python
375+
from feast import FeatureStore
376+
feature_store = FeatureStore('.') # Initialize the feature store
377+
378+
feature_service = feature_store.get_feature_service("driver_activity")
379+
features = feature_store.get_online_features(
380+
features=feature_service,
381+
entity_rows=[
382+
# {join_key: entity_value}
383+
{"driver_id": 1004},
384+
{"driver_id": 1005},
385+
],
386+
).to_dict()
387+
```
388+
389+
{% tabs %}
390+
{% tab title="Output" %}
391+
```bash
392+
{
393+
'acc_rate': [0.5732735991477966, 0.7828438878059387],
394+
'avg_daily_trips': [33, 984],
395+
'conv_rate': [0.15498852729797363, 0.6263588070869446],
396+
'driver_id': [1004, 1005]
397+
}
398+
```
399+
{% endtab %}
400+
{% endtabs %}
401+
402+
358403
## Next steps
359404

360405
* Read the [Concepts](concepts/) page to understand the Feast data model.

sdk/python/feast/templates/aws/driver_repo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import timedelta
22

3-
from feast import Entity, FeatureView, Field, RedshiftSource, ValueType
3+
from feast import Entity, FeatureService, FeatureView, Field, RedshiftSource, ValueType
44
from feast.types import Float32, Int64
55

66
# Define an entity for the driver. Entities can be thought of as primary keys used to
@@ -65,3 +65,5 @@
6565
# feature view
6666
tags={"team": "driver_performance"},
6767
)
68+
69+
driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv])

sdk/python/feast/templates/gcp/driver_repo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import timedelta
22

3-
from feast import BigQuerySource, Entity, FeatureView, Field, ValueType
3+
from feast import BigQuerySource, Entity, FeatureService, FeatureView, Field, ValueType
44
from feast.types import Float32, Int64
55

66
# Define an entity for the driver. Entities can be thought of as primary keys used to
@@ -63,3 +63,5 @@
6363
# feature view
6464
tags={"team": "driver_performance"},
6565
)
66+
67+
driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv])

sdk/python/feast/templates/local/example.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from datetime import timedelta
44

5-
from feast import Entity, FeatureView, Field, FileSource, ValueType
5+
from feast import Entity, FeatureService, FeatureView, Field, FileSource, ValueType
66
from feast.types import Float32, Int64
77

88
# Read data from parquet files. Parquet is convenient for local development mode. For
@@ -34,3 +34,7 @@
3434
source=driver_hourly_stats,
3535
tags={},
3636
)
37+
38+
driver_stats_fs = FeatureService(
39+
name="driver_activity", features=[driver_hourly_stats_view]
40+
)

sdk/python/feast/templates/snowflake/driver_repo.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import yaml
44

5-
from feast import Entity, FeatureView, Field, SnowflakeSource
5+
from feast import Entity, FeatureService, FeatureView, Field, SnowflakeSource
66
from feast.types import Float32, Int64
77

88
# Define an entity for the driver. Entities can be thought of as primary keys used to
@@ -64,3 +64,5 @@
6464
# features
6565
batch_source=driver_stats_source,
6666
)
67+
68+
driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv])

sdk/python/feast/templates/spark/example.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from datetime import timedelta
66
from pathlib import Path
77

8-
from feast import Entity, FeatureView, Field, ValueType
8+
from feast import Entity, FeatureService, FeatureView, Field, ValueType
99
from feast.infra.offline_stores.contrib.spark_offline_store.spark_source import (
1010
SparkSource,
1111
)
@@ -64,3 +64,8 @@
6464
source=customer_daily_profile,
6565
tags={},
6666
)
67+
68+
driver_stats_fs = FeatureService(
69+
name="driver_activity",
70+
features=[driver_hourly_stats_view, customer_daily_profile_view],
71+
)

0 commit comments

Comments
 (0)