> [!WARNING]
>
> **Preview**
>
>
> This feature is
>
> subject to the "Pre-GA Offerings Terms" in the General Service Terms section of the
> [Service Specific
> Terms](https://docs.cloud.google.com/terms/service-terms#1), and the
> [Additional Terms for Generative AI
> Preview Products](https://cloud.google.com/trustedtester/aitos).
>
> Pre-GA features are available "as is" and might have limited support.
>
> For more information, see the
> [launch stage descriptions](https://cloud.google.com/products/#product-launch-stages).
>
>
> For information about access to this release, see the [access
> request page](https://forms.gle/pJByTWfenZAWbaXo7).


> [!WARNING]
> **PostgreSQL interface note:** The examples in this topic are intended for GoogleSQL-dialect databases. This feature doesn't support PostgreSQL interface.

<br />

This document describes how to create, edit, and delete context sets for Spanner Graph in Spanner Studio using a context set file. Context set names must be unique within a database.

To learn about context sets for Spanner Graph, see [Context sets overview](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner-graph/context-sets-overview.md.txt).

## Before you begin

Complete the following prerequisites before creating a context set:

### Enable required services

Enable the following services for your project:

- [Data Analytics API with Gemini](https://console.cloud.google.com/apis/library/geminidataanalytics.googleapis.com)
- [Gemini for Google Cloud API](https://console.cloud.google.com/apis/library/cloudaicompanion.googleapis.com)
- [Knowledge Catalog API](https://console.cloud.google.com/apis/library/dataplex.googleapis.com)

### Prepare a Spanner instance

- Make sure that a Spanner instance is available. For more information, see [Create an instance](https://docs.cloud.google.com/spanner/docs/create-manage-instances.md.txt).
- 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](https://docs.cloud.google.com/spanner/docs/create-manage-databases#create-database).

### Required roles and permissions

- Add an IAM user or service account to the instance. For more information, see [Apply IAM roles](https://docs.cloud.google.com/spanner/docs/grant-permissions.md.txt).
- Grant the `roles/spanner.databaseReader`, `roles/serviceusage.serviceUsageConsumer`, and `roles/geminidataanalytics.queryDataUser` roles to the IAM user at the project level. For more information, see [Add IAM policy binding for a project](https://docs.cloud.google.com/sdk/gcloud/reference/projects/add-iam-policy-binding).
- 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](https://docs.cloud.google.com/knowledge-catalog/docs/iam-permissions.md.txt#context-set-permissions).
- [Grant roles and permissions](https://docs.cloud.google.com/spanner/docs/grant-permissions.md.txt#project-level_permissions) to the IAM user at the project-level for the required databases.

> [!WARNING]
> **Warning:** All context sets associated with a database are viewable to all users with any read access to that database. In cases where users have narrower access to the database, such as Spanner fine-grained access control, users can potentially discover other fields and tables from the context set.

To create an example property graph schema and insert sample graph data in your Spanner database, see [Set up and query Spanner Graph](https://docs.cloud.google.com/spanner/docs/graph/set-up.md.txt).

## Create a context set

To create a context set, perform the following steps:

1. In the Google Cloud console, go to the Spanner page.

   [Go to Spanner](https://console.cloud.google.com/spanner)
2. Select an instance from the list, and then select your Spanner database.

3. In the navigation menu, click **Spanner Studio**.

4. In the **Explorer** pane, next to **Context sets** , click **View actions**.

5. Click **Create context set**.

6. In the **Context set name** field, enter a unique context set name (for example, `fingraph-assistant`). The context set name is case-sensitive and can contain letters, numbers, hyphens, and underscores.

7. Optional: In the **Context set description** field, add a description for your context set.

8. Click **Create**.

> [!NOTE]
> **Note:** Creating the first context set in a project can take several minutes.

## Build context sets

After creating a context set, follow the steps in [Build context sets using the context engineering agent](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner-graph/build-context-sets.md.txt) to create a context set file for your property graph. You can then edit your context set to upload the context set file.

## Edit a context set

To edit a context set and upload a context set file, perform the following steps:

1. In the Google Cloud console, go to the Spanner page.

   [Go to Spanner](https://console.cloud.google.com/spanner)
2. Select an instance from the list, and then select a database.

3. In the navigation menu, click **Spanner Studio**.

4. In the **Explorer** pane, next to **Context sets** , click **View actions**.

5. Click **Edit context set**.

6. Optional: Edit the **Context set description** field.

7. Click **Browse** in the **Upload context set file** section, and select your context set JSON file.

8. Click **Save**.

## Delete a context set

To delete a context set, perform the following steps:

1. In the Google Cloud console, go to the Spanner page.

   [Go to Spanner](https://console.cloud.google.com/spanner)
2. Select an instance from the list, and then select a database.

3. In the navigation menu, click **Spanner Studio**.

4. In the **Explorer** pane, next to **Context sets** , click **View actions**.

5. Click **Delete context set**.

6. In the **Delete context set** confirmation dialog, enter the name of the context set.

7. Click **Confirm** to delete the context set.

> [!NOTE]
> **Note:** Before you delete a database, you must delete all context sets associated with that database.

## What's next

- Learn more about [context sets](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner-graph/context-sets-overview.md.txt).
- Learn how to [test QueryData for Spanner Graph](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner-graph/inspect-data-agent.md.txt).
- Learn how to [build context sets using the context engineering agent](https://docs.cloud.google.com/gemini/data-agents/querydata/spanner-graph/build-context-sets.md.txt).