-
Notifications
You must be signed in to change notification settings - Fork 604
/
Copy pathcompletion_service.advanced_complete_query.js
130 lines (120 loc) · 5.38 KB
/
completion_service.advanced_complete_query.js
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
// Copyright 2025 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
//
// https://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.
//
// ** This file is automatically generated by gapic-generator-typescript. **
// ** https://github.com/googleapis/gapic-generator-typescript **
// ** All changes to this file may be overwritten. **
'use strict';
function main(completionConfig, query) {
// [START discoveryengine_v1beta_generated_CompletionService_AdvancedCompleteQuery_async]
/**
* This snippet has been automatically generated and should be regarded as a code template only.
* It will require modifications to work.
* It may require correct/in-range values for request initialization.
* TODO(developer): Uncomment these variables before running the sample.
*/
/**
* Required. The completion_config of the parent dataStore or engine resource
* name for which the completion is performed, such as
* `projects/* /locations/global/collections/default_collection/dataStores/* /completionConfig`
* `projects/* /locations/global/collections/default_collection/engines/* /completionConfig`.
*/
// const completionConfig = 'abc123'
/**
* Required. The typeahead input used to fetch suggestions. Maximum length is
* 128 characters.
* The query can not be empty for most of the suggestion types. If it is
* empty, an `INVALID_ARGUMENT` error is returned. The exception is when the
* suggestion_types contains only the type `RECENT_SEARCH`, the query can
* be an empty string. The is called "zero prefix" feature, which returns
* user's recently searched queries given the empty query.
*/
// const query = 'abc123'
/**
* Specifies the autocomplete data model. This overrides any model specified
* in the Configuration > Autocomplete section of the Cloud console. Currently
* supported values:
* * `document` - Using suggestions generated from user-imported documents.
* * `search-history` - Using suggestions generated from the past history of
* SearchService.Search google.cloud.discoveryengine.v1beta.SearchService.Search
* API calls. Do not use it when there is no traffic for Search API.
* * `user-event` - Using suggestions generated from user-imported search
* events.
* * `document-completable` - Using suggestions taken directly from
* user-imported document fields marked as completable.
* Default values:
* * `document` is the default model for regular dataStores.
* * `search-history` is the default model for site search dataStores.
*/
// const queryModel = 'abc123'
/**
* 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.
* This field should NOT have a fixed value such as `unknown_visitor`.
* This should be the same identifier as
* UserEvent.user_pseudo_id google.cloud.discoveryengine.v1beta.UserEvent.user_pseudo_id
* and
* SearchRequest.user_pseudo_id google.cloud.discoveryengine.v1beta.SearchRequest.user_pseudo_id.
* The field must be a UTF-8 encoded string with a length limit of 128
*/
// const userPseudoId = 'abc123'
/**
* Optional. Information about the end user.
* This should be the same identifier information as
* UserEvent.user_info google.cloud.discoveryengine.v1beta.UserEvent.user_info
* and
* SearchRequest.user_info google.cloud.discoveryengine.v1beta.SearchRequest.user_info.
*/
// const userInfo = {}
/**
* Indicates if tail suggestions should be returned if there are no
* suggestions that match the full query. Even if set to true, if there are
* suggestions that match the full query, those are returned and no
* tail suggestions are returned.
*/
// const includeTailSuggestions = true
/**
* Optional. Specification to boost suggestions matching the condition.
*/
// const boostSpec = {}
/**
* Optional. Suggestion types to return. If empty or unspecified, query
* suggestions are returned. Only one suggestion type is supported at the
* moment.
*/
// const suggestionTypes = [1,2,3,4]
// Imports the Discoveryengine library
const {CompletionServiceClient} = require('@google-cloud/discoveryengine').v1beta;
// Instantiates a client
const discoveryengineClient = new CompletionServiceClient();
async function callAdvancedCompleteQuery() {
// Construct request
const request = {
completionConfig,
query,
};
// Run request
const response = await discoveryengineClient.advancedCompleteQuery(request);
console.log(response);
}
callAdvancedCompleteQuery();
// [END discoveryengine_v1beta_generated_CompletionService_AdvancedCompleteQuery_async]
}
process.on('unhandledRejection', err => {
console.error(err.message);
process.exitCode = 1;
});
main(...process.argv.slice(2));