xref: /aosp_15_r20/external/googleapis/google/cloud/discoveryengine/v1/recommendation_service.proto (revision d5c09012810ac0c9f33fe448fb6da8260d444cc9)
1// Copyright 2022 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.discoveryengine.v1;
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/discoveryengine/v1/document.proto";
24import "google/cloud/discoveryengine/v1/user_event.proto";
25import "google/protobuf/struct.proto";
26
27option csharp_namespace = "Google.Cloud.DiscoveryEngine.V1";
28option go_package = "cloud.google.com/go/discoveryengine/apiv1/discoveryenginepb;discoveryenginepb";
29option java_multiple_files = true;
30option java_outer_classname = "RecommendationServiceProto";
31option java_package = "com.google.cloud.discoveryengine.v1";
32option objc_class_prefix = "DISCOVERYENGINE";
33option php_namespace = "Google\\Cloud\\DiscoveryEngine\\V1";
34option ruby_package = "Google::Cloud::DiscoveryEngine::V1";
35
36// Service for making recommendations.
37service RecommendationService {
38  option (google.api.default_host) = "discoveryengine.googleapis.com";
39  option (google.api.oauth_scopes) =
40      "https://www.googleapis.com/auth/cloud-platform";
41
42  // Makes a recommendation, which requires a contextual user event.
43  rpc Recommend(RecommendRequest) returns (RecommendResponse) {
44    option (google.api.http) = {
45      post: "/v1/{serving_config=projects/*/locations/*/dataStores/*/servingConfigs/*}:recommend"
46      body: "*"
47      additional_bindings {
48        post: "/v1/{serving_config=projects/*/locations/*/collections/*/dataStores/*/servingConfigs/*}:recommend"
49        body: "*"
50      }
51      additional_bindings {
52        post: "/v1/{serving_config=projects/*/locations/*/collections/*/engines/*/servingConfigs/*}:recommend"
53        body: "*"
54      }
55    };
56  }
57}
58
59// Request message for Recommend method.
60message RecommendRequest {
61  // Required. Full resource name of a [ServingConfig][]:
62  // `projects/*/locations/global/collections/*/engines/*/servingConfigs/*`, or
63  // `projects/*/locations/global/collections/*/dataStores/*/servingConfigs/*`
64  //
65  // One default serving config is created along with your recommendation engine
66  // creation. The engine ID will be used as the ID of the default serving
67  // config. For example, for Engine
68  // `projects/*/locations/global/collections/*/engines/my-engine`, you can use
69  // `projects/*/locations/global/collections/*/engines/my-engine/servingConfigs/my-engine`
70  // for your
71  // [RecommendationService.Recommend][google.cloud.discoveryengine.v1.RecommendationService.Recommend]
72  // requests.
73  string serving_config = 1 [
74    (google.api.field_behavior) = REQUIRED,
75    (google.api.resource_reference) = {
76      type: "discoveryengine.googleapis.com/ServingConfig"
77    }
78  ];
79
80  // Required. Context about the user, what they are looking at and what action
81  // they took to trigger the Recommend request. Note that this user event
82  // detail won't be ingested to userEvent logs. Thus, a separate userEvent
83  // write request is required for event logging.
84  //
85  // Don't set
86  // [UserEvent.user_pseudo_id][google.cloud.discoveryengine.v1.UserEvent.user_pseudo_id]
87  // or
88  // [UserEvent.user_info.user_id][google.cloud.discoveryengine.v1.UserInfo.user_id]
89  // to the same fixed ID for different users. If you are trying to receive
90  // non-personalized recommendations (not recommended; this can negatively
91  // impact model performance), instead set
92  // [UserEvent.user_pseudo_id][google.cloud.discoveryengine.v1.UserEvent.user_pseudo_id]
93  // to a random unique ID and leave
94  // [UserEvent.user_info.user_id][google.cloud.discoveryengine.v1.UserInfo.user_id]
95  // unset.
96  UserEvent user_event = 2 [(google.api.field_behavior) = REQUIRED];
97
98  // Maximum number of results to return. Set this property
99  // to the number of recommendation results needed. If zero, the service will
100  // choose a reasonable default. The maximum allowed value is 100. Values
101  // above 100 will be coerced to 100.
102  int32 page_size = 3;
103
104  // Filter for restricting recommendation results with a length limit of 5,000
105  // characters. Currently, only filter expressions on the `filter_tags`
106  // attribute is supported.
107  //
108  //
109  // Examples:
110  //
111  //  * `(filter_tags: ANY("Red", "Blue") OR filter_tags: ANY("Hot", "Cold"))`
112  //  * `(filter_tags: ANY("Red", "Blue")) AND NOT (filter_tags: ANY("Green"))`
113  //
114  // If `attributeFilteringSyntax` is set to true under the `params` field, then
115  // attribute-based expressions are expected instead of the above described
116  // tag-based syntax. Examples:
117  //
118  //  * (launguage: ANY("en", "es")) AND NOT (categories: ANY("Movie"))
119  //  * (available: true) AND
120  //    (launguage: ANY("en", "es")) OR (categories: ANY("Movie"))
121  //
122  // If your filter blocks all results, the API will return generic
123  // (unfiltered) popular Documents. If you only want results strictly matching
124  // the filters, set `strictFiltering` to True in
125  // [RecommendRequest.params][google.cloud.discoveryengine.v1.RecommendRequest.params]
126  // to receive empty results instead.
127  //
128  // Note that the API will never return
129  // [Document][google.cloud.discoveryengine.v1.Document]s with `storageStatus`
130  // of `EXPIRED` or `DELETED` regardless of filter choices.
131  string filter = 4;
132
133  // Use validate only mode for this recommendation query. If set to true, a
134  // fake model will be used that returns arbitrary Document IDs.
135  // Note that the validate only mode should only be used for testing the API,
136  // or if the model is not ready.
137  bool validate_only = 5;
138
139  // Additional domain specific parameters for the recommendations.
140  //
141  // Allowed values:
142  //
143  // * `returnDocument`: Boolean. If set to true, the associated Document
144  //    object will be returned in
145  //    [RecommendResponse.RecommendationResult.document][google.cloud.discoveryengine.v1.RecommendResponse.RecommendationResult.document].
146  // * `returnScore`: Boolean. If set to true, the recommendation 'score'
147  //    corresponding to each returned Document will be set in
148  //    [RecommendResponse.RecommendationResult.metadata][google.cloud.discoveryengine.v1.RecommendResponse.RecommendationResult.metadata].
149  //    The given 'score' indicates the probability of a Document conversion
150  //    given the user's context and history.
151  // * `strictFiltering`: Boolean. True by default. If set to false, the service
152  //    will return generic (unfiltered) popular Documents instead of empty if
153  //    your filter blocks all recommendation results.
154  // * `diversityLevel`: String. Default empty. If set to be non-empty, then
155  //    it needs to be one of:
156  //     *  `no-diversity`
157  //     *  `low-diversity`
158  //     *  `medium-diversity`
159  //     *  `high-diversity`
160  //     *  `auto-diversity`
161  //    This gives request-level control and adjusts recommendation results
162  //    based on Document category.
163  // * `attributeFilteringSyntax`: Boolean. False by default. If set to true,
164  //    the `filter` field is interpreted according to the new,
165  //    attribute-based syntax.
166  map<string, google.protobuf.Value> params = 6;
167
168  // The user labels applied to a resource must meet the following requirements:
169  //
170  // * Each resource can have multiple labels, up to a maximum of 64.
171  // * Each label must be a key-value pair.
172  // * Keys have a minimum length of 1 character and a maximum length of 63
173  //   characters and cannot be empty. Values can be empty and have a maximum
174  //   length of 63 characters.
175  // * Keys and values can contain only lowercase letters, numeric characters,
176  //   underscores, and dashes. All characters must use UTF-8 encoding, and
177  //   international characters are allowed.
178  // * The key portion of a label must be unique. However, you can use the same
179  //   key with multiple resources.
180  // * Keys must start with a lowercase letter or international character.
181  //
182  // See [Requirements for
183  // labels](https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
184  // for more details.
185  map<string, string> user_labels = 8;
186}
187
188// Response message for Recommend method.
189message RecommendResponse {
190  // RecommendationResult represents a generic recommendation result with
191  // associated metadata.
192  message RecommendationResult {
193    // Resource ID of the recommended Document.
194    string id = 1;
195
196    // Set if `returnDocument` is set to true in
197    // [RecommendRequest.params][google.cloud.discoveryengine.v1.RecommendRequest.params].
198    Document document = 2;
199
200    // Additional Document metadata / annotations.
201    //
202    // Possible values:
203    //
204    // * `score`: Recommendation score in double value. Is set if
205    //   `returnScore` is set to true in
206    //   [RecommendRequest.params][google.cloud.discoveryengine.v1.RecommendRequest.params].
207    map<string, google.protobuf.Value> metadata = 3;
208  }
209
210  // A list of recommended Documents. The order represents the ranking (from the
211  // most relevant Document to the least).
212  repeated RecommendationResult results = 1;
213
214  // A unique attribution token. This should be included in the
215  // [UserEvent][google.cloud.discoveryengine.v1.UserEvent] logs resulting from
216  // this recommendation, which enables accurate attribution of recommendation
217  // model performance.
218  string attribution_token = 2;
219
220  // IDs of documents in the request that were missing from the default Branch
221  // associated with the requested ServingConfig.
222  repeated string missing_ids = 3;
223
224  // True if
225  // [RecommendRequest.validate_only][google.cloud.discoveryengine.v1.RecommendRequest.validate_only]
226  // was set.
227  bool validate_only = 4;
228}
229