This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
/
completion_service.py
178 lines (144 loc) · 6.87 KB
/
completion_service.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# -*- coding: utf-8 -*-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import proto # type: ignore
from google.cloud.retail_v2.types import common
__protobuf__ = proto.module(
package="google.cloud.retail.v2",
manifest={"CompleteQueryRequest", "CompleteQueryResponse",},
)
class CompleteQueryRequest(proto.Message):
r"""Auto-complete parameters.
Attributes:
catalog (str):
Required. Catalog for which the completion is performed.
Full resource name of catalog, such as
``projects/*/locations/global/catalogs/default_catalog``.
query (str):
Required. The query used to generate
suggestions.
The maximum number of allowed characters is 255.
visitor_id (str):
A unique identifier for tracking visitors. For example, this
could be implemented with an HTTP cookie, which should be
able to uniquely identify a visitor on a single device. This
unique identifier should not change if the visitor logs in
or out of the website.
The field must be a UTF-8 encoded string with a length limit
of 128 characters. Otherwise, an INVALID_ARGUMENT error is
returned.
language_codes (Sequence[str]):
The list of languages of the query. This is the BCP-47
language code, such as "en-US" or "sr-Latn". For more
information, see `Tags for Identifying
Languages <https://tools.ietf.org/html/bcp47>`__.
The maximum number of allowed characters is 255. Only
"en-US" is currently supported.
device_type (str):
The device type context for completion suggestions. It is
useful to apply different suggestions on different device
types, e.g. ``DESKTOP``, ``MOBILE``. If it is empty, the
suggestions are across all device types.
Supported formats:
- ``UNKNOWN_DEVICE_TYPE``
- ``DESKTOP``
- ``MOBILE``
- A customized string starts with ``OTHER_``, e.g.
``OTHER_IPHONE``.
dataset (str):
Determines which dataset to use for fetching completion.
"user-data" will use the imported dataset through
[CompletionService.ImportCompletionData][google.cloud.retail.v2.CompletionService.ImportCompletionData].
"cloud-retail" will use the dataset generated by cloud
retail based on user events. If leave empty, it will use the
"user-data".
Current supported values:
- user-data
- cloud-retail This option requires additional
allowlisting. Before using cloud-retail, contact Cloud
Retail support team first.
max_suggestions (int):
Completion max suggestions. If left unset or set to 0, then
will fallback to the configured value
[CompletionConfig.max_suggestions][].
The maximum allowed max suggestions is 20. If it is set
higher, it will be capped by 20.
"""
catalog = proto.Field(proto.STRING, number=1,)
query = proto.Field(proto.STRING, number=2,)
visitor_id = proto.Field(proto.STRING, number=7,)
language_codes = proto.RepeatedField(proto.STRING, number=3,)
device_type = proto.Field(proto.STRING, number=4,)
dataset = proto.Field(proto.STRING, number=6,)
max_suggestions = proto.Field(proto.INT32, number=5,)
class CompleteQueryResponse(proto.Message):
r"""Response of the auto-complete query.
Attributes:
completion_results (Sequence[google.cloud.retail_v2.types.CompleteQueryResponse.CompletionResult]):
Results of the matching suggestions. The
result list is ordered and the first result is
top suggestion.
attribution_token (str):
A unique complete token. This should be included in the
[SearchRequest][google.cloud.retail.v2.SearchRequest]
resulting from this completion, which enables accurate
attribution of complete model performance.
recent_search_results (Sequence[google.cloud.retail_v2.types.CompleteQueryResponse.RecentSearchResult]):
Matched recent searches of this user. The maximum number of
recent searches is 10. This field is a restricted feature.
Contact Retail Search support team if you are interested in
enabling it.
This feature is only available when
[CompleteQueryRequest.visitor_id][google.cloud.retail.v2.CompleteQueryRequest.visitor_id]
field is set and
[UserEvent][google.cloud.retail.v2.UserEvent] is imported.
The recent searches satisfy the follow rules:
- They are ordered from latest to oldest.
- They are matched with
[CompleteQueryRequest.query][google.cloud.retail.v2.CompleteQueryRequest.query]
case insensitively.
- They are transformed to lower cases.
- They are UTF-8 safe.
Recent searches are deduplicated. More recent searches will
be reserved when duplication happens.
"""
class CompletionResult(proto.Message):
r"""Resource that represents completion results.
Attributes:
suggestion (str):
The suggestion for the query.
attributes (Sequence[google.cloud.retail_v2.types.CompleteQueryResponse.CompletionResult.AttributesEntry]):
Additional custom attributes ingested through
BigQuery.
"""
suggestion = proto.Field(proto.STRING, number=1,)
attributes = proto.MapField(
proto.STRING, proto.MESSAGE, number=2, message=common.CustomAttribute,
)
class RecentSearchResult(proto.Message):
r"""Recent search of this user.
Attributes:
recent_search (str):
The recent search query.
"""
recent_search = proto.Field(proto.STRING, number=1,)
completion_results = proto.RepeatedField(
proto.MESSAGE, number=1, message=CompletionResult,
)
attribution_token = proto.Field(proto.STRING, number=2,)
recent_search_results = proto.RepeatedField(
proto.MESSAGE, number=3, message=RecentSearchResult,
)
__all__ = tuple(sorted(__protobuf__.manifest))