When you use the context engineering agent, it can create and upload context sets automatically from your CLI. This document describes how to create, edit, and delete context sets in AlloyDB for PostgreSQL Studio when you want a visual interface in the Google Cloud console to manage context set files. When you create a context set in AlloyDB Studio, AlloyDB Studio stores it in the project's default context set group for the selected region and links it to the current database. Context set names (and their derived context set IDs) must be unique within the project's default context set group for a given region, across all databases and instances. In AlloyDB Studio, creating a context set with a name whose derived ID already exists fails validation; to overwrite its contents while keeping its database associations, edit the existing context set instead. Uploading directly through the context engineering agent or the Dataplex API with an existing context set ID replaces its contents and, if specified, its database associations.
The Context sets list in AlloyDB Studio shows only context sets in the default context set group across all supported regions that are linked to the current database. Context sets created for another database, or created through the API without linking the database resource in databases (or in a custom context set group), don't appear in the AlloyDB Studio list.
Before you begin
Complete the following prerequisites before creating or uploading a context set.
Context sets can be created in the us-central1, us-east1, europe-west4,
and asia-southeast1 regions.
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
- Enable Identity and Access Management (IAM) database authentication on the instance by setting the
alloydb.iam_authenticationdatabase flag toon(alloydb.iam_authentication=on). For more information, see Enable and disable IAM authentication. - Add an IAM user or service account to the cluster at the database level. For more information, see Manage IAM authentication.
- Grant the
roles/alloydb.databaseUser, theroles/serviceusage.serviceUsageConsumer, and theroles/geminidataanalytics.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. - You must also grant read-only database privileges to the IAM user or
service account.
GRANT SELECT ON ALL TABLES IN SCHEMA public TO "USER_NAME";
Replace USER_NAME with the email address for a user, or the service account address without the.gserviceaccount.comsuffix (for example,my-sa@my-project.iam). You must use quotes around the identifier because it contains special characters (@ and .).
For more information, see Grant appropriate database permissions to IAM users.
Grant executesql permission to AlloyDB for PostgreSQL instance
To grant the executesql permission to the AlloyDB for PostgreSQL instance and set
the dataApiAccess instance field to ENABLED (required for QueryData even though
the default allows some internal Google Cloud services such as AlloyDB Studio),
use the following curl command:
curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "Content-Type: application/json" \
-H "x-goog-user-project: PROJECT_ID" \
https://alloydb.googleapis.com/v1beta/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 AlloyDB 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. In AlloyDB Studio, the name must be 4 to 30 characters long and cannot begin with whitespace; Studio derives the context set ID by converting the name to lowercase and replacing non-alphanumeric characters with hyphens (
-), and the derived context set ID must be unique within the project'sdefaultcontext set group for the selected region. For example, the context set namequerydata_e2e_testhas the context set IDquerydata-e2e-test. When you upload a context set directly using the context engineering agent or the Dataplex API, the context set ID is case-sensitive, cannot contain slashes (/), and is not restricted to 4 to 30 characters or alphanumeric characters, hyphens, and underscores.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.
Optional. To choose a region for the context set, click Show Advanced Options and select a region in Select a location (defaults to
us-east1on each creation). If you choose a region other thanus-east1, select the region before entering the context set name so AlloyDB Studio validates name uniqueness in that region.Click Create.
Build context sets
If you created an empty context set in Studio, or want to update an existing one, follow the steps in Build and optimize context sets with the context engineering agent to generate and optimize a context set file. The context engineering agent can create and upload your context set directly from the CLI, or you can edit your context set in Studio to upload the context set file manually.
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 AlloyDB 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 AlloyDB 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 QueryData in AlloyDB Studio.
- Learn how to build and optimize context sets with the context engineering agent.
- Learn how to integrate QueryData with an application.