Method: projects.locations.catalogs.eventStores.placements.predict

Makes a recommendation prediction. If using API Key based authentication, the API Key must be registered using the PredictionApiKeyRegistry service. Learn more.

HTTP request

POST https://recommendationengine.googleapis.com/v1beta1/{name=projects/*/locations/*/catalogs/*/eventStores/*/placements/*}:predict

The URL uses gRPC Transcoding syntax.

Path parameters

Parameters
name

string

Required. Full resource name of the format: {name=projects/*/locations/global/catalogs/default_catalog/eventStores/default_event_store/placements/*} The id of the recommendation engine placement. This id is used to identify the set of models that will be used to make the prediction.

We currently support three placements with the following IDs by default:

  • shopping_cart: Predicts items frequently bought together with one or more catalog items in the same shopping session. Commonly displayed after add-to-cart events, on product detail pages, or on the shopping cart page.

  • home_page: Predicts the next product that a user will most likely engage with or purchase based on the shopping or viewing history of the specified userId or visitorId. For example - Recommendations for you.

  • product_detail: Predicts the next product that a user will most likely engage with or purchase. The prediction is based on the shopping or viewing history of the specified userId or visitorId and its relevance to a specified CatalogItem. Typically used on product detail pages. For example - More items like this.

  • recently_viewed_default: Returns up to 75 items recently viewed by the specified userId or visitorId, most recent ones first. Returns nothing if neither of them has viewed any items yet. For example - Recently viewed.

The full list of available placements can be seen at https://console.cloud.google.com/recommendation/datafeeds/default_catalog/dashboard

Request body

The request body contains data with the following structure:

JSON representation
{
  "userEvent": {
    object (UserEvent)
  },
  "pageSize": integer,
  "pageToken": string,
  "filter": string,
  "dryRun": boolean,
  "params": {
    string: value,
    ...
  },
  "labels": {
    string: string,
    ...
  }
}
Fields
userEvent

object (UserEvent)

Required. Context about the user, what they are looking at and what action they took to trigger the predict request. Note that this user event detail won't be ingested to userEvent logs. Thus, a separate userEvent write request is required for event logging.

pageSize

integer

Optional. Maximum number of results to return per page. Set this property to the number of prediction results required. If zero, the service will choose a reasonable default.

pageToken

string

Optional. The previous PredictResponse.next_page_token.

filter

string

Optional. Filter for restricting prediction results. Accepts values for tags and the filterOutOfStockItems flag.

  • Tag expressions. Restricts predictions to items 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. -"tagA" is also supported and is equivalent to NOT "tagA". Tag values must be double quoted UTF-8 encoded strings with a size limit of 1 KiB.

  • filterOutOfStockItems. Restricts predictions to items 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, nothing will be returned. If you want generic (unfiltered) popular items to be returned instead, set strictFiltering to false in PredictRequest.params.

dryRun

boolean

Optional. Use dryRun mode for this prediction query. If set to true, a fake model will be used that returns arbitrary catalog items. Note that the dryRun mode should only be used for testing the API, or if the model is not ready.

params

map (key: string, value: value (Value format))

Optional. Additional domain specific parameters for the predictions.

Allowed values:

  • returnCatalogItem: Boolean. If set to true, the associated catalogItem object will be returned in the PredictResponse.PredictionResult.itemMetadata object in the method response.
  • returnItemScore: Boolean. If set to true, the prediction 'score' corresponding to each returned item will be set in the metadata field in the prediction response. The given 'score' indicates the probability of an item being clicked/purchased given the user's context and history.
  • strictFiltering: Boolean. True by default. If set to false, the service will return generic (unfiltered) popular items instead of empty if your filter blocks all prediction results.
  • priceRerankLevel: String. Default empty. If set to be non-empty, then it needs to be one of {'no-price-reranking', 'low-price-reranking', 'medium-price-reranking', 'high-price-reranking'}. This gives request level control and adjust prediction results based on product price.
  • diversityLevel: String. Default empty. If set to be non-empty, then it needs to be one of {'no-diversity', 'low-diversity', 'medium-diversity', 'high-diversity', 'auto-diversity'}. This gives request level control and adjust prediction results based on product category.
labels

map (key: string, value: string)

Optional. The labels for the predict request.

  • Label keys can contain lowercase letters, digits and hyphens, must start with a letter, and must end with a letter or digit.
  • Non-zero label values can contain lowercase letters, digits and hyphens, must start with a letter, and must end with a letter or digit.
  • No more than 64 labels can be associated with a given request.

See https://goo.gl/xmQnxf for more information on and examples of labels.

Response body

If successful, the response body contains data with the following structure:

Response message for predict method.

JSON representation
{
  "results": [
    {
      object (PredictionResult)
    }
  ],
  "recommendationToken": string,
  "itemsMissingInCatalog": [
    string
  ],
  "dryRun": boolean,
  "metadata": {
    string: value,
    ...
  },
  "nextPageToken": string
}
Fields
results[]

object (PredictionResult)

A list of recommended items. The order represents the ranking (from the most relevant item to the least).

recommendationToken

string

A unique recommendation token. This should be included in the user event logs resulting from this recommendation, which enables accurate attribution of recommendation model performance.

itemsMissingInCatalog[]

string

IDs of items in the request that were missing from the catalog.

dryRun

boolean

True if the dryRun property was set in the request.

metadata

map (key: string, value: value (Value format))

Additional domain specific prediction response metadata.

nextPageToken

string

If empty, the list is complete. If nonempty, the token to pass to the next request's PredictRequest.page_token.

Authorization Scopes

Requires the following OAuth scope:

  • https://www.googleapis.com/auth/cloud-platform

For more information, see the Authentication Overview.

PredictionResult

PredictionResult represents the recommendation prediction results.

JSON representation
{
  "id": string,
  "itemMetadata": {
    string: value,
    ...
  }
}
Fields
id

string

ID of the recommended catalog item

itemMetadata

map (key: string, value: value (Value format))

Additional item metadata / annotations.

Possible values:

  • catalogItem: JSON representation of the catalogItem. Will be set if returnCatalogItem is set to true in PredictRequest.params.
  • score: Prediction score in double value. Will be set if returnItemScore is set to true in PredictRequest.params.