Dokumente aus AlloyDB importieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Dokumente aus AlloyDB importieren
Weitere Informationen
Eine ausführliche Dokumentation, die dieses Codebeispiel enthält, finden Sie hier:
Codebeispiel
Nächste Schritte
Wenn Sie nach Codebeispielen für andere Google Cloud -Produkte suchen und filtern möchten, können Sie den Google Cloud -Beispielbrowser verwenden.
Sofern nicht anders angegeben, sind die Inhalte dieser Seite unter der Creative Commons Attribution 4.0 License und Codebeispiele unter der Apache 2.0 License lizenziert. Weitere Informationen finden Sie in den Websiterichtlinien von Google Developers. Java ist eine eingetragene Marke von Oracle und/oder seinen Partnern.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],[],[[["\u003cp\u003eThis code sample demonstrates how to import documents from AlloyDB into a Vertex AI Agent Builder data store using the \u003ccode\u003ediscoveryengine\u003c/code\u003e Python library.\u003c/p\u003e\n"],["\u003cp\u003eAuthentication to Vertex AI Agent Builder is required, and users can use Application Default Credentials for local development.\u003c/p\u003e\n"],["\u003cp\u003eThe code snippet provides parameters like project ID, location, data store ID, and AlloyDB details (project, location, cluster, database, and table IDs) for configuration.\u003c/p\u003e\n"],["\u003cp\u003eThe import process supports \u003ccode\u003eFULL\u003c/code\u003e or \u003ccode\u003eINCREMENTAL\u003c/code\u003e reconciliation modes and uses the \u003ccode\u003eImportDocumentsRequest\u003c/code\u003e function.\u003c/p\u003e\n"],["\u003cp\u003eThe location needs to be specified using the \u003ccode\u003eclient_options\u003c/code\u003e, and the specific multi-region is to be selected as well.\u003c/p\u003e\n"]]],[],null,["# Import documents from AlloyDB\n\nExplore further\n---------------\n\n\nFor detailed documentation that includes this code sample, see the following:\n\n- [Create a search data store](/generative-ai-app-builder/docs/create-data-store-es)\n\nCode sample\n-----------\n\n### Python\n\n\nFor more information, see the\n[AI Applications Python API\nreference documentation](/python/docs/reference/discoveryengine/latest).\n\n\nTo authenticate to AI Applications, set up Application Default Credentials.\nFor more information, see\n\n[Set up authentication for a local development environment](/docs/authentication/set-up-adc-local-dev-environment).\n\n from google.api_core.client_options import ClientOptions\n from google.cloud import discoveryengine_v1 as discoveryengine\n\n # TODO(developer): Uncomment these variables before running the sample.\n # project_id = \"YOUR_PROJECT_ID\"\n # location = \"YOUR_LOCATION\" # Values: \"global\"\n # data_store_id = \"YOUR_DATA_STORE_ID\"\n # alloy_db_project_id = \"YOUR_ALLOY_DB_PROJECT_ID\"\n # alloy_db_location_id = \"YOUR_ALLOY_DB_LOCATION_ID\"\n # alloy_db_cluster_id = \"YOUR_ALLOY_DB_CLUSTER_ID\"\n # alloy_db_database_id = \"YOUR_ALLOY_DB_DATABASE_ID\"\n # alloy_db_table_id = \"YOUR_ALLOY_DB_TABLE_ID\"\n\n # For more information, refer to:\n # https://cloud.google.com/generative-ai-app-builder/docs/locations#specify_a_multi-region_for_your_data_store\n client_options = (\n ClientOptions(api_endpoint=f\"{location}-discoveryengine.googleapis.com\")\n if location != \"global\"\n else None\n )\n\n # Create a client\n client = discoveryengine.DocumentServiceClient(client_options=client_options)\n\n # The full resource name of the search engine branch.\n # e.g. projects/{project}/locations/{location}/dataStores/{data_store_id}/branches/{branch}\n parent = client.branch_path(\n project=project_id,\n location=location,\n data_store=data_store_id,\n branch=\"default_branch\",\n )\n\n request = discoveryengine.ImportDocumentsRequest(\n parent=parent,\n alloy_db_source=discoveryengine.AlloyDbSource(\n project_id=alloy_db_project_id,\n location_id=alloy_db_location_id,\n cluster_id=alloy_db_cluster_id,\n database_id=alloy_db_database_id,\n table_id=alloy_db_table_id,\n ),\n # Options: `FULL`, `INCREMENTAL`\n reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,\n )\n\n # Make the request\n operation = client.import_documents(request=request)\n\n print(f\"Waiting for operation to complete: {operation.operation.name}\")\n response = operation.result()\n\n # After the operation is complete,\n # get information from operation metadata\n metadata = discoveryengine.ImportDocumentsMetadata(operation.metadata)\n\n # Handle the response\n print(response)\n print(metadata)\n\nWhat's next\n-----------\n\n\nTo search and filter code samples for other Google Cloud products, see the\n[Google Cloud sample browser](/docs/samples?product=genappbuilder)."]]