Skip to content

Commit 19e0612

Browse files
authored
[FSTORE-1682] Change default behaviour of get_feature_vector to return on-demand features by default (logicalclocks#447)
* reformatting code with black and correcting snippets * adding documentation for the parameters transform and on-demand features * adding documentation for the parameters transform and on-demand features
1 parent 98b71c9 commit 19e0612

File tree

4 files changed

+147
-25
lines changed

4 files changed

+147
-25
lines changed

docs/user_guides/fs/feature_group/on_demand_transformations.md

Lines changed: 76 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ The `get_feature_vector` function retrieves a single feature vector based on the
103103
=== "Python"
104104
!!! example "Computing on-demand features while retrieving a feature vector"
105105
```python
106-
107-
feature_vector = feature_view.get_feature_vector(entry={"id":1}, request_parameter={"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()})
106+
feature_vector = feature_view.get_feature_vector(
107+
entry={"id": 1},
108+
request_parameter={
109+
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
110+
"current_time": datetime.now(),
111+
},
112+
)
108113
```
109114

110115
#### Retrieving feature vectors
@@ -114,24 +119,44 @@ The `get_feature_vectors` function retrieves multiple feature vectors using a li
114119
=== "Python"
115120
!!! example "Computing on-demand features while retrieving a feature vectors"
116121
```python
117-
118122
# Specify unique request parameters for each serving key.
119-
feature_vector = feature_view.get_feature_vectors(entry=[{"id":1}, {"id":2}], request_parameter=[{"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()},
120-
{"transaction_time":datetime(2022, 11, 20, 12, 50, 00), "current_time":datetime.now()}])
123+
feature_vector = feature_view.get_feature_vectors(
124+
entry=[{"id": 1}, {"id": 2}],
125+
request_parameter=[
126+
{
127+
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
128+
"current_time": datetime.now(),
129+
},
130+
{
131+
"transaction_time": datetime(2022, 11, 20, 12, 50, 00),
132+
"current_time": datetime.now(),
133+
},
134+
],
135+
)
121136

122137
# Specify common request parameters for all serving key.
123-
feature_vector = feature_view.get_feature_vectors(entry=[{"id":1}, {"id":2}], request_parameter={"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()})
138+
feature_vector = feature_view.get_feature_vectors(
139+
entry=[{"id": 1}, {"id": 2}],
140+
request_parameter={
141+
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
142+
"current_time": datetime.now(),
143+
},
144+
)
124145
```
125146

126-
The `get_feature_vector` and `get_feature_vectors` can also return untransformed features by setting the parameter `transform` to `False`.
147+
#### Retrieving feature vector without on-demand features
148+
149+
The `get_feature_vector` and `get_feature_vectors` methods can return untransformed feature vectors without on-demand features by disabling model-dependent transformations and excluding on-demand features. To achieve this, set the parameters `transform` and `on_demand_features` to `False`.
127150

128151
=== "Python"
129152
!!! example "Returning untransformed feature vectors"
130153
```python
131-
132-
untransformed_feature_vector = feature_view.get_feature_vector(entry={"id":1}, transform=False)
133-
134-
untransformed_feature_vectors = feature_view.get_feature_vectors(entry=[{"id":1}, {"id":2}], transform=False)
154+
untransformed_feature_vector = feature_view.get_feature_vector(
155+
entry={"id": 1}, transform=False, on_demand_features=False
156+
)
157+
untransformed_feature_vectors = feature_view.get_feature_vectors(
158+
entry=[{"id": 1}, {"id": 2}], transform=False, on_demand_features=False
159+
)
135160
```
136161

137162
#### Compute all on-demand features
@@ -143,27 +168,51 @@ The `request_parameter` in this case, can be a list of dictionaries that specifi
143168
=== "Python"
144169
!!! example "Computing all on-demand features and manually applying model dependent transformations."
145170
```python
146-
147171
# Specify request parameters for each serving key.
148-
untransformed_feature_vector = feature_view.get_feature_vector(entry={"id":1}, transform=False)
172+
untransformed_feature_vector = feature_view.get_feature_vector(
173+
entry={"id": 1}, transform=False, on_demand_features=False
174+
)
149175

150176
# re-compute and add on-demand features to the feature vector
151-
feature_vector_with_on_demand_features = fv.compute_on_demand_features(untransformed_feature_vector,
152-
request_parameter={"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()})
177+
feature_vector_with_on_demand_features = fv.compute_on_demand_features(
178+
untransformed_feature_vector,
179+
request_parameter={
180+
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
181+
"current_time": datetime.now(),
182+
},
183+
)
153184

154185
# Applying model dependent transformations
155186
encoded_feature_vector = fv.transform(feature_vector_with_on_demand_features)
156187

157188
# Specify request parameters for each serving key.
158-
untransformed_feature_vectors = feature_view.get_feature_vectors(entry=[{"id":1}, {"id":2}], transform=False)
189+
untransformed_feature_vectors = feature_view.get_feature_vectors(
190+
entry=[{"id": 1}, {"id": 2}], transform=False, on_demand_features=False
191+
)
159192

160193
# re-compute and add on-demand features to the feature vectors - Specify unique request parameter for each feature vector
161-
feature_vectors_with_on_demand_features = fv.compute_on_demand_features(untransformed_feature_vectors,
162-
request_parameter=[{"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()},
163-
{"transaction_time":datetime(2022, 11, 20, 12, 50, 00), "current_time":datetime.now()}])
194+
feature_vectors_with_on_demand_features = fv.compute_on_demand_features(
195+
untransformed_feature_vectors,
196+
request_parameter=[
197+
{
198+
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
199+
"current_time": datetime.now(),
200+
},
201+
{
202+
"transaction_time": datetime(2022, 11, 20, 12, 50, 00),
203+
"current_time": datetime.now(),
204+
},
205+
],
206+
)
164207

165208
# re-compute and add on-demand feature to the feature vectors - Specify common request parameter for all feature vectors
166-
feature_vectors_with_on_demand_features = fv.compute_on_demand_features(untransformed_feature_vectors, request_parameter={"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()})
209+
feature_vectors_with_on_demand_features = fv.compute_on_demand_features(
210+
untransformed_feature_vectors,
211+
request_parameter={
212+
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
213+
"current_time": datetime.now(),
214+
},
215+
)
167216

168217
# Applying model dependent transformations
169218
encoded_feature_vector = fv.transform(feature_vectors_with_on_demand_features)
@@ -177,10 +226,14 @@ On-demand transformation functions can also be accessed and executed as normal f
177226
=== "Python"
178227
!!! example "Executing each on-demand transformation function"
179228
```python
180-
181229
# Specify request parameters for each serving key.
182-
feature_vector = feature_view.get_feature_vector(entry={"id":1}, transform=False, return_type="pandas")
230+
feature_vector = feature_view.get_feature_vector(
231+
entry={"id": 1}, transform=False, on_demand_features=False, return_type="pandas"
232+
)
183233

184234
# Applying model dependent transformations
185-
feature_vector["on_demand_feature1"] = fv.on_demand_transformations["on_demand_feature1"](feature_vector["transaction_time"], datetime.now())
235+
feature_vector["on_demand_feature1"] = fv.on_demand_transformations[
236+
"on_demand_feature1"
237+
](feature_vector["transaction_time"], datetime.now())
238+
186239
```

docs/user_guides/fs/feature_view/batch-data.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ feature_view.init_batch_scoring(training_dataset_version=1)
5555

5656
It is important to note that in addition to the filters defined in feature view, [extra filters](./training-data.md#Extra-filters) will be applied if they are defined in the given training dataset version.
5757

58+
## Retrieving untransformed batch data
59+
60+
By default, the `get_batch_data` function returns batch data with model-dependent transformations applied. However, you can retrieve untransformed batch data—while still including on-demand features—by setting the `transform` parameter to `False`.
61+
62+
=== "Python"
63+
!!! example "Returning untransformed batch data"
64+
```python
65+
# Fetching untransformed batch data.
66+
untransformed_batch_data = feature_view.get_batch_data(transform=False)
67+
```
68+
5869

5970
## Passing Context Variables to Transformation Functions
6071
After [defining a transformation function using a context variable](../transformation_functions.md#passing-context-variables-to-transformation-function), you can pass the necessary context variables through the `transformation_context` parameter when fetching batch data.

docs/user_guides/fs/feature_view/feature-vectors.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,41 @@ You can also use the parameter to provide values for all the features which are
191191
)
192192
```
193193

194+
## Retrieving untransformed feature vectors
195+
196+
By default, the `get_feature_vector` and `get_feature_vectors` functions return transformed feature vectors, which has model-dependent transformations applied and includes on-demand features.
197+
198+
However, you can retrieve the untransformed feature vectors without applying model-dependent transformations while still including on-demand features by setting the `transform` parameter to False.
199+
200+
=== "Python"
201+
!!! example "Returning untransformed feature vectors"
202+
```python
203+
# Fetching untransformed feature vector.
204+
untransformed_feature_vector = feature_view.get_feature_vector(
205+
entry={"id": 1}, transform=False
206+
)
207+
208+
# Fetching untransformed feature vectors.
209+
untransformed_feature_vectors = feature_view.get_feature_vectors(
210+
entry=[{"id": 1}, {"id": 2}], transform=False
211+
)
212+
```
213+
214+
## Retrieving feature vector without on-demand features
215+
216+
The `get_feature_vector` and `get_feature_vectors` methods can also return untransformed feature vectors without on-demand features by disabling model-dependent transformations and excluding on-demand features. To achieve this, set the parameters `transform` and `on_demand_features` to `False`.
217+
218+
=== "Python"
219+
!!! example "Returning untransformed feature vectors"
220+
```python
221+
untransformed_feature_vector = feature_view.get_feature_vector(
222+
entry={"id": 1}, transform=False, on_demand_features=False
223+
)
224+
untransformed_feature_vectors = feature_view.get_feature_vectors(
225+
entry=[{"id": 1}, {"id": 2}], transform=False, on_demand_features=False
226+
)
227+
```
228+
194229
## Passing Context Variables to Transformation Functions
195230
After [defining a transformation function using a context variable](../transformation_functions.md#passing-context-variables-to-transformation-function), you can pass the required context variables using the `transformation_context` parameter when fetching the feature vectors.
196231

docs/user_guides/fs/feature_view/model-dependent-transformations.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,32 @@ Model-dependent transformation functions can also be manually applied to a featu
123123
fv.init_serving(training_dataset_version)
124124

125125
# Get untransformed feature Vector
126-
feature_vector = fv.get_feature_vector(entry={"index":10}, transformed=False, return_type="pandas")
126+
feature_vector = fv.get_feature_vector(entry={"index":10}, transform=False, return_type="pandas")
127127

128128
# Apply Model Dependent transformations
129-
encode_feature_vector = fv.transform(feature_vector)
129+
encoded_feature_vector = fv.transform(feature_vector)
130130
```
131131

132+
#### Retrieving untransformed feature vector and batch inference data
133+
134+
The `get_feature_vector`, `get_feature_vectors`, and `get_batch_data` methods can return untransformed feature vectors and batch data without applying model-dependent transformations while still including on-demand features. To achieve this, set the `transform` parameter to False.
135+
136+
=== "Python"
137+
!!! example "Returning untransformed feature vectors and batch data."
138+
```python
139+
# Fetching untransformed feature vector.
140+
untransformed_feature_vector = feature_view.get_feature_vector(
141+
entry={"id": 1}, transform=False
142+
)
143+
144+
# Fetching untransformed feature vectors.
145+
untransformed_feature_vectors = feature_view.get_feature_vectors(
146+
entry=[{"id": 1}, {"id": 2}], transform=False
147+
)
148+
149+
# Fetching untransformed batch data.
150+
untransformed_batch_data = feature_view.get_batch_data(
151+
transform=False
152+
)
153+
```
154+

0 commit comments

Comments
 (0)