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

[FSTORE-1682] Change default behaviour of get_feature_vector to return on-demand features by default #447

Merged
merged 3 commits into from
Feb 13, 2025
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
99 changes: 76 additions & 23 deletions docs/user_guides/fs/feature_group/on_demand_transformations.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,13 @@ The `get_feature_vector` function retrieves a single feature vector based on the
=== "Python"
!!! example "Computing on-demand features while retrieving a feature vector"
```python

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()})
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(),
},
)
```

#### Retrieving feature vectors
Expand All @@ -114,24 +119,44 @@ The `get_feature_vectors` function retrieves multiple feature vectors using a li
=== "Python"
!!! example "Computing on-demand features while retrieving a feature vectors"
```python

# Specify unique request parameters for each serving key.
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()},
{"transaction_time":datetime(2022, 11, 20, 12, 50, 00), "current_time":datetime.now()}])
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(),
},
{
"transaction_time": datetime(2022, 11, 20, 12, 50, 00),
"current_time": datetime.now(),
},
],
)

# Specify common request parameters for all serving key.
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()})
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(),
},
)
```

The `get_feature_vector` and `get_feature_vectors` can also return untransformed features by setting the parameter `transform` to `False`.
#### Retrieving feature vector without on-demand features

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`.

=== "Python"
!!! example "Returning untransformed feature vectors"
```python

untransformed_feature_vector = feature_view.get_feature_vector(entry={"id":1}, transform=False)

untransformed_feature_vectors = feature_view.get_feature_vectors(entry=[{"id":1}, {"id":2}], transform=False)
untransformed_feature_vector = feature_view.get_feature_vector(
entry={"id": 1}, transform=False, on_demand_features=False
)
untransformed_feature_vectors = feature_view.get_feature_vectors(
entry=[{"id": 1}, {"id": 2}], transform=False, on_demand_features=False
)
```

#### Compute all on-demand features
Expand All @@ -143,27 +168,51 @@ The `request_parameter` in this case, can be a list of dictionaries that specifi
=== "Python"
!!! example "Computing all on-demand features and manually applying model dependent transformations."
```python

# Specify request parameters for each serving key.
untransformed_feature_vector = feature_view.get_feature_vector(entry={"id":1}, transform=False)
untransformed_feature_vector = feature_view.get_feature_vector(
entry={"id": 1}, transform=False, on_demand_features=False
)

# re-compute and add on-demand features to the feature vector
feature_vector_with_on_demand_features = fv.compute_on_demand_features(untransformed_feature_vector,
request_parameter={"transaction_time":datetime(2022, 12, 28, 23, 55, 59), "current_time":datetime.now()})
feature_vector_with_on_demand_features = fv.compute_on_demand_features(
untransformed_feature_vector,
request_parameter={
"transaction_time": datetime(2022, 12, 28, 23, 55, 59),
"current_time": datetime.now(),
},
)

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

# Specify request parameters for each serving key.
untransformed_feature_vectors = feature_view.get_feature_vectors(entry=[{"id":1}, {"id":2}], transform=False)
untransformed_feature_vectors = feature_view.get_feature_vectors(
entry=[{"id": 1}, {"id": 2}], transform=False, on_demand_features=False
)

# re-compute and add on-demand features to the feature vectors - Specify unique request parameter for each feature vector
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()},
{"transaction_time":datetime(2022, 11, 20, 12, 50, 00), "current_time":datetime.now()}])
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(),
},
{
"transaction_time": datetime(2022, 11, 20, 12, 50, 00),
"current_time": datetime.now(),
},
],
)

# re-compute and add on-demand feature to the feature vectors - Specify common request parameter for all feature vectors
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()})
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(),
},
)

# Applying model dependent transformations
encoded_feature_vector = fv.transform(feature_vectors_with_on_demand_features)
Expand All @@ -177,10 +226,14 @@ On-demand transformation functions can also be accessed and executed as normal f
=== "Python"
!!! example "Executing each on-demand transformation function"
```python

# Specify request parameters for each serving key.
feature_vector = feature_view.get_feature_vector(entry={"id":1}, transform=False, return_type="pandas")
feature_vector = feature_view.get_feature_vector(
entry={"id": 1}, transform=False, on_demand_features=False, return_type="pandas"
)

# Applying model dependent transformations
feature_vector["on_demand_feature1"] = fv.on_demand_transformations["on_demand_feature1"](feature_vector["transaction_time"], datetime.now())
feature_vector["on_demand_feature1"] = fv.on_demand_transformations[
"on_demand_feature1"
](feature_vector["transaction_time"], datetime.now())

```
11 changes: 11 additions & 0 deletions docs/user_guides/fs/feature_view/batch-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ feature_view.init_batch_scoring(training_dataset_version=1)

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.

## Retrieving untransformed batch data

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`.

=== "Python"
!!! example "Returning untransformed batch data"
```python
# Fetching untransformed batch data.
untransformed_batch_data = feature_view.get_batch_data(transform=False)
```


## Passing Context Variables to Transformation Functions
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.
Expand Down
35 changes: 35 additions & 0 deletions docs/user_guides/fs/feature_view/feature-vectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,41 @@ You can also use the parameter to provide values for all the features which are
)
```

## Retrieving untransformed feature vectors

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.

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.

=== "Python"
!!! example "Returning untransformed feature vectors"
```python
# Fetching untransformed feature vector.
untransformed_feature_vector = feature_view.get_feature_vector(
entry={"id": 1}, transform=False
)

# Fetching untransformed feature vectors.
untransformed_feature_vectors = feature_view.get_feature_vectors(
entry=[{"id": 1}, {"id": 2}], transform=False
)
```

## Retrieving feature vector without on-demand features

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`.

=== "Python"
!!! example "Returning untransformed feature vectors"
```python
untransformed_feature_vector = feature_view.get_feature_vector(
entry={"id": 1}, transform=False, on_demand_features=False
)
untransformed_feature_vectors = feature_view.get_feature_vectors(
entry=[{"id": 1}, {"id": 2}], transform=False, on_demand_features=False
)
```

## Passing Context Variables to Transformation Functions
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.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,32 @@ Model-dependent transformation functions can also be manually applied to a featu
fv.init_serving(training_dataset_version)

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

# Apply Model Dependent transformations
encode_feature_vector = fv.transform(feature_vector)
encoded_feature_vector = fv.transform(feature_vector)
```

#### Retrieving untransformed feature vector and batch inference data

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.

=== "Python"
!!! example "Returning untransformed feature vectors and batch data."
```python
# Fetching untransformed feature vector.
untransformed_feature_vector = feature_view.get_feature_vector(
entry={"id": 1}, transform=False
)

# Fetching untransformed feature vectors.
untransformed_feature_vectors = feature_view.get_feature_vectors(
entry=[{"id": 1}, {"id": 2}], transform=False
)

# Fetching untransformed batch data.
untransformed_batch_data = feature_view.get_batch_data(
transform=False
)
```