Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into FSTORE-1436
Browse files Browse the repository at this point in the history
  • Loading branch information
davitbzh committed Nov 20, 2024
2 parents ac3eabf + ef383bc commit 7f7bef8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
38 changes: 36 additions & 2 deletions python/hsfs/core/vector_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def __init__(
self._feature_to_handle_if_sql: Optional[Set[str]] = None
self._valid_serving_keys: Set[str] = set()
self._serving_initialized: bool = False
self.__all_features_on_demand: Optional[bool] = None

def init_serving(
self,
Expand Down Expand Up @@ -415,14 +416,23 @@ def get_feature_vectors(
request_parameters is None
or len(request_parameters) == 0
or isinstance(request_parameters, dict)
or not entries
or len(request_parameters) == len(entries)
), "Request Parameters should be a Dictionary, None, empty or have the same length as the entries"
), "Request Parameters should be a Dictionary, None, empty or have the same length as the entries if they are not None or empty."

online_client_choice = self.which_client_and_ensure_initialised(
force_rest_client=force_rest_client, force_sql_client=force_sql_client
)
rondb_entries = []
skipped_empty_entries = []

if not entries:
entries = (
[[] * len(request_parameters)]
if isinstance(request_parameters, list)
else [[]]
)

for (idx, entry), passed, vector_features in itertools.zip_longest(
enumerate(entries),
passed_features,
Expand Down Expand Up @@ -547,7 +557,11 @@ def assemble_feature_vector(
# for backward compatibility, before 3.4, if result is empty,
# instead of throwing error, it skips the result
# Maybe we drop this behaviour for 4.0
if len(result_dict) == 0 and not allow_missing:
if (
len(result_dict) == 0
and not allow_missing
and not self._all_features_on_demand
):
return None

if not allow_missing and len(missing_features) > 0:
Expand Down Expand Up @@ -1255,6 +1269,17 @@ def validate_entry(
Keys relevant to vector_db are filtered out.
"""
_logger.debug(
"Checking if entry is None and all features in the feature view are on-demand."
)
if not entry:
if self._all_features_on_demand:
return {}
else:
raise exceptions.FeatureStoreException(
"The required argument `entries` is missing. If the feature view includes only on-demand features, entries may be left empty or set to None."
)

_logger.debug("Checking keys in entry are valid serving keys.")
for key in entry.keys():
if key not in self.valid_serving_keys:
Expand Down Expand Up @@ -1584,3 +1609,12 @@ def transformed_feature_vector_col_name(self):
]
self._transformed_feature_vector_col_name.extend(output_column_names)
return self._transformed_feature_vector_col_name

@property
def _all_features_on_demand(self) -> bool:
"""True if all features in the feature view are on-demand."""
if self.__all_features_on_demand is None:
self.__all_features_on_demand = all(
feature.on_demand_transformation_function for feature in self._features
)
return self.__all_features_on_demand
4 changes: 2 additions & 2 deletions python/hsfs/feature_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def get_batch_query(

def get_feature_vector(
self,
entry: Dict[str, Any],
entry: Optional[Dict[str, Any]] = None,
passed_features: Optional[Dict[str, Any]] = None,
external: Optional[bool] = None,
return_type: Literal["list", "polars", "numpy", "pandas"] = "list",
Expand Down Expand Up @@ -635,7 +635,7 @@ def get_feature_vector(

def get_feature_vectors(
self,
entry: List[Dict[str, Any]],
entry: Optional[List[Dict[str, Any]]] = None,
passed_features: Optional[List[Dict[str, Any]]] = None,
external: Optional[bool] = None,
return_type: Literal["list", "polars", "numpy", "pandas"] = "list",
Expand Down

0 comments on commit 7f7bef8

Please sign in to comment.