prediction_service.proto 9.8 KB

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