Ejemplo n.º 1
0
    def streaming_read_feature_values(
        self,
        request: Union[
            featurestore_online_service.StreamingReadFeatureValuesRequest,
            dict] = None,
        *,
        entity_type: str = None,
        retry: OptionalRetry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> Iterable[featurestore_online_service.ReadFeatureValuesResponse]:
        r"""Reads Feature values for multiple entities. Depending
        on their size, data for different entities may be broken
        up across multiple responses.


        .. code-block:: python

            from google.cloud import aiplatform_v1beta1

            def sample_streaming_read_feature_values():
                # Create a client
                client = aiplatform_v1beta1.FeaturestoreOnlineServingServiceClient()

                # Initialize request argument(s)
                feature_selector = aiplatform_v1beta1.FeatureSelector()
                feature_selector.id_matcher.ids = ['ids_value_1', 'ids_value_2']

                request = aiplatform_v1beta1.StreamingReadFeatureValuesRequest(
                    entity_type="entity_type_value",
                    entity_ids=['entity_ids_value_1', 'entity_ids_value_2'],
                    feature_selector=feature_selector,
                )

                # Make the request
                stream = client.streaming_read_feature_values(request=request)

                # Handle the response
                for response in stream:
                    print(response)

        Args:
            request (Union[google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest, dict]):
                The request object. Request message for
                [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][].
            entity_type (str):
                Required. The resource name of the entities' type. Value
                format:
                ``projects/{project}/locations/{location}/featurestores/{featurestore}/entityTypes/{entityType}``.
                For example, for a machine learning model predicting
                user clicks on a website, an EntityType ID could be
                ``user``.

                This corresponds to the ``entity_type`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            Iterable[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse]:
                Response message for
                [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.ReadFeatureValues].

        """
        # Create or coerce a protobuf request object.
        # Quick check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([entity_type])
        if request is not None and has_flattened_params:
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        # Minor optimization to avoid making a copy if the user passes
        # in a featurestore_online_service.StreamingReadFeatureValuesRequest.
        # There's no risk of modifying the input as we've already verified
        # there are no flattened fields.
        if not isinstance(
                request,
                featurestore_online_service.StreamingReadFeatureValuesRequest):
            request = featurestore_online_service.StreamingReadFeatureValuesRequest(
                request)
            # If we have keyword arguments corresponding to fields on the
            # request, apply these.
            if entity_type is not None:
                request.entity_type = entity_type

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = self._transport._wrapped_methods[
            self._transport.streaming_read_feature_values]

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("entity_type", request.entity_type), )), )

        # Send the request.
        response = rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # Done; return the response.
        return response
Ejemplo n.º 2
0
    def streaming_read_feature_values(
        self,
        request: featurestore_online_service.
        StreamingReadFeatureValuesRequest = None,
        *,
        entity_type: str = None,
        retry: retries.Retry = gapic_v1.method.DEFAULT,
        timeout: float = None,
        metadata: Sequence[Tuple[str, str]] = (),
    ) -> Awaitable[AsyncIterable[
            featurestore_online_service.ReadFeatureValuesResponse]]:
        r"""Reads Feature values for multiple entities. Depending
        on their size, data for different entities may be broken
        up across multiple responses.

        Args:
            request (:class:`google.cloud.aiplatform_v1beta1.types.StreamingReadFeatureValuesRequest`):
                The request object. Request message for
                [FeaturestoreOnlineServingService.StreamingFeatureValuesRead][].
            entity_type (:class:`str`):
                Required. The resource name of the entities' type. Value
                format:
                ``projects/{project}/locations/{location}/featurestores/ {featurestore}/entityTypes/{entityType}``.
                For example, for a machine learning model predicting
                user clicks on a website, an EntityType ID could be
                "user".

                This corresponds to the ``entity_type`` field
                on the ``request`` instance; if ``request`` is provided, this
                should not be set.
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.
            timeout (float): The timeout for this request.
            metadata (Sequence[Tuple[str, str]]): Strings which should be
                sent along with the request as metadata.

        Returns:
            AsyncIterable[google.cloud.aiplatform_v1beta1.types.ReadFeatureValuesResponse]:
                Response message for
                [FeaturestoreOnlineServingService.ReadFeatureValues][google.cloud.aiplatform.v1beta1.FeaturestoreOnlineServingService.ReadFeatureValues].

        """
        # Create or coerce a protobuf request object.
        # Sanity check: If we got a request object, we should *not* have
        # gotten any keyword arguments that map to the request.
        has_flattened_params = any([entity_type])
        if request is not None and has_flattened_params:
            raise ValueError("If the `request` argument is set, then none of "
                             "the individual field arguments should be set.")

        request = featurestore_online_service.StreamingReadFeatureValuesRequest(
            request)

        # If we have keyword arguments corresponding to fields on the
        # request, apply these.
        if entity_type is not None:
            request.entity_type = entity_type

        # Wrap the RPC method; this adds retry and timeout information,
        # and friendly error handling.
        rpc = gapic_v1.method_async.wrap_method(
            self._client._transport.streaming_read_feature_values,
            default_timeout=5.0,
            client_info=DEFAULT_CLIENT_INFO,
        )

        # Certain fields should be provided within the metadata header;
        # add these here.
        metadata = tuple(metadata) + (gapic_v1.routing_header.to_grpc_metadata(
            (("entity_type", request.entity_type), )), )

        # Send the request.
        response = rpc(
            request,
            retry=retry,
            timeout=timeout,
            metadata=metadata,
        )

        # Done; return the response.
        return response