This stateless API provides automatic suggestions for natural language queries for the data sources in the provided project and location.
The service provides a resourceless operation suggestQueries
that can be called to get a list of suggestions for a given incomplete query and scope (or list of scopes) under which the query is to be interpreted.
There are two types of suggestions, ENTITY for single entity suggestions and TEMPLATE for full sentences. By default, both types are returned.
Example Request: ``` GetSuggestions({ parent: "locations/us/projects/my-project" scopes: "//bigquery.googleapis.com/projects/my-project/datasets/my-dataset/tables/my-table" query: "top it" }) ```
The service will retrieve information based on the given scope(s) and give suggestions based on that (e.g. "top item" for "top it" if "item" is a known dimension for the provided scope). ``` suggestions { suggestion_info { annotated_suggestion { text_formatted: "top item by sum of usd_revenue_net" markups { type: DIMENSION start_char_index: 4 length: 4 } markups { type: METRIC start_char_index: 19 length: 15 } } query_matches { start_char_index: 0 length: 6 } } suggestion_type: TEMPLATE ranking_score: 0.9 } suggestions { suggestion_info { annotated_suggestion { text_formatted: "item" markups { type: DIMENSION start_char_index: 4 length: 2 } } query_matches { start_char_index: 0 length: 6 } } suggestion_type: ENTITY ranking_score: 0.8 } ``` v1alpha
Package
@google-cloud/data-qnaConstructors
(constructor)(opts, gaxInstance)
constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);
Construct an instance of AutoSuggestionServiceClient.
Parameters | |
---|---|
Name | Description |
opts |
ClientOptions
|
gaxInstance |
typeof gax | typeof fallback
: loaded instance of |
Properties
apiEndpoint
get apiEndpoint(): string;
The DNS address for this API service.
apiEndpoint
static get apiEndpoint(): string;
The DNS address for this API service - same as servicePath.
auth
auth: gax.GoogleAuth;
autoSuggestionServiceStub
autoSuggestionServiceStub?: Promise<{
[name: string]: Function;
}>;
descriptors
descriptors: Descriptors;
innerApiCalls
innerApiCalls: {
[name: string]: Function;
};
pathTemplates
pathTemplates: {
[name: string]: gax.PathTemplate;
};
port
static get port(): number;
The port for this API service.
scopes
static get scopes(): string[];
The scopes needed to make gRPC calls for every method defined in this service.
servicePath
static get servicePath(): string;
The DNS address for this API service.
universeDomain
get universeDomain(): string;
warn
warn: (code: string, message: string, warnType?: string) => void;
Methods
close()
close(): Promise<void>;
Terminate the gRPC channel and close the client.
The client will no longer be usable and all future behavior is undefined.
Returns | |
---|---|
Type | Description |
Promise<void> | {Promise} A promise that resolves when the client is closed. |
getProjectId()
getProjectId(): Promise<string>;
Returns | |
---|---|
Type | Description |
Promise<string> |
getProjectId(callback)
getProjectId(callback: Callback<string, undefined, undefined>): void;
Parameter | |
---|---|
Name | Description |
callback |
Callback<string, undefined, undefined>
|
Returns | |
---|---|
Type | Description |
void |
initialize()
initialize(): Promise<{
[name: string]: Function;
}>;
Initialize the client. Performs asynchronous operations (such as authentication) and prepares the client. This function will be called automatically when any class method is called for the first time, but if you need to initialize it before calling an actual method, feel free to call initialize() directly.
You can await on this method if you want to make sure the client is initialized.
Returns | |
---|---|
Type | Description |
Promise<{
[name: string]: Function;
}> | {Promise} A promise that resolves to an authenticated service stub. |
locationPath(project, location)
locationPath(project: string, location: string): string;
Return a fully-qualified location resource name string.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
Returns | |
---|---|
Type | Description |
string | {string} Resource name string. |
matchLocationFromLocationName(locationName)
matchLocationFromLocationName(locationName: string): string | number;
Parse the location from Location resource.
Parameter | |
---|---|
Name | Description |
locationName |
string
A fully-qualified path representing Location resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the location. |
matchLocationFromQuestionName(questionName)
matchLocationFromQuestionName(questionName: string): string | number;
Parse the location from Question resource.
Parameter | |
---|---|
Name | Description |
questionName |
string
A fully-qualified path representing Question resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the location. |
matchLocationFromUserFeedbackName(userFeedbackName)
matchLocationFromUserFeedbackName(userFeedbackName: string): string | number;
Parse the location from UserFeedback resource.
Parameter | |
---|---|
Name | Description |
userFeedbackName |
string
A fully-qualified path representing UserFeedback resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the location. |
matchProjectFromLocationName(locationName)
matchProjectFromLocationName(locationName: string): string | number;
Parse the project from Location resource.
Parameter | |
---|---|
Name | Description |
locationName |
string
A fully-qualified path representing Location resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the project. |
matchProjectFromQuestionName(questionName)
matchProjectFromQuestionName(questionName: string): string | number;
Parse the project from Question resource.
Parameter | |
---|---|
Name | Description |
questionName |
string
A fully-qualified path representing Question resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the project. |
matchProjectFromUserFeedbackName(userFeedbackName)
matchProjectFromUserFeedbackName(userFeedbackName: string): string | number;
Parse the project from UserFeedback resource.
Parameter | |
---|---|
Name | Description |
userFeedbackName |
string
A fully-qualified path representing UserFeedback resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the project. |
matchQuestionFromQuestionName(questionName)
matchQuestionFromQuestionName(questionName: string): string | number;
Parse the question from Question resource.
Parameter | |
---|---|
Name | Description |
questionName |
string
A fully-qualified path representing Question resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the question. |
matchQuestionFromUserFeedbackName(userFeedbackName)
matchQuestionFromUserFeedbackName(userFeedbackName: string): string | number;
Parse the question from UserFeedback resource.
Parameter | |
---|---|
Name | Description |
userFeedbackName |
string
A fully-qualified path representing UserFeedback resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the question. |
questionPath(project, location, question)
questionPath(project: string, location: string, question: string): string;
Return a fully-qualified question resource name string.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
question |
string
|
Returns | |
---|---|
Type | Description |
string | {string} Resource name string. |
suggestQueries(request, options)
suggestQueries(request?: protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest, options?: CallOptions): Promise<[
protos.google.cloud.dataqna.v1alpha.ISuggestQueriesResponse,
protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest | undefined,
{} | undefined
]>;
Gets a list of suggestions based on a prefix string. AutoSuggestion tolerance should be less than 1 second.
Parameters | |
---|---|
Name | Description |
request |
ISuggestQueriesRequest
The request object that will be sent. |
options |
CallOptions
Call options. See CallOptions for more details. |
Returns | |
---|---|
Type | Description |
Promise<[
protos.google.cloud.dataqna.v1alpha.ISuggestQueriesResponse,
protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest | undefined,
{} | undefined
]> | {Promise} - The promise which resolves to an array. The first element of the array is an object representing SuggestQueriesResponse. Please see the documentation for more details and examples. |
/**
* 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 parent of the suggestion query is the resource denoting the project and
* location.
*/
// const parent = 'abc123'
/**
* The scopes to which this search is restricted. The only supported scope
* pattern is
* `//bigquery.googleapis.com/projects/{GCP-PROJECT-ID}/datasets/{DATASET-ID}/tables/{TABLE-ID}`.
*/
// const scopes = ['abc','def']
/**
* User query for which to generate suggestions. If the query is empty, zero
* state suggestions are returned. This allows UIs to display suggestions
* right away, helping the user to get a sense of what a query might look
* like.
*/
// const query = 'abc123'
/**
* The requested suggestion type. Multiple suggestion types can be
* requested, but there is no guarantee that the service will return
* suggestions for each type. Suggestions for a requested type might rank
* lower than suggestions for other types and the service may decide to cut
* these suggestions off.
*/
// const suggestionTypes = [1,2,3,4]
// Imports the Dataqna library
const {AutoSuggestionServiceClient} = require('@google-cloud/data-qna').v1alpha;
// Instantiates a client
const dataqnaClient = new AutoSuggestionServiceClient();
async function callSuggestQueries() {
// Construct request
const request = {
parent,
};
// Run request
const response = await dataqnaClient.suggestQueries(request);
console.log(response);
}
callSuggestQueries();
suggestQueries(request, options, callback)
suggestQueries(request: protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest, options: CallOptions, callback: Callback<protos.google.cloud.dataqna.v1alpha.ISuggestQueriesResponse, protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest | null | undefined, {} | null | undefined>): void;
Parameters | |
---|---|
Name | Description |
request |
ISuggestQueriesRequest
|
options |
CallOptions
|
callback |
Callback<protos.google.cloud.dataqna.v1alpha.ISuggestQueriesResponse, protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest | null | undefined, {} | null | undefined>
|
Returns | |
---|---|
Type | Description |
void |
suggestQueries(request, callback)
suggestQueries(request: protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest, callback: Callback<protos.google.cloud.dataqna.v1alpha.ISuggestQueriesResponse, protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest | null | undefined, {} | null | undefined>): void;
Parameters | |
---|---|
Name | Description |
request |
ISuggestQueriesRequest
|
callback |
Callback<protos.google.cloud.dataqna.v1alpha.ISuggestQueriesResponse, protos.google.cloud.dataqna.v1alpha.ISuggestQueriesRequest | null | undefined, {} | null | undefined>
|
Returns | |
---|---|
Type | Description |
void |
userFeedbackPath(project, location, question)
userFeedbackPath(project: string, location: string, question: string): string;
Return a fully-qualified userFeedback resource name string.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
question |
string
|
Returns | |
---|---|
Type | Description |
string | {string} Resource name string. |