This document describes how to create context sets in Spanner Studio using a context set file. Context set names must be unique within a database.
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 a Spanner instance
- Make sure that a Spanner instance is available. For more information, see Create an instance .
- Ensure that you create a database in your instance where you will create the tables. For more information, see Create a database on the Spanner instance
This tutorial requires you to have a database in your Spanner instance. For more information, see Create a database .
Required roles and permissions
- Add an IAM user or service account to the cluster. For more information, see Apply IAM roles .
- Grant the
spanner.databaseReaderandgeminidataanalytics.queryDataUserroles to the IAM user at the project level. For more information, see Add IAM policy binding for a project . - Grant roles and permissions to the IAM user at the project-level for the required databases.
Create a context set
To create a context set, perform the following steps:
-
In the Google Cloud console, go to the Spanner page.
-
Select an instance from the list, and then select a database.
-
In the navigation menu, click Spanner Studio.
-
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.
-
Optional. In Context set description, add a description for your context set.
-
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 Spanner page.
-
Select an instance from the list, and then select a database.
-
In the navigation menu, click Spanner Studio.
-
In the Explorer pane, next to Context sets, click View actions.
-
Click Edit context set.
-
Optional: Edit Context set description.
-
Click Browsein the Upload context set filesection, 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 Spanner page.
-
Select an instance from the list, and then select a database.
-
In the navigation menu, click Spanner Studio.
-
In the Explorer pane, next to Context sets, click View actions.
-
Click Delete context set.
-
In the Delete context setconfirmation dialog, enter the name of the context set.
-
Click Confirmto 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 .

