from google.api_core.client_options import ClientOptions
from google.cloud import discoveryengine, storage
# Variables
def GCS_import_datastore(project_id,location,data_store_id,gcs_files):
# Set client options
client_options = (
ClientOptions(api_endpoint=f"{location}-discoveryengine.googleapis.com")
if location != "global"
else None
)
# Create a client
client = discoveryengine.DocumentServiceClient(client_options=client_options)
# Set parent path
parent = client.branch_path(
project=project_id,
location=location,
data_store=data_store_id,
branch="default_branch",
)
# Request to import documents
request = discoveryengine.ImportDocumentsRequest(
parent=parent,
gcs_source=discoveryengine.GcsSource(
input_uris=gcs_files, # リスト化したファイルを指定
data_schema="content",
),
reconciliation_mode=discoveryengine.ImportDocumentsRequest.ReconciliationMode.INCREMENTAL,
)
# Make the request
operation = client.import_documents(request=request)
print(f"Waiting for operation to complete: {operation.operation.name}")
response = operation.result(timeout=6800)
# Handle the response
print("Response:", response)
データストアへファイルをアップロードするコードで発生したエラー
---------------------------------------------------------------------------
InvalidArgument Traceback (most recent call last)
Cell In[19], line 7
5 for i in range(100):
6 gcs_files.append(f"gs://{file_path}")
----> 7 GCS_import_datastore(project_id,location,data_store_id,gcs_files)
Cell In[18], line 41, in GCS_import_datastore(project_id, location, data_store_id, gcs_files)
38 operation = client.import_documents(request=request)
40 print(f"Waiting for operation to complete: {operation.operation.name}")
---> 41 response = operation.result(timeout=6800)
43 # Handle the response
44 print("Response:", response)
File /opt/anaconda3/envs/ab/lib/python3.11/site-packages/google/api_core/future/polling.py:261, in PollingFuture.result(self, timeout, retry, polling)
256 self._blocking_poll(timeout=timeout, retry=retry, polling=polling)
258 if self._exception is not None:
259 # pylint: disable=raising-bad-type
260 # Pylint doesn't recognize that this is valid in this case.
--> 261 raise self._exception
263 return self._result
InvalidArgument: 400 Custom Document Id (`_id`) was not found in document. 3: Custom Document Id (`_id`) was not found in document.