Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Feature service to templates #2649

Merged
merged 3 commits into from
May 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 54 additions & 9 deletions docs/getting-started/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand Down Expand Up @@ -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 %}
Expand Down Expand Up @@ -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": [
Expand Down Expand Up @@ -263,14 +273,14 @@ print(training_df.head())
<class 'pandas.core.frame.DataFrame'>
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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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]
Comment on lines +393 to +396
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we expect these exact values? If not, we should caveat that the numbers here in the example may be different from what users see.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
```
{% endtab %}
{% endtabs %}


## Next steps

* Read the [Concepts](concepts/) page to understand the Feast data model.
Expand Down
4 changes: 3 additions & 1 deletion sdk/python/feast/templates/aws/driver_repo.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -65,3 +65,5 @@
# feature view
tags={"team": "driver_performance"},
)

driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv])
4 changes: 3 additions & 1 deletion sdk/python/feast/templates/gcp/driver_repo.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -63,3 +63,5 @@
# feature view
tags={"team": "driver_performance"},
)

driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv])
6 changes: 5 additions & 1 deletion sdk/python/feast/templates/local/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -34,3 +34,7 @@
source=driver_hourly_stats,
tags={},
)

driver_stats_fs = FeatureService(
name="driver_activity", features=[driver_hourly_stats_view]
)
4 changes: 3 additions & 1 deletion sdk/python/feast/templates/snowflake/driver_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -64,3 +64,5 @@
# features
batch_source=driver_stats_source,
)

driver_stats_fs = FeatureService(name="driver_activity", features=[driver_stats_fv])
7 changes: 6 additions & 1 deletion sdk/python/feast/templates/spark/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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],
)