To give Agentspace access to Spanner data that is
in a different project, follow these steps:
Replace the following PROJECT_NUMBER variable with your
Agentspace project number, and then copy the contents of this
code block. This is your Agentspace service account
identifier:
Switch to your Spanner project on the IAM & Admin page
and click Grant Access.
For New principals, enter the identifier for the service account and
select one of the following:
If you won't use data boost during import, select the Cloud Spanner >
Cloud Spanner Database Reader role.
If you plan to use data boost during import, select the Cloud Spanner >
Cloud Spanner Database Admin role, or a custom role with the permissions of
Cloud Spanner Database Reader and spanner.databases.useDataBoost.
For information about Data Boost, see
Data Boost overview in the
Spanner documentation.
Specify the project ID, instance ID, database ID, and table ID of the data
that you plan to import.
Select whether to turn on Data Boost. For information about Data Boost, see
Data Boost overview in the
Spanner documentation.
Click Continue.
Choose a region for your data store.
Enter a name for your data store.
Click Create.
To check the status of your ingestion, go to the Data Stores page
and click your data store name to see details about it on its Data page.
When the status column on the Activity tab changes from In progress
to Import completed, the ingestion is complete.
Depending on the size of your data, ingestion can take several
minutes or several hours.
REST
To use the command line to create a data store and ingest data from
Spanner, follow these steps:
SPANNER_PROJECT_ID: the ID of your Spanner
project.
INSTANCE_ID: the ID of your Spanner instance.
DATABASE_ID: the ID of your Spanner database.
TABLE_ID: the ID of your Spanner table.
DATA_BOOST_BOOLEAN: optional. Whether to turn on Data Boost.
For information about Data Boost, see Data Boost
overview in the
Spanner documentation.
RECONCILIATION_MODE: optional. Values are
FULL and INCREMENTAL. Default is INCREMENTAL. Specifying
INCREMENTAL causes an incremental refresh of data from
Spanner to your data store. This does an upsert
operation, which adds new documents and replaces existing documents
with updated documents with the same ID. Specifying FULL causes a
full rebase of the documents in your data store. In other words, new
and updated documents are added to your data store, and documents that
are not in Spanner are removed from your data store. The
FULL mode is helpful if you want to automatically delete documents
that you no longer need.
AUTO_GENERATE_IDS: optional. Specifies whether to
automatically generate document IDs. If set to true, document IDs
are generated based on a hash of the payload. Note that generated
document IDs might not remain consistent over multiple imports. If
you auto-generate IDs over multiple imports, Google highly
recommends setting reconciliationMode to FULL to maintain
consistent document IDs.
ID_FIELD: optional. Specifies which fields are the
document IDs.
Next steps
To attach your data store to an app, create an app and select your data store
following the steps in
Create a search app.
To preview how your search results appear after your app and data store are
set up, see
Preview search results.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[],[],null,["# Import from Spanner (Public Preview)\n\n| **Note:** Importing data from Spanner is in Public preview.\n\nTo ingest data from Spanner, use the following steps to create\na data store and ingest data using either the Google Cloud console or the API.\n\nSet up Spanner access from a different project\n----------------------------------------------\n\nIf your Spanner data is in the same project as\nAgentspace, skip to [Import data from\nSpanner](#spanner-procedure).\n\nTo give Agentspace access to Spanner data that is\nin a different project, follow these steps:\n\n1. Replace the following \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e variable with your\n Agentspace project number, and then copy the contents of this\n code block. This is your Agentspace service account\n identifier:\n\n service-\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e@gcp-sa-discoveryengine.iam.gserviceaccount.com\n\n2. Go to the **IAM \\& Admin** page.\n\n [IAM \\& Admin](https://console.cloud.google.com/iam-admin/iam)\n3. Switch to your Spanner project on the **IAM \\& Admin** page\n and click **Grant Access**.\n\n4. For **New principals**, enter the identifier for the service account and\n select one of the following:\n\n - If you won't use data boost during import, select the **Cloud Spanner \\\u003e\n Cloud Spanner Database Reader** role.\n - If you plan to use data boost during import, select the **Cloud Spanner \\\u003e\n Cloud Spanner Database Admin** role, or a custom role with the permissions of **Cloud Spanner Database Reader** and **spanner.databases.useDataBoost** . For information about Data Boost, see [Data Boost overview](/spanner/docs/databoost/databoost-overview) in the Spanner documentation.\n5. Click **Save**.\n\nNext, go to [Import data from Spanner](#spanner-procedure).\n\nImport data from Spanner\n------------------------\n\n### Console\n\nTo use the console to ingest data from Spanner, follow these\nsteps:\n\n1. In the Google Cloud console, go to the **Agentspace** page.\n\n [Agentspace](https://console.cloud.google.com/gen-app-builder/)\n2. Go to the **Data Stores** page.\n\n3. Click **New data store**.\n\n4. On the **Source** page, select **Cloud Spanner**.\n\n5. Specify the project ID, instance ID, database ID, and table ID of the data\n that you plan to import.\n\n6. Select whether to turn on Data Boost. For information about Data Boost, see\n [Data Boost overview](/spanner/docs/databoost/databoost-overview) in the\n Spanner documentation.\n\n7. Click **Continue**.\n\n8. Choose a region for your data store.\n\n9. Enter a name for your data store.\n\n10. Click **Create**.\n\n11. To check the status of your ingestion, go to the **Data Stores** page\n and click your data store name to see details about it on its **Data** page.\n When the status column on the **Activity** tab changes from **In progress**\n to **Import completed**, the ingestion is complete.\n\n Depending on the size of your data, ingestion can take several\n minutes or several hours.\n\n### REST\n\nTo use the command line to create a data store and ingest data from\nSpanner, follow these steps:\n\n1. Create a data store.\n\n curl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n -H \"X-Goog-User-Project: \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\" \\\n \"https://discoveryengine.googleapis.com/v1alpha/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/collections/default_collection/dataStores?dataStoreId=\u003cvar translate=\"no\"\u003eDATA_STORE_ID\u003c/var\u003e\" \\\n -d '{\n \"displayName\": \"\u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e\",\n \"industryVertical\": \"GENERIC\",\n \"solutionTypes\": [\"SOLUTION_TYPE_SEARCH\"],\n \"contentConfig\": \"CONTENT_REQUIRED\",\n }'\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Agentspace project.\n - \u003cvar translate=\"no\"\u003eDATA_STORE_ID\u003c/var\u003e: the ID of the data store. The ID can contain only lowercase letters, digits, underscores, and hyphens.\n - \u003cvar translate=\"no\"\u003eDISPLAY_NAME\u003c/var\u003e: the display name of the data store. This might be displayed in the Google Cloud console.\n2. Import data from Spanner.\n\n curl -X POST \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Content-Type: application/json\" \\\n \"https://discoveryengine.googleapis.com/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/collections/default_collection/dataStores/\u003cvar translate=\"no\"\u003eDATA_STORE_ID\u003c/var\u003e/branches/0/documents:import\" \\\n -d '{\n \"cloudSpannerSource\": {\n \"projectId\": \"\u003cvar translate=\"no\"\u003eSPANNER_PROJECT_ID\u003c/var\u003e\",\n \"instanceId\": \"\u003cvar translate=\"no\"\u003eINSTANCE_ID\u003c/var\u003e\",\n \"databaseId\": \"\u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e\",\n \"tableId\": \"\u003cvar translate=\"no\"\u003eTABLE_ID\u003c/var\u003e\",\n \"enableDataBoost\": \"\u003cvar translate=\"no\"\u003eDATA_BOOST_BOOLEAN\u003c/var\u003e\"\n },\n \"reconciliationMode\": \"\u003cvar translate=\"no\"\u003eRECONCILIATION_MODE\u003c/var\u003e\",\n \"autoGenerateIds\": \"\u003cvar translate=\"no\"\u003eAUTO_GENERATE_IDS\u003c/var\u003e\",\n \"idField\": \"\u003cvar translate=\"no\"\u003eID_FIELD\u003c/var\u003e\",\n }'\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: the ID of your Agentspace project.\n - \u003cvar translate=\"no\"\u003eDATA_STORE_ID\u003c/var\u003e: the ID of the data store.\n - \u003cvar translate=\"no\"\u003eSPANNER_PROJECT_ID\u003c/var\u003e: the ID of your Spanner project.\n - \u003cvar translate=\"no\"\u003eINSTANCE_ID\u003c/var\u003e: the ID of your Spanner instance.\n - \u003cvar translate=\"no\"\u003eDATABASE_ID\u003c/var\u003e: the ID of your Spanner database.\n - \u003cvar translate=\"no\"\u003eTABLE_ID\u003c/var\u003e: the ID of your Spanner table.\n - \u003cvar translate=\"no\"\u003eDATA_BOOST_BOOLEAN\u003c/var\u003e: optional. Whether to turn on Data Boost. For information about Data Boost, see [Data Boost\n overview](/spanner/docs/databoost/databoost-overview) in the Spanner documentation.\n - \u003cvar translate=\"no\"\u003eRECONCILIATION_MODE\u003c/var\u003e: optional. Values are `FULL` and `INCREMENTAL`. Default is `INCREMENTAL`. Specifying `INCREMENTAL` causes an incremental refresh of data from Spanner to your data store. This does an upsert operation, which adds new documents and replaces existing documents with updated documents with the same ID. Specifying `FULL` causes a full rebase of the documents in your data store. In other words, new and updated documents are added to your data store, and documents that are not in Spanner are removed from your data store. The `FULL` mode is helpful if you want to automatically delete documents that you no longer need.\n - \u003cvar translate=\"no\"\u003eAUTO_GENERATE_IDS\u003c/var\u003e: optional. Specifies whether to\n automatically generate document IDs. If set to `true`, document IDs\n are generated based on a hash of the payload. Note that generated\n document IDs might not remain consistent over multiple imports. If\n you auto-generate IDs over multiple imports, Google highly\n recommends setting `reconciliationMode` to `FULL` to maintain\n consistent document IDs.\n\n - \u003cvar translate=\"no\"\u003eID_FIELD\u003c/var\u003e: optional. Specifies which fields are the\n document IDs.\n\n\n\u003cbr /\u003e\n\nNext steps\n----------\n\n- To attach your data store to an app, create an app and select your data store\n following the steps in\n [Create a search app](/agentspace/docs/create-app).\n\n- To preview how your search results appear after your app and data store are\n set up, see\n [Preview search results](/agentspace/docs/preview-search-results)."]]