prediction_service.proto 9.9 KB

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