Service for making recommendations. v1beta
Package
@google-cloud/discoveryengineConstructors
(constructor)(opts, gaxInstance)
constructor(opts?: ClientOptions, gaxInstance?: typeof gax | typeof gax.fallback);
Construct an instance of RecommendationServiceClient.
Parameters | |
---|---|
Name | Description |
opts |
ClientOptions
|
gaxInstance |
typeof gax | typeof gax.fallback
: loaded instance of |
Properties
apiEndpoint
static get apiEndpoint(): string;
The DNS address for this API service - same as servicePath(), exists for compatibility reasons.
auth
auth: gax.GoogleAuth;
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.
recommendationServiceStub
recommendationServiceStub?: Promise<{
[name: string]: Function;
}>;
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.
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. |
documentPath(project, location, dataStore, branch, document)
documentPath(project: string, location: string, dataStore: string, branch: string, document: string): string;
Return a fully-qualified document resource name string.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
dataStore |
string
|
branch |
string
|
document |
string
|
Returns | |
---|---|
Type | Description |
string | {string} Resource name string. |
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. |
matchBranchFromDocumentName(documentName)
matchBranchFromDocumentName(documentName: string): string | number;
Parse the branch from Document resource.
Parameter | |
---|---|
Name | Description |
documentName |
string
A fully-qualified path representing Document resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the branch. |
matchDataStoreFromDocumentName(documentName)
matchDataStoreFromDocumentName(documentName: string): string | number;
Parse the data_store from Document resource.
Parameter | |
---|---|
Name | Description |
documentName |
string
A fully-qualified path representing Document resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the data_store. |
matchDataStoreFromServingConfigName(servingConfigName)
matchDataStoreFromServingConfigName(servingConfigName: string): string | number;
Parse the data_store from ServingConfig resource.
Parameter | |
---|---|
Name | Description |
servingConfigName |
string
A fully-qualified path representing ServingConfig resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the data_store. |
matchDocumentFromDocumentName(documentName)
matchDocumentFromDocumentName(documentName: string): string | number;
Parse the document from Document resource.
Parameter | |
---|---|
Name | Description |
documentName |
string
A fully-qualified path representing Document resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the document. |
matchLocationFromDocumentName(documentName)
matchLocationFromDocumentName(documentName: string): string | number;
Parse the location from Document resource.
Parameter | |
---|---|
Name | Description |
documentName |
string
A fully-qualified path representing Document resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the location. |
matchLocationFromServingConfigName(servingConfigName)
matchLocationFromServingConfigName(servingConfigName: string): string | number;
Parse the location from ServingConfig resource.
Parameter | |
---|---|
Name | Description |
servingConfigName |
string
A fully-qualified path representing ServingConfig resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the location. |
matchProjectFromDocumentName(documentName)
matchProjectFromDocumentName(documentName: string): string | number;
Parse the project from Document resource.
Parameter | |
---|---|
Name | Description |
documentName |
string
A fully-qualified path representing Document resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the project. |
matchProjectFromServingConfigName(servingConfigName)
matchProjectFromServingConfigName(servingConfigName: string): string | number;
Parse the project from ServingConfig resource.
Parameter | |
---|---|
Name | Description |
servingConfigName |
string
A fully-qualified path representing ServingConfig resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the project. |
matchServingConfigFromServingConfigName(servingConfigName)
matchServingConfigFromServingConfigName(servingConfigName: string): string | number;
Parse the serving_config from ServingConfig resource.
Parameter | |
---|---|
Name | Description |
servingConfigName |
string
A fully-qualified path representing ServingConfig resource. |
Returns | |
---|---|
Type | Description |
string | number | {string} A string representing the serving_config. |
recommend(request, options)
recommend(request?: protos.google.cloud.discoveryengine.v1beta.IRecommendRequest, options?: CallOptions): Promise<[
protos.google.cloud.discoveryengine.v1beta.IRecommendResponse,
protos.google.cloud.discoveryengine.v1beta.IRecommendRequest | undefined,
{} | undefined
]>;
Makes a recommendation, which requires a contextual user event.
Parameters | |
---|---|
Name | Description |
request |
protos.google.cloud.discoveryengine.v1beta.IRecommendRequest
The request object that will be sent. |
options |
CallOptions
Call options. See CallOptions for more details. |
Returns | |
---|---|
Type | Description |
Promise<[
protos.google.cloud.discoveryengine.v1beta.IRecommendResponse,
protos.google.cloud.discoveryengine.v1beta.IRecommendRequest | undefined,
{} | undefined
]> | {Promise} - The promise which resolves to an array. The first element of the array is an object representing . Please see the [documentation](https://github.com/googleapis/gax-nodejs/blob/master/client-libraries.md#regular-methods) 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. Full resource name of the format:
* projects/* /locations/global/dataStores/* /servingConfigs/*
* Before you can request recommendations from your model, you must create at
* least one serving config for it.
*/
// const servingConfig = 'abc123'
/**
* Required. Context about the user, what they are looking at and what action
* they took to trigger the Recommend request. Note that this user event
* detail won't be ingested to userEvent logs. Thus, a separate userEvent
* write request is required for event logging.
* Don't set
* UserEvent.user_pseudo_id google.cloud.discoveryengine.v1beta.UserEvent.user_pseudo_id
* or
* UserEvent.user_info.user_id google.cloud.discoveryengine.v1beta.UserInfo.user_id
* to the same fixed ID for different users. If you are trying to receive
* non-personalized recommendations (not recommended; this can negatively
* impact model performance), instead set
* UserEvent.user_pseudo_id google.cloud.discoveryengine.v1beta.UserEvent.user_pseudo_id
* to a random unique ID and leave
* UserEvent.user_info.user_id google.cloud.discoveryengine.v1beta.UserInfo.user_id
* unset.
*/
// const userEvent = {}
/**
* Maximum number of results to return. Set this property
* to the number of recommendation results needed. If zero, the service will
* choose a reasonable default. The maximum allowed value is 100. Values
* above 100 will be coerced to 100.
*/
// const pageSize = 1234
/**
* Filter for restricting recommendation results with a length limit of 5,000
* characters. Currently, only filter expressions on the `filter_tags`
* attribute is supported.
* Examples:
* * (filter_tags: ANY("Red", "Blue") OR filter_tags: ANY("Hot", "Cold"))
* * (filter_tags: ANY("Red", "Blue")) AND NOT (filter_tags: ANY("Green"))
* If your filter blocks all results, the API will return generic
* (unfiltered) popular Documents. If you only want results strictly matching
* the filters, set `strictFiltering` to True in
* RecommendRequest.params google.cloud.discoveryengine.v1beta.RecommendRequest.params
* to receive empty results instead.
* Note that the API will never return Documents with storageStatus of
* "EXPIRED" or "DELETED" regardless of filter choices.
*/
// const filter = 'abc123'
/**
* Use validate only mode for this recommendation query. If set to true, a
* fake model will be used that returns arbitrary Document IDs.
* Note that the validate only mode should only be used for testing the API,
* or if the model is not ready.
*/
// const validateOnly = true
/**
* Additional domain specific parameters for the recommendations.
* Allowed values:
* * `returnDocument`: Boolean. If set to true, the associated Document
* object will be returned in
* RecommendResponse.results.document RecommendationResult.document.
* * `returnScore`: Boolean. If set to true, the recommendation 'score'
* corresponding to each returned Document will be set in
* RecommendResponse.results.metadata RecommendationResult.metadata. The
* given 'score' indicates the probability of a Document conversion given
* the user's context and history.
* * `strictFiltering`: Boolean. True by default. If set to false, the service
* will return generic (unfiltered) popular Documents instead of empty if
* your filter blocks all recommendation results.
* * `diversityLevel`: String. Default empty. If set to be non-empty, then
* it needs to be one of:
* * 'no-diversity'
* * 'low-diversity'
* * 'medium-diversity'
* * 'high-diversity'
* * 'auto-diversity'
* This gives request-level control and adjusts recommendation results
* based on Document category.
*/
// const params = 1234
/**
* The user labels applied to a resource must meet the following requirements:
* * Each resource can have multiple labels, up to a maximum of 64.
* * Each label must be a key-value pair.
* * Keys have a minimum length of 1 character and a maximum length of 63
* characters and cannot be empty. Values can be empty and have a maximum
* length of 63 characters.
* * Keys and values can contain only lowercase letters, numeric characters,
* underscores, and dashes. All characters must use UTF-8 encoding, and
* international characters are allowed.
* * The key portion of a label must be unique. However, you can use the same
* key with multiple resources.
* * Keys must start with a lowercase letter or international character.
* See Google Cloud
* Document (https://cloud.google.com/resource-manager/docs/creating-managing-labels#requirements)
* for more details.
*/
// const userLabels = 1234
// Imports the Discoveryengine library
const {RecommendationServiceClient} = require('@google-cloud/discoveryengine').v1beta;
// Instantiates a client
const discoveryengineClient = new RecommendationServiceClient();
async function callRecommend() {
// Construct request
const request = {
servingConfig,
userEvent,
};
// Run request
const response = await discoveryengineClient.recommend(request);
console.log(response);
}
callRecommend();
recommend(request, options, callback)
recommend(request: protos.google.cloud.discoveryengine.v1beta.IRecommendRequest, options: CallOptions, callback: Callback<protos.google.cloud.discoveryengine.v1beta.IRecommendResponse, protos.google.cloud.discoveryengine.v1beta.IRecommendRequest | null | undefined, {} | null | undefined>): void;
Parameters | |
---|---|
Name | Description |
request |
protos.google.cloud.discoveryengine.v1beta.IRecommendRequest
|
options |
CallOptions
|
callback |
Callback<protos.google.cloud.discoveryengine.v1beta.IRecommendResponse, protos.google.cloud.discoveryengine.v1beta.IRecommendRequest | null | undefined, {} | null | undefined>
|
Returns | |
---|---|
Type | Description |
void |
recommend(request, callback)
recommend(request: protos.google.cloud.discoveryengine.v1beta.IRecommendRequest, callback: Callback<protos.google.cloud.discoveryengine.v1beta.IRecommendResponse, protos.google.cloud.discoveryengine.v1beta.IRecommendRequest | null | undefined, {} | null | undefined>): void;
Parameters | |
---|---|
Name | Description |
request |
protos.google.cloud.discoveryengine.v1beta.IRecommendRequest
|
callback |
Callback<protos.google.cloud.discoveryengine.v1beta.IRecommendResponse, protos.google.cloud.discoveryengine.v1beta.IRecommendRequest | null | undefined, {} | null | undefined>
|
Returns | |
---|---|
Type | Description |
void |
servingConfigPath(project, location, dataStore, servingConfig)
servingConfigPath(project: string, location: string, dataStore: string, servingConfig: string): string;
Return a fully-qualified servingConfig resource name string.
Parameters | |
---|---|
Name | Description |
project |
string
|
location |
string
|
dataStore |
string
|
servingConfig |
string
|
Returns | |
---|---|
Type | Description |
string | {string} Resource name string. |