@@ -455,6 +455,81 @@ def import_documents_bigtable_sample(
455455 return operation .operation .name
456456
457457
458+ def import_documents_alloy_db_sample (
459+ project_id : str ,
460+ location : str ,
461+ data_store_id : str ,
462+ alloy_db_project_id : str ,
463+ alloy_db_location_id : str ,
464+ alloy_db_cluster_id : str ,
465+ alloy_db_database_id : str ,
466+ alloy_db_table_id : str ,
467+ ) -> str :
468+ # [START genappbuilder_import_documents_alloy_db]
469+ from google .api_core .client_options import ClientOptions
470+ from google .cloud import discoveryengine_v1 as discoveryengine
471+
472+ # TODO(developer): Uncomment these variables before running the sample.
473+ # project_id = "YOUR_PROJECT_ID"
474+ # location = "YOUR_LOCATION" # Values: "global"
475+ # data_store_id = "YOUR_DATA_STORE_ID"
476+ # alloy_db_project_id = "YOUR_ALLOY_DB_PROJECT_ID"
477+ # alloy_db_location_id = "YOUR_ALLOY_DB_LOCATION_ID"
478+ # alloy_db_cluster_id = "YOUR_ALLOY_DB_CLUSTER_ID"
479+ # alloy_db_database_id = "YOUR_ALLOY_DB_DATABASE_ID"
480+ # alloy_db_table_id = "YOUR_ALLOY_DB_TABLE_ID"
481+
482+ # For more information, refer to:
483+ # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store
484+ client_options = (
485+ ClientOptions (api_endpoint = f"{ location } -discoveryengine.googleapis.com" )
486+ if location != "global"
487+ else None
488+ )
489+
490+ # Create a client
491+ client = discoveryengine .DocumentServiceClient (client_options = client_options )
492+
493+ # The full resource name of the search engine branch.
494+ # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}
495+ parent = client .branch_path (
496+ project = project_id ,
497+ location = location ,
498+ data_store = data_store_id ,
499+ branch = "default_branch" ,
500+ )
501+
502+ request = discoveryengine .ImportDocumentsRequest (
503+ parent = parent ,
504+ alloy_db_source = discoveryengine .AlloyDbSource (
505+ project_id = alloy_db_project_id ,
506+ location_id = alloy_db_location_id ,
507+ cluster_id = alloy_db_cluster_id ,
508+ database_id = alloy_db_database_id ,
509+ table_id = alloy_db_table_id ,
510+ ),
511+ # Options: `FULL`, `INCREMENTAL`
512+ reconciliation_mode = discoveryengine .ImportDocumentsRequest .ReconciliationMode .INCREMENTAL ,
513+ )
514+
515+ # Make the request
516+ operation = client .import_documents (request = request )
517+
518+ print (f"Waiting for operation to complete: { operation .operation .name } " )
519+ response = operation .result ()
520+
521+ # Once the operation is complete,
522+ # get information from operation metadata
523+ metadata = discoveryengine .ImportDocumentsMetadata (operation .metadata )
524+
525+ # Handle the response
526+ print (response )
527+ print (metadata )
528+ # [END genappbuilder_import_documents_alloy_db]
529+
530+ return operation .operation .name
531+
532+
458533def import_documents_healthcare_fhir_sample (
459534 project_id : str ,
460535 location : str ,
@@ -500,7 +575,12 @@ def import_documents_healthcare_fhir_sample(
500575 request = discoveryengine .ImportDocumentsRequest (
501576 parent = parent ,
502577 fhir_store_source = discoveryengine .FhirStoreSource (
503- fhir_store = f"projects/{ healthcare_project_id } /locations/{ healthcare_location } /datasets/{ healthcare_dataset_id } /fhirStores/{ healthcare_fihr_store_id } " ,
578+ fhir_store = client .fhir_store_path (
579+ healthcare_project_id ,
580+ healthcare_location ,
581+ healthcare_dataset_id ,
582+ healthcare_fihr_store_id ,
583+ ),
504584 ),
505585 # Options: `FULL`, `INCREMENTAL`
506586 reconciliation_mode = discoveryengine .ImportDocumentsRequest .ReconciliationMode .INCREMENTAL ,
0 commit comments