Beispiel #1
0
    def to_dict(self) -> Dict[str, Any]:
        """
        Converts GetOnlineFeaturesResponse features into a dictionary form.
        """
        fields = [k for row in self.field_values for k, _ in row.fields.items()]
        features_dict: Dict[str, List[Any]] = {k: list() for k in fields}

        for row in self.field_values:
            for feature in features_dict.keys():
                native_type_value = feast_value_type_to_python_type(row.fields[feature])
                features_dict[feature].append(native_type_value)

        return features_dict
Beispiel #2
0
    def to_dict(self) -> Dict[str, Any]:
        """
        Converts GetOnlineFeaturesResponse features into a dictionary form.
        """
        response: Dict[str, List[Any]] = {}

        for result in self.proto.results:
            for idx, feature_ref in enumerate(
                    self.proto.metadata.feature_names.val):
                native_type_value = feast_value_type_to_python_type(
                    result.values[idx])
                if feature_ref not in response:
                    response[feature_ref] = [native_type_value]
                else:
                    response[feature_ref].append(native_type_value)

        return response
Beispiel #3
0
    async def get_online_features(request: Request):
        try:
            # Validate and parse the request data into GetOnlineFeaturesRequest Protobuf object
            body = await request.body()
            request_proto = GetOnlineFeaturesRequest()
            Parse(body, request_proto)

            # Initialize parameters for FeatureStore.get_online_features(...) call
            if request_proto.HasField("feature_service"):
                features = store.get_feature_service(
                    request_proto.feature_service)
            else:
                features = list(request_proto.features.val)

            full_feature_names = request_proto.full_feature_names

            batch_sizes = [len(v.val) for v in request_proto.entities.values()]
            num_entities = batch_sizes[0]
            if any(batch_size != num_entities for batch_size in batch_sizes):
                raise HTTPException(status_code=500,
                                    detail="Uneven number of columns")

            entity_rows = [{
                k: feast_value_type_to_python_type(v.val[idx])
                for k, v in request_proto.entities.items()
            } for idx in range(num_entities)]

            response_proto = store.get_online_features(
                features, entity_rows,
                full_feature_names=full_feature_names).proto

            # Convert the Protobuf object to JSON and return it
            return MessageToDict(  # type: ignore
                response_proto,
                preserving_proto_field_name=True,
                float_precision=18)
        except Exception as e:
            # Print the original exception on the server side
            logger.exception(e)
            # Raise HTTPException to return the error message to the client
            raise HTTPException(status_code=500, detail=str(e))
Beispiel #4
0
    def to_dict(self,
                include_event_timestamps: bool = False) -> Dict[str, Any]:
        """
        Converts GetOnlineFeaturesResponse features into a dictionary form.

        Args:
        is_with_event_timestamps: bool Optionally include feature timestamps in the dictionary
        """
        response: Dict[str, List[Any]] = {}

        for feature_ref, feature_vector in zip(
                self.proto.metadata.feature_names.val, self.proto.results):
            response[feature_ref] = [
                feast_value_type_to_python_type(v)
                for v in feature_vector.values
            ]

            if include_event_timestamps:
                timestamp_ref = feature_ref + TIMESTAMP_POSTFIX
                response[timestamp_ref] = [
                    ts.seconds for ts in feature_vector.event_timestamps
                ]

        return response