Makes a recommendation prediction.

Scopes

You will need authorization for the https://www.googleapis.com/auth/cloud-platform scope to make a valid call.

If unset, the scope for this method defaults to https://www.googleapis.com/auth/cloud-platform. You can set the scope for this method like this: retail2 --scope <scope> projects locations-catalogs-serving-configs-predict ...

Required Scalar Argument

  • <placement> (string)
    • Required. Full resource name of the format: {placement=projects/*/locations/global/catalogs/default_catalog/servingConfigs/*} or {placement=projects/*/locations/global/catalogs/default_catalog/placements/*}. We recommend using the servingConfigs resource. placements is a legacy resource. The ID of the Recommendations AI serving config or placement. Before you can request predictions from your model, you must create at least one serving config or placement for it. For more information, see [Manage serving configs] (https://cloud.google.com/retail/docs/manage-configs). The full list of available serving configs can be seen at https://console.cloud.google.com/ai/retail/catalogs/default_catalog/configs

Required Request Value

The request value is a data-structure with various fields. Each field may be a simple scalar or another data-structure. In the latter case it is advised to set the field-cursor to the data-structure's field to specify values more concisely.

For example, a structure like this:

GoogleCloudRetailV2PredictRequest:
  filter: string
  labels: { string: string }
  page-size: integer
  page-token: string
  user-event:
    attribution-token: string
    cart-id: string
    completion-detail:
      completion-attribution-token: string
      selected-position: integer
      selected-suggestion: string
    entity: string
    event-time: string
    event-type: string
    experiment-ids: [string]
    filter: string
    offset: integer
    order-by: string
    page-categories: [string]
    page-view-id: string
    purchase-transaction:
      cost: number
      currency-code: string
      id: string
      revenue: number
      tax: number
    referrer-uri: string
    search-query: string
    session-id: string
    uri: string
    user-info:
      direct-user-request: boolean
      ip-address: string
      user-agent: string
      user-id: string
    visitor-id: string
  validate-only: boolean

can be set completely with the following arguments which are assumed to be executed in the given order. Note how the cursor position is adjusted to the respective structures, allowing simple field names to be used most of the time.

  • -r . filter=amet.
    • Filter for restricting prediction results with a length limit of 5,000 characters. Accepts values for tags and the filterOutOfStockItems flag. * Tag expressions. Restricts predictions to products that match all of the specified tags. Boolean operators OR and NOT are supported if the expression is enclosed in parentheses, and must be separated from the tag values by a space. -&#34;tagA&#34; is also supported and is equivalent to NOT &#34;tagA&#34;. Tag values must be double quoted UTF-8 encoded strings with a size limit of 1,000 characters. Note: "Recently viewed" models don't support tag filtering at the moment. * filterOutOfStockItems. Restricts predictions to products that do not have a stockState value of OUT_OF_STOCK. Examples: * tag=("Red" OR "Blue") tag="New-Arrival" tag=(NOT "promotional") * filterOutOfStockItems tag=(-"promotional") * filterOutOfStockItems If your filter blocks all prediction results, the API will return no results. If instead you want empty result sets to return generic (unfiltered) popular products, set strictFiltering to False in PredictRequest.params. Note that the API will never return items with storageStatus of "EXPIRED" or "DELETED" regardless of filter choices. If filterSyntaxV2 is set to true under the params field, then attribute-based expressions are expected instead of the above described tag-based syntax. Examples: * (colors: ANY("Red", "Blue")) AND NOT (categories: ANY("Phones")) * (availability: ANY("IN_STOCK")) AND (colors: ANY("Red") OR categories: ANY("Phones")) For more information, see Filter recommendations.
  • labels=key=ipsum
    • The labels applied to a resource must meet the following requirements: * Each resource can have multiple labels, up to a maximum of 64. * Each label must be a key-value pair. * Keys have a minimum length of 1 character and a maximum length of 63 characters and cannot be empty. Values can be empty and have a maximum length of 63 characters. * Keys and values can contain only lowercase letters, numeric characters, underscores, and dashes. All characters must use UTF-8 encoding, and international characters are allowed. * The key portion of a label must be unique. However, you can use the same key with multiple resources. * Keys must start with a lowercase letter or international character. See Google Cloud Document for more details.
    • the value will be associated with the given key
  • page-size=74
    • Maximum number of results to return. Set this property to the number of prediction results needed. If zero, the service will choose a reasonable default. The maximum allowed value is 100. Values above 100 will be coerced to 100.
  • page-token=vero
    • This field is not used; leave it unset.
  • user-event attribution-token=takimata
    • Highly recommended for user events that are the result of PredictionService.Predict. This field enables accurate attribution of recommendation model performance. The value must be a valid PredictResponse.attribution_token for user events that are the result of PredictionService.Predict. The value must be a valid SearchResponse.attribution_token for user events that are the result of SearchService.Search. This token enables us to accurately attribute page view or purchase back to the event and the particular predict response containing this clicked/purchased product. If user clicks on product K in the recommendation results, pass PredictResponse.attribution_token as a URL parameter to product K's page. When recording events on product K's page, log the PredictResponse.attribution_token to this field.
  • cart-id=gubergren
    • The ID or name of the associated shopping cart. This ID is used to associate multiple items added or present in the cart before purchase. This can only be set for add-to-cart, purchase-complete, or shopping-cart-page-view events.
  • completion-detail completion-attribution-token=et
    • Completion attribution token in CompleteQueryResponse.attribution_token.
  • selected-position=13
    • End user selected CompleteQueryResponse.CompletionResult.suggestion position, starting from 0.
  • selected-suggestion=magna

    • End user selected CompleteQueryResponse.CompletionResult.suggestion.
  • .. entity=sit

    • The entity for customers that may run multiple different entities, domains, sites or regions, for example, Google US, Google Ads, Waymo, google.com, youtube.com, etc. We recommend that you set this field to get better per-entity search, completion, and prediction results.
  • event-time=gubergren
    • Only required for UserEventService.ImportUserEvents method. Timestamp of when the user event happened.
  • event-type=elitr
    • Required. User event type. Allowed values are: * add-to-cart: Products being added to cart. * category-page-view: Special pages such as sale or promotion pages viewed. * detail-page-view: Products detail page viewed. * home-page-view: Homepage viewed. * promotion-offered: Promotion is offered to a user. * promotion-not-offered: Promotion is not offered to a user. * purchase-complete: User finishing a purchase. * search: Product search. * shopping-cart-page-view: User viewing a shopping cart.
  • experiment-ids=ipsum
    • A list of identifiers for the independent experiment groups this user event belongs to. This is used to distinguish between user events associated with different experiment setups (e.g. using Retail API, using different recommendation models).
    • Each invocation of this argument appends the given value to the array.
  • filter=kasd
    • The filter syntax consists of an expression language for constructing a predicate from one or more fields of the products being filtered. See SearchRequest.filter for definition and syntax. The value must be a UTF-8 encoded string with a length limit of 1,000 characters. Otherwise, an INVALID_ARGUMENT error is returned.
  • offset=67
    • An integer that specifies the current offset for pagination (the 0-indexed starting location, amongst the products deemed by the API as relevant). See SearchRequest.offset for definition. If this field is negative, an INVALID_ARGUMENT is returned. This can only be set for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
  • order-by=lorem
    • The order in which products are returned. See SearchRequest.order_by for definition and syntax. The value must be a UTF-8 encoded string with a length limit of 1,000 characters. Otherwise, an INVALID_ARGUMENT error is returned. This can only be set for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
  • page-categories=amet
    • The categories associated with a category page. To represent full path of category, use '>' sign to separate different hierarchies. If '>' is part of the category name, replace it with other character(s). Category pages include special pages such as sales or promotions. For instance, a special sale page may have the category hierarchy: "pageCategories" : ["Sales > 2017 Black Friday Deals"]. Required for category-page-view events. At least one of search_query or page_categories is required for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
    • Each invocation of this argument appends the given value to the array.
  • page-view-id=ipsum
    • A unique ID of a web page view. This should be kept the same for all user events triggered from the same pageview. For example, an item detail page view could trigger multiple events as the user is browsing the page. The pageViewId property should be kept the same for all these events so that they can be grouped together properly. When using the client side event reporting with JavaScript pixel and Google Tag Manager, this value is filled in automatically.
  • purchase-transaction cost=0.00012161568028501435
    • All the costs associated with the products. These can be manufacturing costs, shipping expenses not borne by the end user, or any other costs, such that: * Profit = revenue - tax - cost
  • currency-code=dolores
    • Required. Currency code. Use three-character ISO-4217 code.
  • id=consetetur
    • The transaction ID with a length limit of 128 characters.
  • revenue=0.6783360959187912
    • Required. Total non-zero revenue or grand total associated with the transaction. This value include shipping, tax, or other adjustments to total revenue that you want to include as part of your revenue calculations.
  • tax=0.969930868104311

    • All the taxes associated with the transaction.
  • .. referrer-uri=takimata

    • The referrer URL of the current page. When using the client side event reporting with JavaScript pixel and Google Tag Manager, this value is filled in automatically.
  • search-query=sed
    • The user's search query. See SearchRequest.query for definition. The value must be a UTF-8 encoded string with a length limit of 5,000 characters. Otherwise, an INVALID_ARGUMENT error is returned. At least one of search_query or page_categories is required for search events. Other event types should not set this field. Otherwise, an INVALID_ARGUMENT error is returned.
  • session-id=nonumy
    • A unique identifier for tracking a visitor session with a length limit of 128 bytes. A session is an aggregation of an end user behavior in a time span. A general guideline to populate the sesion_id: 1. If user has no activity for 30 min, a new session_id should be assigned. 2. The session_id should be unique across users, suggest use uuid or add visitor_id as prefix.
  • uri=sea
    • Complete URL (window.location.href) of the user's current page. When using the client side event reporting with JavaScript pixel and Google Tag Manager, this value is filled in automatically. Maximum length 5,000 characters.
  • user-info direct-user-request=true
    • True if the request is made directly from the end user, in which case the ip_address and user_agent can be populated from the HTTP request. This flag should be set only if the API request is made directly from the end user such as a mobile app (and not if a gateway or a server is processing and pushing the user events). This should not be set when using the JavaScript tag in UserEventService.CollectUserEvent.
  • ip-address=sed
    • The end user's IP address. This field is used to extract location information for personalization. This field must be either an IPv4 address (e.g. "104.133.9.80") or an IPv6 address (e.g. "2001:0db8:85a3:0000:0000:8a2e:0370:7334"). Otherwise, an INVALID_ARGUMENT error is returned. This should not be set when: * setting SearchRequest.user_info. * using the JavaScript tag in UserEventService.CollectUserEvent or if direct_user_request is set.
  • user-agent=labore
    • User agent as included in the HTTP header. Required for getting SearchResponse.sponsored_results. The field must be a UTF-8 encoded string with a length limit of 1,000 characters. Otherwise, an INVALID_ARGUMENT error is returned. This should not be set when using the client side event reporting with GTM or JavaScript tag in UserEventService.CollectUserEvent or if direct_user_request is set.
  • user-id=et

    • Highly recommended for logged-in users. Unique identifier for logged-in user, such as a user name. Don't set for anonymous users. Always use a hashed value for this ID. Don't set the field to the same fixed ID for different users. This mixes the event history of those users together, which results in degraded model quality. The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned.
  • .. visitor-id=eirmod

    • Required. A unique identifier for tracking visitors. For example, this could be implemented with an HTTP cookie, which should be able to uniquely identify a visitor on a single device. This unique identifier should not change if the visitor log in/out of the website. Don't set the field to the same fixed ID for different users. This mixes the event history of those users together, which results in degraded model quality. The field must be a UTF-8 encoded string with a length limit of 128 characters. Otherwise, an INVALID_ARGUMENT error is returned. The field should not contain PII or user-data. We recommend to use Google Analytics Client ID for this field.
  • .. validate-only=true

    • Use validate only mode for this prediction query. If set to true, a dummy model will be used that returns arbitrary products. Note that the validate only mode should only be used for testing the API, or if the model is not ready.

About Cursors

The cursor position is key to comfortably set complex nested structures. The following rules apply:

  • The cursor position is always set relative to the current one, unless the field name starts with the . character. Fields can be nested such as in -r f.s.o .
  • The cursor position is set relative to the top-level structure if it starts with ., e.g. -r .s.s
  • You can also set nested fields without setting the cursor explicitly. For example, to set a value relative to the current cursor position, you would specify -r struct.sub_struct=bar.
  • You can move the cursor one level up by using ... Each additional . moves it up one additional level. E.g. ... would go three levels up.

Optional Output Flags

The method's return value a JSON encoded structure, which will be written to standard output by default.

  • -o out
    • out specifies the destination to which to write the server's result to. It will be a JSON-encoded structure. The destination may be - to indicate standard output, or a filepath that is to contain the received bytes. If unset, it defaults to standard output.

Optional General Properties

The following properties can configure any call, and are not specific to this method.

  • -p $-xgafv=string

    • V1 error format.
  • -p access-token=string

    • OAuth access token.
  • -p alt=string

    • Data format for response.
  • -p callback=string

    • JSONP
  • -p fields=string

    • Selector specifying which fields to include in a partial response.
  • -p key=string

    • API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.
  • -p oauth-token=string

    • OAuth 2.0 token for the current user.
  • -p pretty-print=boolean

    • Returns response with indentations and line breaks.
  • -p quota-user=string

    • Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.
  • -p upload-type=string

    • Legacy upload protocol for media (e.g. "media", "multipart").
  • -p upload-protocol=string

    • Upload protocol for media (e.g. "raw", "multipart").