This page shows how to preview recommendations using the Google Cloud console and get recommendations results using the API. See the REST tab for examples of API calls that can help you integrate recommendations into your app.
The procedure that you use depends on whether you have media data or custom data:
Get media recommendations
Console
To use the Google Cloud console to preview media recommendations, follow these steps:
-
In the Google Cloud console, go to the AI Applicationspage.
-
Click the name of the app for which you want to preview recommendations.
-
Click Configurations> Training. If Ready to queryis Yes, then the app is ready for preview.
-
Click Preview.
-
Click the Document IDfield. A list of document IDs appears.
-
Click the document ID for the document that you want recommendations for. Alternatively, enter a document ID into the Document IDfield.
-
Click Select serving configand select the serving config to preview.
-
Optional: Enter the visitor ID (also called the pseudo user ID) of a user for whom you have collected user events. If you leave this field blank or enter a non-existent visitor ID, you'll preview recommendations as a new user.
-
Click Get recommendations. A list of recommended documents appears.
-
Click a document to get document details.
REST
To use the API to get media recommendations, use the servingConfigs.recommend
method:
-
Find your engine ID and serving config ID. If you already have your engine ID and serving config IDs, skip to step 2.
-
In the Google Cloud console, go to the AI Applicationspage.
-
Click the name of the app.
-
In the navigation pane, click Configurations.
-
If you have only one serving config, get the serving config ID that is displayed in the Servingtab.
If you have multiple serving configs listed in the Servingtab, find the serving config that you want to get recommendations from. Your serving config ID is the value in the IDcolumn.
-
Click the Trainingtab. Your engine ID is the value in the App IDrow.
-
-
Make sure the app is ready for previewing:
-
In the Google Cloud console, go to the AI Applicationspage.
-
Click the name of the app.
-
Click Configurations> Training. If Ready to queryis Yes, then the app is ready for preview.
-
-
Get recommendations.
curl -X POST \ -H "Authorization: Bearer $( gcloud auth print-access-token ) " \ -H "Content-Type: application/json; charset=utf-8" \ -d '{ "validateOnly": false, "userEvent": { "eventType": "view-item", "userPseudoId": " USER_PSEUDO_ID ", "documents": [{ "id": " DOCUMENT_ID " }], "filter": " FILTER_STRING " } }' \ "https://discoveryengine.googleapis.com/v1beta/projects/ PROJECT_ID /locations/global/collections/default_collection/dataStores/ DATA_STORE_ID /servingConfigs/ SERVING_CONFIG_ID :recommend"
Replace the following:
-
PROJECT_ID
: the ID of your project. -
DATA_STORE_ID
: the ID of your data store. -
DOCUMENT_ID
: the ID of document that you want to preview recommendations for. Use the ID that you used for this document at the time you ingested your data. -
USER_PSEUDO_ID
: a UTF-8 encoded string, which acts as a unique pseudonymized identifier that tracks the users. It can have a maximum length of 128 characters. Google strongly recommends using this field because it improves model performance and personalization quality. You can use an HTTP cookie for this field, which uniquely identifies a visitor on a single device. Some important considerations are as follows:- This identifier doesn't change when the visitor signs in or out of a website.
- This field must not be set to the same identifier for multiple users. Otherwise, same user ID can combine event histories of different users and degrade model quality.
- This field must not include personally identifiable information (PII).
For more information, see
userPseudoId
. -
SERVING_CONFIG_ID
: the ID of your serving config. -
FILTER
: optional. A text field that lets you to filter on a specified set of fields, using filter expression syntax. The default value is an empty string, which means no filter is applied. For more information, see Filter recommendations .
-
You should see results similar to the following:
{ "results" : [{ "id" : "sample-id-1" }, { "id" : "sample-id-2" }], "attributionToken" : "abc123" }
Google recommends associating attribution tokens, which we include with each
search response and recommendation, with actions that a user takes in response
to those search responses and recommendations. This can improve the quality of
your search responses and recommendations over time. To do this, append attributionToken
values to the URLs for each of the links that you display on
your website for search responses or recommendations—for example, https://www.example.com/54321/?rtoken=abc123
. When a user clicks one of these
links, include the attributionToken
value in the user event that you record.