This document describes how to create context sets in AlloyDB for PostgreSQL Studio using a context set file. Context set names must be unique within a project.
To learn about context sets, see Context sets overview.Before you begin
Complete the following prerequisites before creating an agent.
Enable required services
Enable the following services for your project:Prepare an AlloyDB for PostgreSQL cluster, instance, and database
Make sure that you have access to an existing AlloyDB cluster and instance or create a new one.This tutorial requires you to have a database in your AlloyDB instance. For more information, see Create a database.
Required roles and permissions
- Add an Identity and Access Management (IAM) user or service account to the cluster at the database level. For more information, see Manage database users.
- Grant the
alloydb.databaseUser, theserviceusage.serviceUsageConsumer, and thegeminidataanalytics.queryDataUserroles to the IAM user at the project level. For more information, see Add IAM policy binding for a project. - To create, upload, and manage context sets, grant the Dataplex Catalog Editor
(
roles/dataplex.catalogEditor) or Dataplex Catalog Admin (roles/dataplex.catalogAdmin) role to the IAM user at the project level. For more information, see Context sets permissions.
Grant executesql permission to AlloyDB for PostgreSQL instance
To grant the executesql permission to the AlloyDB for PostgreSQL instance and set
the data_api_access instance setting to the value ALLOW_DATA_API,
use the following curl command:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
https://alloydb.googleapis.com/v1alpha/projects/PROJECT_ID/locations/LOCATION/clusters/CLUSTER_ID/instances/INSTANCE_ID?updateMask=dataApiAccess \
-d '{
"dataApiAccess": "ENABLED",
}'
PROJECT_ID: The ID of your Google Cloud project.LOCATION: The region where your AlloyDB cluster is located.CLUSTER_ID: The ID of your AlloyDB cluster.INSTANCE_ID: The ID of your AlloyDB instance.
Create a context set
To create a context set, perform the following steps:
In the Google Cloud console, go to the AlloyDB page.
Select a cluster from the list.
In the navigation menu, click AlloyDB Studio.
Sign in to Studio using IAM authentication.
In the Explorer pane, next to Context sets, click View actions.
Click Create context set.
In Context set name, provide a unique context set name. The context set name is case-sensitive and can contain letters, numbers, hyphens, and underscores. Names must be 4-30 characters.
The context set ID is derived from the context set name but is not necessarily identical. For the context set ID, the context set name is converted to lowercase and non-alphanumeric characters are replaced with the
-character. For example, the context set namequerydata_e2e_testhas the context set IDquerydata-e2e-test.Optional. In Context set description, add a description for your context set.
Optional. To upload a context set file, click Browse in the Upload context set file section, and select the context set file.
Click Create.
Build context sets
After creating a context set, follow the steps in Build contexts using Gemini CLI to create a context set file. You can then edit your context set to upload the context set file.
Edit a context set
To edit a context set, perform the following steps:
In the Google Cloud console, go to the AlloyDB page.
Select a cluster from the list.
In the navigation menu, click AlloyDB Studio.
Sign in to Studio using IAM authentication.
Click View actions next to the context set you want to edit.
Click Edit context set.
Optional. Edit Context set description.
Click Browse in the Upload context set file section, and select the context set file.
Click Save.
Delete a context set
To delete a context set, perform the following steps:
In the Google Cloud console, go to the AlloyDB page.
Select a cluster from the list.
In the navigation menu, click AlloyDB Studio.
Sign in to Studio using IAM authentication.
Click View actions next to the context set you want to delete.
Click Delete context set.
In the Delete context set confirmation dialog, enter the ID of the context set.
Click Confirm to delete the context set.
What's next
- Learn more about context sets.
- Learn how to test a context set.
- Learn how to build contexts using Gemini CLI.