1// Copyright 2021 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto3"; 16 17package google.cloud.retail.v2; 18 19import "google/api/annotations.proto"; 20import "google/api/client.proto"; 21import "google/api/field_behavior.proto"; 22import "google/api/resource.proto"; 23import "google/cloud/retail/v2/user_event.proto"; 24import "google/protobuf/struct.proto"; 25 26option csharp_namespace = "Google.Cloud.Retail.V2"; 27option go_package = "cloud.google.com/go/retail/apiv2/retailpb;retailpb"; 28option java_multiple_files = true; 29option java_outer_classname = "PredictionServiceProto"; 30option java_package = "com.google.cloud.retail.v2"; 31option objc_class_prefix = "RETAIL"; 32option php_namespace = "Google\\Cloud\\Retail\\V2"; 33option ruby_package = "Google::Cloud::Retail::V2"; 34 35// Service for making recommendation prediction. 36service PredictionService { 37 option (google.api.default_host) = "retail.googleapis.com"; 38 option (google.api.oauth_scopes) = 39 "https://www.googleapis.com/auth/cloud-platform"; 40 41 // Makes a recommendation prediction. 42 rpc Predict(PredictRequest) returns (PredictResponse) { 43 option (google.api.http) = { 44 post: "/v2/{placement=projects/*/locations/*/catalogs/*/placements/*}:predict" 45 body: "*" 46 additional_bindings { 47 post: "/v2/{placement=projects/*/locations/*/catalogs/*/servingConfigs/*}:predict" 48 body: "*" 49 } 50 }; 51 } 52} 53 54// Request message for Predict method. 55message PredictRequest { 56 // Required. Full resource name of the format: 57 // `{placement=projects/*/locations/global/catalogs/default_catalog/servingConfigs/*}` 58 // or 59 // `{placement=projects/*/locations/global/catalogs/default_catalog/placements/*}`. 60 // We recommend using the `servingConfigs` resource. `placements` is a legacy 61 // resource. 62 // The ID of the Recommendations AI serving config or placement. 63 // Before you can request predictions from your model, you must create at 64 // least one serving config or placement for it. For more information, see 65 // [Manage serving configs] 66 // (https://cloud.google.com/retail/docs/manage-configs). 67 // 68 // The full list of available serving configs can be seen at 69 // https://console.cloud.google.com/ai/retail/catalogs/default_catalog/configs 70 string placement = 1 [(google.api.field_behavior) = REQUIRED]; 71 72 // Required. Context about the user, what they are looking at and what action 73 // they took to trigger the predict request. Note that this user event detail 74 // won't be ingested to userEvent logs. Thus, a separate userEvent write 75 // request is required for event logging. 76 // 77 // Don't set 78 // [UserEvent.visitor_id][google.cloud.retail.v2.UserEvent.visitor_id] or 79 // [UserInfo.user_id][google.cloud.retail.v2.UserInfo.user_id] to the same 80 // fixed ID for different users. If you are trying to receive non-personalized 81 // recommendations (not recommended; this can negatively impact model 82 // performance), instead set 83 // [UserEvent.visitor_id][google.cloud.retail.v2.UserEvent.visitor_id] to a 84 // random unique ID and leave 85 // [UserInfo.user_id][google.cloud.retail.v2.UserInfo.user_id] unset. 86 UserEvent user_event = 2 [(google.api.field_behavior) = REQUIRED]; 87 88 // Maximum number of results to return. Set this property to the number of 89 // prediction results needed. If zero, the service will choose a reasonable 90 // default. The maximum allowed value is 100. Values above 100 will be coerced 91 // to 100. 92 int32 page_size = 3; 93 94 // This field is not used; leave it unset. 95 string page_token = 4 [deprecated = true]; 96 97 // Filter for restricting prediction results with a length limit of 5,000 98 // characters. Accepts values for tags and the `filterOutOfStockItems` flag. 99 // 100 // * Tag expressions. Restricts predictions to products that match all of the 101 // specified tags. Boolean operators `OR` and `NOT` are supported if the 102 // expression is enclosed in parentheses, and must be separated from the 103 // tag values by a space. `-"tagA"` is also supported and is equivalent to 104 // `NOT "tagA"`. Tag values must be double quoted UTF-8 encoded strings 105 // with a size limit of 1,000 characters. 106 // 107 // Note: "Recently viewed" models don't support tag filtering at the 108 // moment. 109 // 110 // * filterOutOfStockItems. Restricts predictions to products that do not 111 // have a 112 // stockState value of OUT_OF_STOCK. 113 // 114 // Examples: 115 // 116 // * tag=("Red" OR "Blue") tag="New-Arrival" tag=(NOT "promotional") 117 // * filterOutOfStockItems tag=(-"promotional") 118 // * filterOutOfStockItems 119 // 120 // If your filter blocks all prediction results, the API will return *no* 121 // results. If instead you want empty result sets to return generic 122 // (unfiltered) popular products, set `strictFiltering` to False in 123 // `PredictRequest.params`. Note that the API will never return items with 124 // storageStatus of "EXPIRED" or "DELETED" regardless of filter choices. 125 // 126 // If `filterSyntaxV2` is set to true under the `params` field, then 127 // attribute-based expressions are expected instead of the above described 128 // tag-based syntax. Examples: 129 // 130 // * (colors: ANY("Red", "Blue")) AND NOT (categories: ANY("Phones")) 131 // * (availability: ANY("IN_STOCK")) AND 132 // (colors: ANY("Red") OR categories: ANY("Phones")) 133 // 134 // For more information, see 135 // [Filter recommendations](https://cloud.google.com/retail/docs/filter-recs). 136 string filter = 5; 137 138 // Use validate only mode for this prediction query. If set to true, a 139 // dummy model will be used that returns arbitrary products. 140 // Note that the validate only mode should only be used for testing the API, 141 // or if the model is not ready. 142 bool validate_only = 6; 143 144 // Additional domain specific parameters for the predictions. 145 // 146 // Allowed values: 147 // 148 // * `returnProduct`: Boolean. If set to true, the associated product 149 // object will be returned in the `results.metadata` field in the 150 // prediction response. 151 // * `returnScore`: Boolean. If set to true, the prediction 'score' 152 // corresponding to each returned product will be set in the 153 // `results.metadata` field in the prediction response. The given 154 // 'score' indicates the probability of a product being clicked/purchased 155 // given the user's context and history. 156 // * `strictFiltering`: Boolean. True by default. If set to false, the service 157 // will return generic (unfiltered) popular products instead of empty if 158 // your filter blocks all prediction results. 159 // * `priceRerankLevel`: String. Default empty. If set to be non-empty, then 160 // it needs to be one of {'no-price-reranking', 'low-price-reranking', 161 // 'medium-price-reranking', 'high-price-reranking'}. This gives 162 // request-level control and adjusts prediction results based on product 163 // price. 164 // * `diversityLevel`: String. Default empty. If set to be non-empty, then 165 // it needs to be one of {'no-diversity', 'low-diversity', 166 // 'medium-diversity', 'high-diversity', 'auto-diversity'}. This gives 167 // request-level control and adjusts prediction results based on product 168 // category. 169 // * `filterSyntaxV2`: Boolean. False by default. If set to true, the `filter` 170 // field is interpreteted according to the new, attribute-based syntax. 171 map<string, google.protobuf.Value> params = 7; 172 173 // The labels applied to a resource must meet the following requirements: 174 // 175 // * Each resource can have multiple labels, up to a maximum of 64. 176 // * Each label must be a key-value pair. 177 // * Keys have a minimum length of 1 character and a maximum length of 63 178 // characters and cannot be empty. Values can be empty and have a maximum 179 // length of 63 characters. 180 // * Keys and values can contain only lowercase letters, numeric characters, 181 // underscores, and dashes. All characters must use UTF-8 encoding, and 182 // international characters are allowed. 183 // * The key portion of a label must be unique. However, you can use the same 184 // key with multiple resources. 185 // * Keys must start with a lowercase letter or international character. 186 // 187 // See [Google Cloud 188 // Document](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements) 189 // for more details. 190 map<string, string> labels = 8; 191} 192 193// Response message for predict method. 194message PredictResponse { 195 // PredictionResult represents the recommendation prediction results. 196 message PredictionResult { 197 // ID of the recommended product 198 string id = 1; 199 200 // Additional product metadata / annotations. 201 // 202 // Possible values: 203 // 204 // * `product`: JSON representation of the product. Is set if 205 // `returnProduct` is set to true in `PredictRequest.params`. 206 // * `score`: Prediction score in double value. Is set if 207 // `returnScore` is set to true in `PredictRequest.params`. 208 map<string, google.protobuf.Value> metadata = 2; 209 } 210 211 // A list of recommended products. The order represents the ranking (from the 212 // most relevant product to the least). 213 repeated PredictionResult results = 1; 214 215 // A unique attribution token. This should be included in the 216 // [UserEvent][google.cloud.retail.v2.UserEvent] logs resulting from this 217 // recommendation, which enables accurate attribution of recommendation model 218 // performance. 219 string attribution_token = 2; 220 221 // IDs of products in the request that were missing from the inventory. 222 repeated string missing_ids = 3; 223 224 // True if the validateOnly property was set in the request. 225 bool validate_only = 4; 226} 227