Skip to content

Commit

Permalink
docs: Updated on demand feature view documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Javier Arceo <[email protected]>
  • Loading branch information
franciscojavierarceo committed Apr 26, 2024
1 parent 8b5698f commit 2d51fc8
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ The list below contains the functionality that contributors are planning to deve
* [x] [Cassandra / AstraDB (contrib plugin)](https://docs.feast.dev/reference/online-stores/cassandra)
* [x] [Custom online store support](https://docs.feast.dev/how-to-guides/customizing-feast/adding-support-for-a-new-online-store)
* **Feature Engineering**
* [x] On-demand Transformations (Alpha release. See [RFC](https://docs.google.com/document/d/1lgfIw0Drc65LpaxbUu49RCeJgMew547meSJttnUqz7c/edit#))
* [x] On-demand Transformations (Beta release. See [RFC](https://docs.google.com/document/d/1lgfIw0Drc65LpaxbUu49RCeJgMew547meSJttnUqz7c/edit#))
* [x] Streaming Transformations (Alpha release. See [RFC](https://docs.google.com/document/d/1UzEyETHUaGpn0ap4G82DHluiCj7zEbrQLkJJkKSv4e8/edit))
* [ ] Batch transformation (In progress. See [RFC](https://docs.google.com/document/d/1964OkzuBljifDvkV-0fakp2uaijnVzdwWNGdz7Vz50A/edit))
* **Streaming**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# \[Alpha] On demand feature view
# \[Beta] On demand feature view

**Warning**: This is an _experimental_ feature. It's intended for early testing and feedback, and could change without warnings in future releases.
**Warning**: This is an experimental feature. To our knowledge, this is stable, but there are still rough edges in the experience. Contributions are welcome!

## Overview

Expand Down Expand Up @@ -32,11 +32,14 @@ See [https://github.com/feast-dev/on-demand-feature-views-demo](https://github.c

### **Registering transformations**

On Demand Transformations support transformations using Pandas and native Python. Note, Native Python is much faster but not yet tested for offline retrieval.

We register `RequestSource` inputs and the transform in `on_demand_feature_view`:

```python
from feast import Field, RequestSource
from feast.types import Float64, Int64
from typing import Any, Dict
import pandas as pd

# Define a request data source which encodes features / information only
Expand All @@ -49,7 +52,7 @@ input_request = RequestSource(
]
)

# Use the input data and feature view features to create new features
# Use the input data and feature view features to create new features Pandas mode
@on_demand_feature_view(
sources=[
driver_hourly_stats_view,
Expand All @@ -58,13 +61,43 @@ input_request = RequestSource(
schema=[
Field(name='conv_rate_plus_val1', dtype=Float64),
Field(name='conv_rate_plus_val2', dtype=Float64)
]
],
mode="pandas",
)
def transformed_conv_rate(features_df: pd.DataFrame) -> pd.DataFrame:
df = pd.DataFrame()
df['conv_rate_plus_val1'] = (features_df['conv_rate'] + features_df['val_to_add'])
df['conv_rate_plus_val2'] = (features_df['conv_rate'] + features_df['val_to_add_2'])
return df

# Use the input data and feature view features to create new features Python mode
@on_demand_feature_view(
sources=[
driver_hourly_stats_view,
input_request
],
schema=[
Field(name='conv_rate_plus_val1_python', dtype=Float64),
Field(name='conv_rate_plus_val2_python', dtype=Float64),
],
mode="python",
)
def transformed_conv_rate_python(inputs: Dict[str, Any]) -> Dict[str, Any]:
output: Dict[str, Any] = {
"conv_rate_plus_val1_python": [
conv_rate + val_to_add
for conv_rate, val_to_add in zip(
inputs["conv_rate"], inputs["val_to_add"]
)
],
"conv_rate_plus_val2_python": [
conv_rate + val_to_add
for conv_rate, val_to_add in zip(
inputs["conv_rate"], inputs["val_to_add_2"]
)
]
}
return output
```

### **Feature retrieval**
Expand All @@ -73,7 +106,9 @@ def transformed_conv_rate(features_df: pd.DataFrame) -> pd.DataFrame:
The on demand feature view's name is the function name (i.e. `transformed_conv_rate`).
{% endhint %}

And then to retrieve historical or online features, we can call this in a feature service or reference individual features:

#### Offline Features
And then to retrieve historical, we can call this in a feature service or reference individual features:

```python
training_df = store.get_historical_features(
Expand All @@ -86,4 +121,29 @@ training_df = store.get_historical_features(
"transformed_conv_rate:conv_rate_plus_val2",
],
).to_df()

```

#### Online Features

And then to retrieve online, we can call this in a feature service or reference individual features:

```python
entity_rows = [
{
"driver_id": 1001,
"val_to_add": 1,
"val_to_add_2": 2,
}
]

online_response = store.get_online_features(
entity_rows=entity_rows,
features=[
"driver_hourly_stats:conv_rate",
"driver_hourly_stats:acc_rate",
"transformed_conv_rate_python:conv_rate_plus_val1_python",
"transformed_conv_rate_python:conv_rate_plus_val2_python",
],
).to_dict()
```
2 changes: 1 addition & 1 deletion docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The list below contains the functionality that contributors are planning to deve
* [x] [Cassandra / AstraDB (contrib plugin)](https://docs.feast.dev/reference/online-stores/cassandra)
* [x] [Custom online store support](https://docs.feast.dev/how-to-guides/customizing-feast/adding-support-for-a-new-online-store)
* **Feature Engineering**
* [x] On-demand Transformations (Alpha release. See [RFC](https://docs.google.com/document/d/1lgfIw0Drc65LpaxbUu49RCeJgMew547meSJttnUqz7c/edit#))
* [x] On-demand Transformations (Beta release. See [RFC](https://docs.google.com/document/d/1lgfIw0Drc65LpaxbUu49RCeJgMew547meSJttnUqz7c/edit#))
* [x] Streaming Transformations (Alpha release. See [RFC](https://docs.google.com/document/d/1UzEyETHUaGpn0ap4G82DHluiCj7zEbrQLkJJkKSv4e8/edit))
* [ ] Batch transformation (In progress. See [RFC](https://docs.google.com/document/d/1964OkzuBljifDvkV-0fakp2uaijnVzdwWNGdz7Vz50A/edit))
* **Streaming**
Expand Down
18 changes: 18 additions & 0 deletions sdk/python/tests/unit/test_on_demand_python_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ def python_view(inputs: Dict[str, Any]) -> Dict[str, Any]:
}
return output

@on_demand_feature_view(
sources=[driver_stats_fv[["conv_rate", "acc_rate"]]],
schema=[
Field(name="conv_rate_plus_val1_python", dtype=Float64)],
Field(name="conv_rate_plus_val2_python", dtype=Float64)],
mode="python",
)
def python_demo_view(inputs: Dict[str, Any]) -> Dict[str, Any]:
output: Dict[str, Any] = {
"conv_rate_plus_acc_python": [
conv_rate + acc_rate
for conv_rate, acc_rate in zip(
inputs["conv_rate"], inputs["acc_rate"]
)
]
}
return output

@on_demand_feature_view(
sources=[driver_stats_fv[["conv_rate", "acc_rate"]]],
schema=[
Expand Down

0 comments on commit 2d51fc8

Please sign in to comment.