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 the type of recommendations you want and the type of data store that your recommendation app is connected to:
- Get media recommendations
- Get generic recommendations for an app with structured data
- Get generic recommendations for an app with unstructured data
- Get generic recommendations for an app with website 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 Agent Builder page.
Click the name of the app for which you want to preview recommendations.
Click Configurations > Training. If Ready to query is OK, then the app is ready for preview.
Click Preview.
Click the Document ID field. 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 ID field.
Click Select serving config and 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.
To use the API to get media recommendations, use the
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 Agent Builder page. Click the name of the app. In the navigation pane, click Configurations. If you have only the serving config that was automatically created when
you created your app, then your serving config ID and engine ID are the
same. Skip to the next step. If you have multiple serving configs listed in the Serving configs
tab, find the serving config that you want to get recommendations from.
Your serving config ID is the value in the ID column. If you deleted the serving config that was automatically created when you
created your app, and currently have only one serving config that you
manually created, then go to the Preview page and click Select
serving config to view the serving config ID. Click the Training tab. Your engine ID is the value in the App ID
row. Make sure the app is ready for previewing: In the Google Cloud console, go to the Agent Builder page. Click the name of the app. Click Configurations > Training. If Ready to query is OK,
then the app is ready for preview. Get recommendations. You should see results similar to the following: 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
REST
servingConfigs.recommend
method:
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/dataStores/DATA_STORE_ID/servingConfigs/SERVING_CONFIG_ID:recommend"
{
"results": [{"id": "sample-id-1"}, {"id": "sample-id-2"}],
"attributionToken": "abc123"
}
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.
Get generic recommendations for an app with structured data
Console
To use the Google Cloud console to preview generic recommendations for your structured app, follow these steps:
In the Google Cloud console, go to the Agent Builder page.
Click the name of the app for which you want to preview recommendations.
Click Preview.
Click the Document ID field. 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 ID field.
Click Get recommendations. A list of recommended documents appears.
Click a document to get document details.
REST
To use the API to get generic recommendations for an app with structured data,
use the servingConfigs.recommend
method:
Find your engine ID. If you already have your engine ID, skip to step 2.
In the Google Cloud console, go to the Agent Builder page.
Click the name of the app.
Get the engine ID from the URL of the Google Cloud console. It is the text between
engines/
and/data
. For example, if the URL containsgen-app-builder/engines/demo_1234567890123/data/records
then the engine ID is
demo_1234567890123
.
Find your data store ID. If you already have your data store ID, skip to the next step.
In the Google Cloud console, go to the Agent Builder page and in the navigation menu, click Data Stores.
Click the name of your data store.
On the Data page for your data store, get the data store ID.
Make sure your engine is ready to previewing by polling the
GetEngine
method until it returns"servingState":"ACTIVE"
. At that point the engine is ready for previewing.curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/ENGINE_ID
- PROJECT_ID: The ID of your project.
- ENGINE_ID: The ID of your engine.
Get recommendations.
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "userEvent": { "eventType":"view-item", "userPseudoId":"USER_PSEUDO_ID", "documents":[{"id":"DOCUMENT_ID"}]}}' \ "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/dataStores/DATA_STORE_ID/servingConfigs/SERVING_CONFIG_ID:recommend"
- 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 pseudonymized identifier of the user. You can use an HTTP cookie for this field, which uniquely identifies a visitor on a single device. Don't set this field to the same identifier for multiple users—this would combine their event histories and degrade model quality. Don't include personally identifiable information (PII) in this field.
- SERVING_CONFIG_ID: The ID of your serving config. Your serving config ID is the same as your engine ID, so use your engine ID here.
C#
For more information, see the Vertex AI Agent Builder C# API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
For more information, see the Vertex AI Agent Builder Go API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
For more information, see the Vertex AI Agent Builder Java API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
For more information, see the Vertex AI Agent Builder Node.js API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
For more information, see the Vertex AI Agent Builder PHP API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
For more information, see the Vertex AI Agent Builder Python API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
For more information, see the
Vertex AI Agent Builder Ruby API
reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Ruby
Get generic recommendations for an app with unstructured data
Console
To use the Google Cloud console to preview generic recommendations, follow these steps:
In the Google Cloud console, go to the Agent Builder page.
Click the name of the app for which you want to preview recommendations.
Click Preview.
Click the URI field. A list of URIs appears.
Click the URI for the document that you want recommendations for. Alternatively, enter a URI into the URI field.
Click Get recommendations. A list of URIs for recommended documents appears.
Click a URI to view the document.
REST
To use the API to get generic recommendations for an app with unstructured data, follow these steps:
Find your engine ID. If you already have your engine ID, skip to step 2.
In the Google Cloud console, go to the Agent Builder page.
Click the name of the app.
Get the engine ID from the URL of the Google Cloud console. It is the text between
engines/
and/data
. For example, if the URL containsgen-app-builder/engines/demo_1234567890123/data/records
then the engine ID is
demo_1234567890123
.
Find your data store ID. If you already have your data store ID, skip to the next step.
In the Google Cloud console, go to the Agent Builder page and in the navigation menu, click Data Stores.
Click the name of your data store.
On the Data page for your data store, get the data store ID.
Make sure your engine is ready to previewing by polling the
GetEngine
method until it returns"servingState":"ACTIVE"
. At that point the engine is ready for previewing.curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/ENGINE_ID
- PROJECT_ID: The ID of your project.
- ENGINE_ID: The ID of your engine.
Get recommendations.
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "userEvent": { "eventType":"view-item", "userPseudoId":"USER_PSEUDO_ID", "documents":[{"id":"DOCUMENT_ID"}]}}' \ "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/dataStores/DATA_STORE_ID/servingConfigs/SERVING_CONFIG_ID:recommend"
- PROJECT_ID: The ID of your project.
- DATA_STORE_ID: The ID of the data store associated with your engine.
- DOCUMENT_ID: The ID of document that you want to preview recommendations for. Use the document ID that you provided at the time you ingested your data.
- USER_PSEUDO_ID: A pseudonymized identifier of the user. You can use an HTTP cookie for this field, which uniquely identifies a visitor on a single device. Don't set this field to the same identifier for multiple users—this would combine their event histories and degrade model quality. Don't include personally identifiable information (PII) in this field.
- SERVING_CONFIG_ID: The ID of your serving config. Your serving config ID is the same as your engine ID, so use your engine ID here.
C#
For more information, see the Vertex AI Agent Builder C# API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
For more information, see the Vertex AI Agent Builder Go API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
For more information, see the Vertex AI Agent Builder Java API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
For more information, see the Vertex AI Agent Builder Node.js API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
For more information, see the Vertex AI Agent Builder PHP API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
For more information, see the Vertex AI Agent Builder Python API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
For more information, see the
Vertex AI Agent Builder Ruby API
reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Ruby
Get generic recommendations for an app with website data
Console
To use the Google Cloud console to preview generic recommendations for your website app, follow these steps:
In the Google Cloud console, go to the Agent Builder page.
Click the name of the app for which you want to preview recommendations.
In the navigation menu, click Preview.
Click the URI field. A list of URLs from your website appears.
Click the URL for the web page that you want recommendations for. Alternatively, enter a URL from your website into the URL field.
Click Get recommendations. A list of URLs for recommended web pages appears.
Click a URL to view the web page.
REST
To use the API to get generic recommendations for an app with website data,
use the servingConfigs.recommend
method:
Find your engine ID. If you already have your engine ID, skip to step 2.
In the Google Cloud console, go to the Agent Builder page.
Click the name of the app.
Get the engine ID from the URL of the Google Cloud console. It is the text between
engines/
and/data
. For example, if the URL containsgen-app-builder/engines/demo_1234567890123/data/records
then the engine ID is
demo_1234567890123
.
Find your data store ID. If you already have your data store ID, skip to the next step.
In the Google Cloud console, go to the Agent Builder page and in the navigation menu, click Data Stores.
Click the name of your data store.
On the Data page for your data store, get the data store ID.
Make sure your engine is ready to previewing by polling the
GetEngine
method until it returns"servingState":"ACTIVE"
. At that point the engine is ready for previewing.curl -X GET \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ "https://discoveryengine.googleapis.com/v1/projects/PROJECT_ID/locations/global/collections/default_collection/engines/ENGINE_ID
- PROJECT_ID: The ID of your project.
- ENGINE_ID: The ID of your engine.
Get recommendations.
curl -X POST \ -H "Authorization: Bearer $(gcloud auth print-access-token)" \ -H "Content-Type: application/json" \ -d '{ "userEvent": { "eventType":"view-item", "userPseudoId":"USER_PSEUDO_ID", "documents":[{"uri":"WEBSITE_URL"}]}}' \ "https://discoveryengine.googleapis.com/v1beta/projects/PROJECT_ID/locations/global/dataStores/DATA_STORE_ID/servingConfigs/SERVING_CONFIG_ID:recommend"
- PROJECT_ID: The ID of your project.
- DATA_STORE_ID: The ID of your data store.
- WEBSITE_URL: The URL of the website that you want to preview recommendations for.
- USER_PSEUDO_ID: A pseudonymized identifier of the user. You can use an HTTP cookie for this field, which uniquely identifies a visitor on a single device. Don't set this field to the same identifier for multiple users—this would combine their event histories and degrade model quality. Don't include personally identifiable information (PII) in this field.
- SERVING_CONFIG_ID: The ID of your serving config. Your serving config ID is the same as your engine ID, so use your engine ID here.
C#
For more information, see the Vertex AI Agent Builder C# API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Go
For more information, see the Vertex AI Agent Builder Go API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Java
For more information, see the Vertex AI Agent Builder Java API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Node.js
For more information, see the Vertex AI Agent Builder Node.js API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
PHP
For more information, see the Vertex AI Agent Builder PHP API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
Python
For more information, see the Vertex AI Agent Builder Python API reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.
For more information, see the
Vertex AI Agent Builder Ruby API
reference documentation.
To authenticate to Vertex AI Agent Builder, set up Application Default Credentials.
For more information, see
Set up authentication for a local development environment.
Ruby