Skip to content

Commit

Permalink
Minor fix doc and test
Browse files Browse the repository at this point in the history
  • Loading branch information
vatj committed Feb 26, 2024
1 parent 0bd9c10 commit e5bdf62
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
35 changes: 20 additions & 15 deletions python/hsfs/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,29 +241,19 @@ def init_serving(
!!! example
```python
# get feature store instance
fs = ...
# get feature view instance
feature_view = fs.get_feature_view(...)
# initialise feature view to retrieve a feature vector using the RonDB REST http client
feature_view.init_serving(
training_dataset_version=1,
init_online_store_rest_client=True,
)
```
Reset the Online Store REST Client connection to fix configuration options:
You can reset the Online Store REST Client connection to fix configuration options. In particular, if you have
called `get_feature_vector` or `get_feature_vectors` without first initialising the client, it results in a default configuration
being set for the rest client. This will reset the client and apply the new configuration options.
!!! example
```python
# get feature store instance
fs = ...
# get feature view instance
feature_view = fs.get_feature_view(...)
# reset the RonDB REST http client connection
feature_view.init_serving(
training_dataset_version=1,
Expand All @@ -272,6 +262,21 @@ def init_serving(
)
```
Note that both the SQL connector and the REST client can be initialised at the same time. This is useful if you want to
fallback on one connector if the other fails.
!!! example
```python
# initialise feature view to retrieve a feature vector using both the SQL connector and the RonDB REST http client
feature_view.init_serving(
training_dataset_version=1,
init_online_store_sql_client=True,
init_online_store_rest_client=True,
)
# When initialising both clients, the SQL connector will be used by default. Change the default client using `set_default_online_client`.
feature_view.set_default_online_client("rest")
```
# Arguments
training_dataset_version: int, optional. Default to be 1 for online feature store.
Transformation statistics are fetched from training dataset and applied to the feature vector.
Expand All @@ -282,15 +287,15 @@ def init_serving(
Defaults to True if connection to Hopsworks is established from external environment (e.g AWS
Sagemaker or Google Colab), otherwise to False.
init_online_store_sql_client: bool, optional. If set to True, initialise the SQL client to retrieve feature vector(s)
from the online feature store. Defaults to True if init_online_.
from the online feature store. Defaults to True if init_online_store_rest_client is False, otherwise False.
init_online_store_rest_client: bool, optional. If set to True, initialise the Online Store REST Client to retrieve
feature vector(s) from the online feature store. Defaults to False, meaning the sql client will be initialised.
options: Additional options as key/value pairs for configuring online serving engine.
* key: kwargs of SqlAlchemy engine creation (See: https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine).
For example: `{"pool_size": 10}`
* key: "config_online_store_rest_client" - dict, optional. Optional configuration options to override defaults for the Online Store REST Client.
* key: "reset_online_store_rest_client" - bool, optional. If set to True, the Online Store REST Client will be reset. Provide
`config_online_store_rest_client` to override defaults.
"config_online_store_rest_client" to override defaults.
"""
# initiate batch scoring server
# `training_dataset_version` should not be set if `None` otherwise backend will look up the td.
Expand Down
10 changes: 4 additions & 6 deletions python/tests/core/test_vector_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ def test_rest_client_config_on_serving(
inference_helper_columns=True,
init_online_store_sql_client=False,
init_online_store_rest_client=True,
options={"online_store_rest_config": optional_config},
options={"config_online_store_rest_client": optional_config},
)
batch_server.init_serving(
entity=fv,
Expand All @@ -238,7 +238,7 @@ def test_rest_client_config_on_serving(
inference_helper_columns=True,
init_online_store_sql_client=False,
init_online_store_rest_client=True,
options={"online_store_rest_config": optional_config},
options={"config_online_store_rest_client": optional_config},
)

print(init_online_store_rest_client.call_args_list)
Expand All @@ -256,12 +256,10 @@ def test_rest_client_config_on_serving(
== optional_config
)
assert (
init_online_store_rest_client.call_args_list[0][1]["reset_connection"]
is False
init_online_store_rest_client.call_args_list[0][1]["reset_client"] is False
)
assert (
init_online_store_rest_client.call_args_list[1][1]["reset_connection"]
is False
init_online_store_rest_client.call_args_list[1][1]["reset_client"] is False
)

def test_reset_connection(
Expand Down

0 comments on commit e5bdf62

Please sign in to comment.