You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Warning**: This is an experimental feature. To our knowledge, this is stable, but there are still rough edges in the experience. Contributions are welcome!
3
+
**Warning**: This is an experimental feature. While it is stable to our knowledge, there may still be rough edges in the experience. Contributions are welcome!
4
4
5
5
## Overview
6
6
7
-
On Demand Feature Views (ODFVs) allow data scientists to use existing features and request-time data (features only
8
-
available at request time) to transform and create new features. Users define Python transformation logic which is
9
-
executed during both historical retrieval and online retrieval. Additionally, ODFVs provide flexibility in
10
-
applying transformations either during data ingestion (at write time) or during feature retrieval (at read time),
11
-
controlled via the `write_to_online_store` parameter.
7
+
On Demand Feature Views (ODFVs) allow data scientists to use existing features and request-time data to transform and
8
+
create new features. Users define transformation logic that is executed during both historical and online retrieval.
9
+
Additionally, ODFVs provide flexibility in applying transformations either during data ingestion (at write time) or
10
+
during feature retrieval (at read time), controlled via the `write_to_online_store` parameter.
12
11
13
12
By setting `write_to_online_store=True`, transformations are applied during data ingestion, and the transformed
14
13
features are stored in the online store. This can improve online feature retrieval performance by reducing computation
15
14
during reads. Conversely, if `write_to_online_store=False` (the default if omitted), transformations are applied during
16
15
feature retrieval.
17
16
18
-
### Why use on demand feature views?
17
+
### Why Use On Demand Feature Views?
19
18
20
-
This enables data scientists to easily impact the online feature retrieval path. For example, a data scientist could
19
+
ODFVs enable data scientists to easily impact the online feature retrieval path. For example, a data scientist could:
21
20
22
-
1. Call `get_historical_features` to generate a training dataframe
23
-
2. Iterate in notebook on feature engineering in Pandas/Python
24
-
3. Copy transformation logic into ODFVs and commit to a development branch of the feature repository
25
-
4. Verify with `get_historical_features` (on a small dataset) that the transformation gives expected output over historical data
21
+
1. Call `get_historical_features` to generate a training dataset.
22
+
2. Iterate in a notebook and do your feature engineering using Pandas or native Python.
23
+
3. Copy transformation logic into ODFVs and commit to a development branch of the feature repository.
24
+
4. Verify with `get_historical_features` (on a small dataset) that the transformation gives the expected output over historical data.
26
25
5. Decide whether to apply the transformation on writes or on reads by setting the `write_to_online_store` parameter accordingly.
27
-
6. Verify with `get_online_features` on dev branch that the transformation correctly outputs online features
28
-
7. Submit a pull request to the staging / prod branches which impact production traffic
26
+
6. Verify with `get_online_features` on the development branch that the transformation correctly outputs online features.
27
+
7. Submit a pull request to the staging or production branches, impacting production traffic.
29
28
30
-
## CLI
29
+
## Transformation Modes
31
30
32
-
There are new CLI commands:
31
+
When defining an ODFV, you can specify the transformation mode using the `mode` parameter. Feast supports the following modes:
33
32
34
-
*`feast on-demand-feature-views list` lists all registered on demand feature view after `feast apply`is run
35
-
*`feast on-demand-feature-views describe [NAME]` describes the definition of an on demand feature view
33
+
-**Pandas Mode (`mode="pandas"`)**: The transformation function takes a Pandas DataFrame as input and returns a Pandas DataFrame as output. This mode is useful for batch transformations over multiple rows.
34
+
-**Native Python Mode (`mode="python"`)**: The transformation function uses native Python and can operate on inputs as lists of values or as single dictionaries representing a singleton (single row).
36
35
37
-
## Example
36
+
### Singleton Transformations in Native Python Mode
37
+
38
+
Native Python mode supports transformations on singleton dictionaries by setting `singleton=True`. This allows you to
39
+
write transformation functions that operate on a single row at a time, making the code more intuitive and aligning with
40
+
how data scientists typically think about data transformations.
38
41
42
+
## Example
39
43
See [https://github.com/feast-dev/on-demand-feature-views-demo](https://github.com/feast-dev/on-demand-feature-views-demo) for an example on how to use on demand feature views.
40
44
41
-
### **Registering transformations**
42
45
43
-
On Demand Transformations support transformations using Pandas and native Python. Note, Native Python is much faster
44
-
but not yet tested for offline retrieval.
46
+
## Registering Transformations
45
47
46
-
When defining an ODFV, you can control when the transformation is applied using the write_to_online_store parameter:
48
+
When defining an ODFV, you can control when the transformation is applied using the `write_to_online_store` parameter:
47
49
48
50
-`write_to_online_store=True`: The transformation is applied during data ingestion (on write), and the transformed features are stored in the online store.
49
-
-`write_to_online_store=False` (default when omitted): The transformation is applied during feature retrieval (on read).
51
+
-`write_to_online_store=False` (default): The transformation is applied during feature retrieval (on read).
50
52
51
-
We register `RequestSource` inputs and the transform in `on_demand_feature_view`:
53
+
### Examples
52
54
53
-
## Example of an On Demand Transformation on Read
55
+
####Example 1: On Demand Transformation on Read Using Pandas Mode
54
56
55
57
```python
56
-
from feast import Field, RequestSource
58
+
from feast import Field, RequestSource, on_demand_feature_view
57
59
from feast.types import Float64, Int64
58
-
from typing import Any, Dict
59
60
import pandas as pd
60
61
61
-
# Define a request data source which encodes features / information only
62
-
# available at request time (e.g. part of the user initiated HTTP request)
62
+
# Define a request data source for request-time features
63
63
input_request = RequestSource(
64
64
name="vals_to_add",
65
65
schema=[
66
-
Field(name='val_to_add', dtype=Int64),
67
-
Field(name='val_to_add_2', dtype=Int64)
68
-
]
66
+
Field(name="val_to_add", dtype=Int64),
67
+
Field(name="val_to_add_2", dtype=Int64),
68
+
],
69
69
)
70
70
71
-
# Use the input data and feature view features to create new features Pandas mode
71
+
# Use input data and feature view features to create new features in Pandas mode
## Example of an On Demand Transformation on Write
142
+
In this example, `inputs` is a dictionary representing a single row, and the transformation function returns a dictionary of transformed features for that single row. This approach is more intuitive and aligns with how data scientists typically process single data records.
143
+
144
+
#### Example 4: On Demand Transformation on Write Using Pandas Mode
120
145
121
146
```python
122
147
from feast import Field, on_demand_feature_view
@@ -126,22 +151,22 @@ import pandas as pd
126
151
# Existing Feature View
127
152
driver_hourly_stats_view =...
128
153
129
-
# Define an ODFV without RequestSource
154
+
# Define an ODFV applying transformation during write time
130
155
@on_demand_feature_view(
131
156
sources=[driver_hourly_stats_view],
132
157
schema=[
133
-
Field(name='conv_rate_adjusted', dtype=Float64),
158
+
Field(name="conv_rate_adjusted", dtype=Float64),
134
159
],
135
160
mode="pandas",
136
161
write_to_online_store=True, # Apply transformation during write time
0 commit comments