google-cloud-agentplatform 1.165.1.dev0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. agentplatform/__init__.py +72 -0
  2. agentplatform/_genai/__init__.py +43 -0
  3. agentplatform/_genai/_agent_engines_utils.py +2341 -0
  4. agentplatform/_genai/_bigquery_utils.py +49 -0
  5. agentplatform/_genai/_datasets_utils.py +344 -0
  6. agentplatform/_genai/_evals_builtin_tools.py +209 -0
  7. agentplatform/_genai/_evals_common.py +4268 -0
  8. agentplatform/_genai/_evals_constant.py +122 -0
  9. agentplatform/_genai/_evals_data_converters.py +926 -0
  10. agentplatform/_genai/_evals_metric_handlers.py +1783 -0
  11. agentplatform/_genai/_evals_metric_loaders.py +401 -0
  12. agentplatform/_genai/_evals_utils.py +1043 -0
  13. agentplatform/_genai/_evals_visualization.py +2070 -0
  14. agentplatform/_genai/_gcs_utils.py +262 -0
  15. agentplatform/_genai/_logging_utils.py +47 -0
  16. agentplatform/_genai/_memory_bank_utils.py +206 -0
  17. agentplatform/_genai/_observability_data_converter.py +186 -0
  18. agentplatform/_genai/_operations_utils.py +94 -0
  19. agentplatform/_genai/_prompt_management_utils.py +147 -0
  20. agentplatform/_genai/_prompt_optimizer_utils.py +215 -0
  21. agentplatform/_genai/_skills_utils.py +69 -0
  22. agentplatform/_genai/_transformers.py +628 -0
  23. agentplatform/_genai/a2a_task_events.py +509 -0
  24. agentplatform/_genai/a2a_tasks.py +861 -0
  25. agentplatform/_genai/agent_engines.py +3931 -0
  26. agentplatform/_genai/client.py +519 -0
  27. agentplatform/_genai/datasets.py +3045 -0
  28. agentplatform/_genai/endpoints.py +1149 -0
  29. agentplatform/_genai/evals.py +6883 -0
  30. agentplatform/_genai/example_stores.py +1445 -0
  31. agentplatform/_genai/feedback_contexts.py +700 -0
  32. agentplatform/_genai/feedback_entries.py +1644 -0
  33. agentplatform/_genai/live.py +64 -0
  34. agentplatform/_genai/live_agent_engines.py +179 -0
  35. agentplatform/_genai/memories.py +2962 -0
  36. agentplatform/_genai/memory_banks.py +1927 -0
  37. agentplatform/_genai/memory_revisions.py +465 -0
  38. agentplatform/_genai/model_garden.py +2638 -0
  39. agentplatform/_genai/prompt_optimizer.py +995 -0
  40. agentplatform/_genai/prompts.py +4515 -0
  41. agentplatform/_genai/rag.py +4961 -0
  42. agentplatform/_genai/runtime_revisions.py +1257 -0
  43. agentplatform/_genai/runtimes.py +78 -0
  44. agentplatform/_genai/sandbox_snapshots.py +1015 -0
  45. agentplatform/_genai/sandbox_templates.py +1088 -0
  46. agentplatform/_genai/sandboxes.py +1604 -0
  47. agentplatform/_genai/session_events.py +543 -0
  48. agentplatform/_genai/sessions.py +1449 -0
  49. agentplatform/_genai/skill_revisions.py +377 -0
  50. agentplatform/_genai/skills.py +1708 -0
  51. agentplatform/_genai/types/__init__.py +4695 -0
  52. agentplatform/_genai/types/agent_engines.py +16 -0
  53. agentplatform/_genai/types/common.py +32784 -0
  54. agentplatform/_genai/types/evals.py +1031 -0
  55. agentplatform/_genai/types/prompt_optimizer.py +107 -0
  56. agentplatform/_genai/types/prompts.py +107 -0
  57. agentplatform/version.py +17 -0
  58. google_cloud_agentplatform-1.165.1.dev0.dist-info/METADATA +79 -0
  59. google_cloud_agentplatform-1.165.1.dev0.dist-info/RECORD +62 -0
  60. google_cloud_agentplatform-1.165.1.dev0.dist-info/WHEEL +5 -0
  61. google_cloud_agentplatform-1.165.1.dev0.dist-info/licenses/LICENSE +202 -0
  62. google_cloud_agentplatform-1.165.1.dev0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,4961 @@
1
+ # Copyright 2025 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ #
15
+
16
+ # Code generated by the Google Gen AI SDK generator DO NOT EDIT.
17
+
18
+ import json
19
+ import logging
20
+ import mimetypes
21
+ import os
22
+ from typing import Any, Optional, Union
23
+ from urllib.parse import urlencode
24
+
25
+ from google.genai import _api_module
26
+ from google.genai import _common
27
+ from google.genai import _extra_utils
28
+ from google.genai import types as genai_types
29
+ from google.genai._common import get_value_by_path as getv
30
+ from google.genai._common import set_value_by_path as setv
31
+
32
+ from . import _gcs_utils
33
+ from . import _operations_utils
34
+ from . import types
35
+
36
+ logger = logging.getLogger("agentplatform_genai.rag")
37
+
38
+
39
+ def _AskContextsConfig_to_vertex(
40
+ from_object: Union[dict[str, Any], object],
41
+ parent_object: Optional[dict[str, Any]] = None,
42
+ ) -> dict[str, Any]:
43
+ to_object: dict[str, Any] = {}
44
+
45
+ if getv(from_object, ["tools"]) is not None:
46
+ setv(parent_object, ["tools"], getv(from_object, ["tools"]))
47
+
48
+ return to_object
49
+
50
+
51
+ def _AskContextsRequestParameters_to_vertex(
52
+ from_object: Union[dict[str, Any], object],
53
+ parent_object: Optional[dict[str, Any]] = None,
54
+ ) -> dict[str, Any]:
55
+ to_object: dict[str, Any] = {}
56
+ if getv(from_object, ["query"]) is not None:
57
+ setv(to_object, ["query"], getv(from_object, ["query"]))
58
+
59
+ if getv(from_object, ["config"]) is not None:
60
+ setv(
61
+ to_object,
62
+ ["config"],
63
+ _AskContextsConfig_to_vertex(getv(from_object, ["config"]), to_object),
64
+ )
65
+
66
+ return to_object
67
+
68
+
69
+ def _CorpusOperation_from_vertex(
70
+ from_object: Union[dict[str, Any], object],
71
+ parent_object: Optional[dict[str, Any]] = None,
72
+ ) -> dict[str, Any]:
73
+ to_object: dict[str, Any] = {}
74
+ if getv(from_object, ["name"]) is not None:
75
+ setv(to_object, ["name"], getv(from_object, ["name"]))
76
+
77
+ if getv(from_object, ["metadata"]) is not None:
78
+ setv(to_object, ["metadata"], getv(from_object, ["metadata"]))
79
+
80
+ if getv(from_object, ["done"]) is not None:
81
+ setv(to_object, ["done"], getv(from_object, ["done"]))
82
+
83
+ if getv(from_object, ["error"]) is not None:
84
+ setv(to_object, ["error"], getv(from_object, ["error"]))
85
+
86
+ if getv(from_object, ["response"]) is not None:
87
+ setv(
88
+ to_object,
89
+ ["response"],
90
+ _RagCorpus_from_vertex(getv(from_object, ["response"]), to_object),
91
+ )
92
+
93
+ return to_object
94
+
95
+
96
+ def _CreateRagCorpusRequestParameters_to_vertex(
97
+ from_object: Union[dict[str, Any], object],
98
+ parent_object: Optional[dict[str, Any]] = None,
99
+ ) -> dict[str, Any]:
100
+ to_object: dict[str, Any] = {}
101
+ if getv(from_object, ["rag_corpus"]) is not None:
102
+ setv(
103
+ to_object,
104
+ ["_self"],
105
+ _RagCorpus_to_vertex(getv(from_object, ["rag_corpus"]), to_object),
106
+ )
107
+
108
+ if getv(from_object, ["config"]) is not None:
109
+ setv(to_object, ["config"], getv(from_object, ["config"]))
110
+
111
+ return to_object
112
+
113
+
114
+ def _DeleteRagCorpusRequestParameters_to_vertex(
115
+ from_object: Union[dict[str, Any], object],
116
+ parent_object: Optional[dict[str, Any]] = None,
117
+ ) -> dict[str, Any]:
118
+ to_object: dict[str, Any] = {}
119
+ if getv(from_object, ["config"]) is not None:
120
+ setv(to_object, ["config"], getv(from_object, ["config"]))
121
+
122
+ if getv(from_object, ["name"]) is not None:
123
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
124
+
125
+ return to_object
126
+
127
+
128
+ def _DeleteRagFileRequestParameters_to_vertex(
129
+ from_object: Union[dict[str, Any], object],
130
+ parent_object: Optional[dict[str, Any]] = None,
131
+ ) -> dict[str, Any]:
132
+ to_object: dict[str, Any] = {}
133
+ if getv(from_object, ["config"]) is not None:
134
+ setv(to_object, ["config"], getv(from_object, ["config"]))
135
+
136
+ if getv(from_object, ["name"]) is not None:
137
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
138
+
139
+ return to_object
140
+
141
+
142
+ def _GetCorpusOperationParameters_to_vertex(
143
+ from_object: Union[dict[str, Any], object],
144
+ parent_object: Optional[dict[str, Any]] = None,
145
+ ) -> dict[str, Any]:
146
+ to_object: dict[str, Any] = {}
147
+ if getv(from_object, ["operation_name"]) is not None:
148
+ setv(
149
+ to_object, ["_url", "operationName"], getv(from_object, ["operation_name"])
150
+ )
151
+
152
+ return to_object
153
+
154
+
155
+ def _GetImportFilesOperationParameters_to_vertex(
156
+ from_object: Union[dict[str, Any], object],
157
+ parent_object: Optional[dict[str, Any]] = None,
158
+ ) -> dict[str, Any]:
159
+ to_object: dict[str, Any] = {}
160
+ if getv(from_object, ["operation_name"]) is not None:
161
+ setv(
162
+ to_object, ["_url", "operation_name"], getv(from_object, ["operation_name"])
163
+ )
164
+
165
+ return to_object
166
+
167
+
168
+ def _GetRagConfigOperationParameters_to_vertex(
169
+ from_object: Union[dict[str, Any], object],
170
+ parent_object: Optional[dict[str, Any]] = None,
171
+ ) -> dict[str, Any]:
172
+ to_object: dict[str, Any] = {}
173
+ if getv(from_object, ["operation_name"]) is not None:
174
+ setv(
175
+ to_object, ["_url", "operation_name"], getv(from_object, ["operation_name"])
176
+ )
177
+
178
+ return to_object
179
+
180
+
181
+ def _GetRagConfigRequestParameters_to_vertex(
182
+ from_object: Union[dict[str, Any], object],
183
+ parent_object: Optional[dict[str, Any]] = None,
184
+ ) -> dict[str, Any]:
185
+ to_object: dict[str, Any] = {}
186
+ if getv(from_object, ["config"]) is not None:
187
+ setv(to_object, ["config"], getv(from_object, ["config"]))
188
+
189
+ return to_object
190
+
191
+
192
+ def _GetRagCorpusRequestParameters_to_vertex(
193
+ from_object: Union[dict[str, Any], object],
194
+ parent_object: Optional[dict[str, Any]] = None,
195
+ ) -> dict[str, Any]:
196
+ to_object: dict[str, Any] = {}
197
+ if getv(from_object, ["config"]) is not None:
198
+ setv(to_object, ["config"], getv(from_object, ["config"]))
199
+
200
+ if getv(from_object, ["name"]) is not None:
201
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
202
+
203
+ return to_object
204
+
205
+
206
+ def _GetRagFileRequestParameters_to_vertex(
207
+ from_object: Union[dict[str, Any], object],
208
+ parent_object: Optional[dict[str, Any]] = None,
209
+ ) -> dict[str, Any]:
210
+ to_object: dict[str, Any] = {}
211
+ if getv(from_object, ["config"]) is not None:
212
+ setv(to_object, ["config"], getv(from_object, ["config"]))
213
+
214
+ if getv(from_object, ["name"]) is not None:
215
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
216
+
217
+ return to_object
218
+
219
+
220
+ def _ImportRagFilesConfig_to_vertex(
221
+ from_object: Union[dict[str, Any], object],
222
+ parent_object: Optional[dict[str, Any]] = None,
223
+ ) -> dict[str, Any]:
224
+ to_object: dict[str, Any] = {}
225
+ if getv(from_object, ["gcs_source"]) is not None:
226
+ setv(to_object, ["gcsSource"], getv(from_object, ["gcs_source"]))
227
+
228
+ if getv(from_object, ["global_max_embedding_requests_per_min"]) is not None:
229
+ setv(
230
+ to_object,
231
+ ["globalMaxEmbeddingRequestsPerMin"],
232
+ getv(from_object, ["global_max_embedding_requests_per_min"]),
233
+ )
234
+
235
+ if getv(from_object, ["google_drive_source"]) is not None:
236
+ setv(
237
+ to_object, ["googleDriveSource"], getv(from_object, ["google_drive_source"])
238
+ )
239
+
240
+ if getv(from_object, ["import_result_bigquery_sink"]) is not None:
241
+ setv(
242
+ to_object,
243
+ ["importResultBigquerySink"],
244
+ getv(from_object, ["import_result_bigquery_sink"]),
245
+ )
246
+
247
+ if getv(from_object, ["import_result_gcs_sink"]) is not None:
248
+ setv(
249
+ to_object,
250
+ ["importResultGcsSink"],
251
+ getv(from_object, ["import_result_gcs_sink"]),
252
+ )
253
+
254
+ if getv(from_object, ["jira_source"]) is not None:
255
+ setv(to_object, ["jiraSource"], getv(from_object, ["jira_source"]))
256
+
257
+ if getv(from_object, ["max_embedding_requests_per_min"]) is not None:
258
+ setv(
259
+ to_object,
260
+ ["maxEmbeddingRequestsPerMin"],
261
+ getv(from_object, ["max_embedding_requests_per_min"]),
262
+ )
263
+
264
+ if getv(from_object, ["partial_failure_bigquery_sink"]) is not None:
265
+ setv(
266
+ to_object,
267
+ ["partialFailureBigquerySink"],
268
+ getv(from_object, ["partial_failure_bigquery_sink"]),
269
+ )
270
+
271
+ if getv(from_object, ["partial_failure_gcs_sink"]) is not None:
272
+ setv(
273
+ to_object,
274
+ ["partialFailureGcsSink"],
275
+ getv(from_object, ["partial_failure_gcs_sink"]),
276
+ )
277
+
278
+ if getv(from_object, ["rag_file_chunking_config"]) is not None:
279
+ setv(
280
+ to_object,
281
+ ["ragFileChunkingConfig"],
282
+ getv(from_object, ["rag_file_chunking_config"]),
283
+ )
284
+
285
+ if getv(from_object, ["rag_file_metadata_config"]) is not None:
286
+ setv(
287
+ to_object,
288
+ ["ragFileMetadataConfig"],
289
+ getv(from_object, ["rag_file_metadata_config"]),
290
+ )
291
+
292
+ if getv(from_object, ["rag_file_parsing_config"]) is not None:
293
+ setv(
294
+ to_object,
295
+ ["ragFileParsingConfig"],
296
+ _RagFileParsingConfig_to_vertex(
297
+ getv(from_object, ["rag_file_parsing_config"]), to_object
298
+ ),
299
+ )
300
+
301
+ if getv(from_object, ["rag_file_transformation_config"]) is not None:
302
+ setv(
303
+ to_object,
304
+ ["ragFileTransformationConfig"],
305
+ getv(from_object, ["rag_file_transformation_config"]),
306
+ )
307
+
308
+ if getv(from_object, ["rebuild_ann_index"]) is not None:
309
+ setv(to_object, ["rebuildAnnIndex"], getv(from_object, ["rebuild_ann_index"]))
310
+
311
+ if getv(from_object, ["share_point_sources"]) is not None:
312
+ setv(
313
+ to_object, ["sharePointSources"], getv(from_object, ["share_point_sources"])
314
+ )
315
+
316
+ if getv(from_object, ["slack_source"]) is not None:
317
+ setv(to_object, ["slackSource"], getv(from_object, ["slack_source"]))
318
+
319
+ return to_object
320
+
321
+
322
+ def _ImportRagFilesRequestParameters_to_vertex(
323
+ from_object: Union[dict[str, Any], object],
324
+ parent_object: Optional[dict[str, Any]] = None,
325
+ ) -> dict[str, Any]:
326
+ to_object: dict[str, Any] = {}
327
+ if getv(from_object, ["name"]) is not None:
328
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
329
+
330
+ if getv(from_object, ["import_rag_files_request"]) is not None:
331
+ setv(
332
+ to_object,
333
+ ["_self"],
334
+ _ImportRagFilesRequest_to_vertex(
335
+ getv(from_object, ["import_rag_files_request"]), to_object
336
+ ),
337
+ )
338
+
339
+ if getv(from_object, ["config"]) is not None:
340
+ setv(to_object, ["config"], getv(from_object, ["config"]))
341
+
342
+ return to_object
343
+
344
+
345
+ def _ImportRagFilesRequest_to_vertex(
346
+ from_object: Union[dict[str, Any], object],
347
+ parent_object: Optional[dict[str, Any]] = None,
348
+ ) -> dict[str, Any]:
349
+ to_object: dict[str, Any] = {}
350
+ if getv(from_object, ["import_rag_files_config"]) is not None:
351
+ setv(
352
+ to_object,
353
+ ["importRagFilesConfig"],
354
+ _ImportRagFilesConfig_to_vertex(
355
+ getv(from_object, ["import_rag_files_config"]), to_object
356
+ ),
357
+ )
358
+
359
+ return to_object
360
+
361
+
362
+ def _ListRagCorporaConfig_to_vertex(
363
+ from_object: Union[dict[str, Any], object],
364
+ parent_object: Optional[dict[str, Any]] = None,
365
+ ) -> dict[str, Any]:
366
+ to_object: dict[str, Any] = {}
367
+
368
+ if getv(from_object, ["page_size"]) is not None:
369
+ setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
370
+
371
+ if getv(from_object, ["page_token"]) is not None:
372
+ setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
373
+
374
+ return to_object
375
+
376
+
377
+ def _ListRagCorporaRequestParameters_to_vertex(
378
+ from_object: Union[dict[str, Any], object],
379
+ parent_object: Optional[dict[str, Any]] = None,
380
+ ) -> dict[str, Any]:
381
+ to_object: dict[str, Any] = {}
382
+ if getv(from_object, ["config"]) is not None:
383
+ setv(
384
+ to_object,
385
+ ["config"],
386
+ _ListRagCorporaConfig_to_vertex(getv(from_object, ["config"]), to_object),
387
+ )
388
+
389
+ return to_object
390
+
391
+
392
+ def _ListRagCorporaResponse_from_vertex(
393
+ from_object: Union[dict[str, Any], object],
394
+ parent_object: Optional[dict[str, Any]] = None,
395
+ ) -> dict[str, Any]:
396
+ to_object: dict[str, Any] = {}
397
+ if getv(from_object, ["sdkHttpResponse"]) is not None:
398
+ setv(to_object, ["sdk_http_response"], getv(from_object, ["sdkHttpResponse"]))
399
+
400
+ if getv(from_object, ["nextPageToken"]) is not None:
401
+ setv(to_object, ["next_page_token"], getv(from_object, ["nextPageToken"]))
402
+
403
+ if getv(from_object, ["ragCorpora"]) is not None:
404
+ setv(
405
+ to_object,
406
+ ["rag_corpora"],
407
+ [
408
+ _RagCorpus_from_vertex(item, to_object)
409
+ for item in getv(from_object, ["ragCorpora"])
410
+ ],
411
+ )
412
+
413
+ return to_object
414
+
415
+
416
+ def _ListRagFilesConfig_to_vertex(
417
+ from_object: Union[dict[str, Any], object],
418
+ parent_object: Optional[dict[str, Any]] = None,
419
+ ) -> dict[str, Any]:
420
+ to_object: dict[str, Any] = {}
421
+
422
+ if getv(from_object, ["page_size"]) is not None:
423
+ setv(parent_object, ["_query", "pageSize"], getv(from_object, ["page_size"]))
424
+
425
+ if getv(from_object, ["page_token"]) is not None:
426
+ setv(parent_object, ["_query", "pageToken"], getv(from_object, ["page_token"]))
427
+
428
+ return to_object
429
+
430
+
431
+ def _ListRagFilesRequestParameters_to_vertex(
432
+ from_object: Union[dict[str, Any], object],
433
+ parent_object: Optional[dict[str, Any]] = None,
434
+ ) -> dict[str, Any]:
435
+ to_object: dict[str, Any] = {}
436
+ if getv(from_object, ["config"]) is not None:
437
+ setv(
438
+ to_object,
439
+ ["config"],
440
+ _ListRagFilesConfig_to_vertex(getv(from_object, ["config"]), to_object),
441
+ )
442
+
443
+ if getv(from_object, ["name"]) is not None:
444
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
445
+
446
+ return to_object
447
+
448
+
449
+ def _RagCorpusCorpusTypeConfigMemoryCorpus_from_vertex(
450
+ from_object: Union[dict[str, Any], object],
451
+ parent_object: Optional[dict[str, Any]] = None,
452
+ ) -> dict[str, Any]:
453
+ to_object: dict[str, Any] = {}
454
+ if getv(from_object, ["llmParser"]) is not None:
455
+ setv(
456
+ to_object,
457
+ ["llm_parser"],
458
+ _RagFileParsingConfigLlmParser_from_vertex(
459
+ getv(from_object, ["llmParser"]), to_object
460
+ ),
461
+ )
462
+
463
+ return to_object
464
+
465
+
466
+ def _RagCorpusCorpusTypeConfigMemoryCorpus_to_vertex(
467
+ from_object: Union[dict[str, Any], object],
468
+ parent_object: Optional[dict[str, Any]] = None,
469
+ ) -> dict[str, Any]:
470
+ to_object: dict[str, Any] = {}
471
+ if getv(from_object, ["llm_parser"]) is not None:
472
+ setv(
473
+ to_object,
474
+ ["llmParser"],
475
+ _RagFileParsingConfigLlmParser_to_vertex(
476
+ getv(from_object, ["llm_parser"]), to_object
477
+ ),
478
+ )
479
+
480
+ return to_object
481
+
482
+
483
+ def _RagCorpusCorpusTypeConfig_from_vertex(
484
+ from_object: Union[dict[str, Any], object],
485
+ parent_object: Optional[dict[str, Any]] = None,
486
+ ) -> dict[str, Any]:
487
+ to_object: dict[str, Any] = {}
488
+ if getv(from_object, ["documentCorpus"]) is not None:
489
+ setv(to_object, ["document_corpus"], getv(from_object, ["documentCorpus"]))
490
+
491
+ if getv(from_object, ["memoryCorpus"]) is not None:
492
+ setv(
493
+ to_object,
494
+ ["memory_corpus"],
495
+ _RagCorpusCorpusTypeConfigMemoryCorpus_from_vertex(
496
+ getv(from_object, ["memoryCorpus"]), to_object
497
+ ),
498
+ )
499
+
500
+ return to_object
501
+
502
+
503
+ def _RagCorpusCorpusTypeConfig_to_vertex(
504
+ from_object: Union[dict[str, Any], object],
505
+ parent_object: Optional[dict[str, Any]] = None,
506
+ ) -> dict[str, Any]:
507
+ to_object: dict[str, Any] = {}
508
+ if getv(from_object, ["document_corpus"]) is not None:
509
+ setv(to_object, ["documentCorpus"], getv(from_object, ["document_corpus"]))
510
+
511
+ if getv(from_object, ["memory_corpus"]) is not None:
512
+ setv(
513
+ to_object,
514
+ ["memoryCorpus"],
515
+ _RagCorpusCorpusTypeConfigMemoryCorpus_to_vertex(
516
+ getv(from_object, ["memory_corpus"]), to_object
517
+ ),
518
+ )
519
+
520
+ return to_object
521
+
522
+
523
+ def _RagCorpus_from_vertex(
524
+ from_object: Union[dict[str, Any], object],
525
+ parent_object: Optional[dict[str, Any]] = None,
526
+ ) -> dict[str, Any]:
527
+ to_object: dict[str, Any] = {}
528
+ if getv(from_object, ["corpusStatus"]) is not None:
529
+ setv(to_object, ["corpus_status"], getv(from_object, ["corpusStatus"]))
530
+
531
+ if getv(from_object, ["corpusTypeConfig"]) is not None:
532
+ setv(
533
+ to_object,
534
+ ["corpus_type_config"],
535
+ _RagCorpusCorpusTypeConfig_from_vertex(
536
+ getv(from_object, ["corpusTypeConfig"]), to_object
537
+ ),
538
+ )
539
+
540
+ if getv(from_object, ["createTime"]) is not None:
541
+ setv(to_object, ["create_time"], getv(from_object, ["createTime"]))
542
+
543
+ if getv(from_object, ["description"]) is not None:
544
+ setv(to_object, ["description"], getv(from_object, ["description"]))
545
+
546
+ if getv(from_object, ["displayName"]) is not None:
547
+ setv(to_object, ["display_name"], getv(from_object, ["displayName"]))
548
+
549
+ if getv(from_object, ["encryptionSpec"]) is not None:
550
+ setv(to_object, ["encryption_spec"], getv(from_object, ["encryptionSpec"]))
551
+
552
+ if getv(from_object, ["name"]) is not None:
553
+ setv(to_object, ["name"], getv(from_object, ["name"]))
554
+
555
+ if getv(from_object, ["ragEmbeddingModelConfig"]) is not None:
556
+ setv(
557
+ to_object,
558
+ ["rag_embedding_model_config"],
559
+ _RagEmbeddingModelConfig_from_vertex(
560
+ getv(from_object, ["ragEmbeddingModelConfig"]), to_object
561
+ ),
562
+ )
563
+
564
+ if getv(from_object, ["ragFilesCount"]) is not None:
565
+ setv(to_object, ["rag_files_count"], getv(from_object, ["ragFilesCount"]))
566
+
567
+ if getv(from_object, ["ragVectorDbConfig"]) is not None:
568
+ setv(
569
+ to_object,
570
+ ["rag_vector_db_config"],
571
+ _RagVectorDbConfig_from_vertex(
572
+ getv(from_object, ["ragVectorDbConfig"]), to_object
573
+ ),
574
+ )
575
+
576
+ if getv(from_object, ["satisfiesPzi"]) is not None:
577
+ setv(to_object, ["satisfies_pzi"], getv(from_object, ["satisfiesPzi"]))
578
+
579
+ if getv(from_object, ["satisfiesPzs"]) is not None:
580
+ setv(to_object, ["satisfies_pzs"], getv(from_object, ["satisfiesPzs"]))
581
+
582
+ if getv(from_object, ["updateTime"]) is not None:
583
+ setv(to_object, ["update_time"], getv(from_object, ["updateTime"]))
584
+
585
+ if getv(from_object, ["vectorDbConfig"]) is not None:
586
+ setv(
587
+ to_object,
588
+ ["vector_db_config"],
589
+ _RagVectorDbConfig_from_vertex(
590
+ getv(from_object, ["vectorDbConfig"]), to_object
591
+ ),
592
+ )
593
+
594
+ if getv(from_object, ["vertexAiSearchConfig"]) is not None:
595
+ setv(
596
+ to_object,
597
+ ["vertex_ai_search_config"],
598
+ _VertexAiSearchConfig_from_vertex(
599
+ getv(from_object, ["vertexAiSearchConfig"]), to_object
600
+ ),
601
+ )
602
+
603
+ return to_object
604
+
605
+
606
+ def _RagCorpus_to_vertex(
607
+ from_object: Union[dict[str, Any], object],
608
+ parent_object: Optional[dict[str, Any]] = None,
609
+ ) -> dict[str, Any]:
610
+ to_object: dict[str, Any] = {}
611
+ if getv(from_object, ["corpus_status"]) is not None:
612
+ setv(to_object, ["corpusStatus"], getv(from_object, ["corpus_status"]))
613
+
614
+ if getv(from_object, ["corpus_type_config"]) is not None:
615
+ setv(
616
+ to_object,
617
+ ["corpusTypeConfig"],
618
+ _RagCorpusCorpusTypeConfig_to_vertex(
619
+ getv(from_object, ["corpus_type_config"]), to_object
620
+ ),
621
+ )
622
+
623
+ if getv(from_object, ["create_time"]) is not None:
624
+ setv(to_object, ["createTime"], getv(from_object, ["create_time"]))
625
+
626
+ if getv(from_object, ["description"]) is not None:
627
+ setv(to_object, ["description"], getv(from_object, ["description"]))
628
+
629
+ if getv(from_object, ["display_name"]) is not None:
630
+ setv(to_object, ["displayName"], getv(from_object, ["display_name"]))
631
+
632
+ if getv(from_object, ["encryption_spec"]) is not None:
633
+ setv(to_object, ["encryptionSpec"], getv(from_object, ["encryption_spec"]))
634
+
635
+ if getv(from_object, ["name"]) is not None:
636
+ setv(to_object, ["name"], getv(from_object, ["name"]))
637
+
638
+ if getv(from_object, ["rag_embedding_model_config"]) is not None:
639
+ setv(
640
+ to_object,
641
+ ["ragEmbeddingModelConfig"],
642
+ _RagEmbeddingModelConfig_to_vertex(
643
+ getv(from_object, ["rag_embedding_model_config"]), to_object
644
+ ),
645
+ )
646
+
647
+ if getv(from_object, ["rag_files_count"]) is not None:
648
+ setv(to_object, ["ragFilesCount"], getv(from_object, ["rag_files_count"]))
649
+
650
+ if getv(from_object, ["rag_vector_db_config"]) is not None:
651
+ setv(
652
+ to_object,
653
+ ["ragVectorDbConfig"],
654
+ _RagVectorDbConfig_to_vertex(
655
+ getv(from_object, ["rag_vector_db_config"]), to_object
656
+ ),
657
+ )
658
+
659
+ if getv(from_object, ["satisfies_pzi"]) is not None:
660
+ setv(to_object, ["satisfiesPzi"], getv(from_object, ["satisfies_pzi"]))
661
+
662
+ if getv(from_object, ["satisfies_pzs"]) is not None:
663
+ setv(to_object, ["satisfiesPzs"], getv(from_object, ["satisfies_pzs"]))
664
+
665
+ if getv(from_object, ["update_time"]) is not None:
666
+ setv(to_object, ["updateTime"], getv(from_object, ["update_time"]))
667
+
668
+ if getv(from_object, ["vector_db_config"]) is not None:
669
+ setv(
670
+ to_object,
671
+ ["vectorDbConfig"],
672
+ _RagVectorDbConfig_to_vertex(
673
+ getv(from_object, ["vector_db_config"]), to_object
674
+ ),
675
+ )
676
+
677
+ if getv(from_object, ["vertex_ai_search_config"]) is not None:
678
+ setv(
679
+ to_object,
680
+ ["vertexAiSearchConfig"],
681
+ _VertexAiSearchConfig_to_vertex(
682
+ getv(from_object, ["vertex_ai_search_config"]), to_object
683
+ ),
684
+ )
685
+
686
+ return to_object
687
+
688
+
689
+ def _RagEmbeddingModelConfigHybridSearchConfig_from_vertex(
690
+ from_object: Union[dict[str, Any], object],
691
+ parent_object: Optional[dict[str, Any]] = None,
692
+ ) -> dict[str, Any]:
693
+ to_object: dict[str, Any] = {}
694
+ if getv(from_object, ["denseEmbeddingModelPredictionEndpoint"]) is not None:
695
+ setv(
696
+ to_object,
697
+ ["dense_embedding_model_prediction_endpoint"],
698
+ _RagEmbeddingModelConfigVertexPredictionEndpoint_from_vertex(
699
+ getv(from_object, ["denseEmbeddingModelPredictionEndpoint"]), to_object
700
+ ),
701
+ )
702
+
703
+ if getv(from_object, ["sparseEmbeddingConfig"]) is not None:
704
+ setv(
705
+ to_object,
706
+ ["sparse_embedding_config"],
707
+ _RagEmbeddingModelConfigSparseEmbeddingConfig_from_vertex(
708
+ getv(from_object, ["sparseEmbeddingConfig"]), to_object
709
+ ),
710
+ )
711
+
712
+ return to_object
713
+
714
+
715
+ def _RagEmbeddingModelConfigHybridSearchConfig_to_vertex(
716
+ from_object: Union[dict[str, Any], object],
717
+ parent_object: Optional[dict[str, Any]] = None,
718
+ ) -> dict[str, Any]:
719
+ to_object: dict[str, Any] = {}
720
+ if getv(from_object, ["dense_embedding_model_prediction_endpoint"]) is not None:
721
+ setv(
722
+ to_object,
723
+ ["denseEmbeddingModelPredictionEndpoint"],
724
+ _RagEmbeddingModelConfigVertexPredictionEndpoint_to_vertex(
725
+ getv(from_object, ["dense_embedding_model_prediction_endpoint"]),
726
+ to_object,
727
+ ),
728
+ )
729
+
730
+ if getv(from_object, ["sparse_embedding_config"]) is not None:
731
+ setv(
732
+ to_object,
733
+ ["sparseEmbeddingConfig"],
734
+ _RagEmbeddingModelConfigSparseEmbeddingConfig_to_vertex(
735
+ getv(from_object, ["sparse_embedding_config"]), to_object
736
+ ),
737
+ )
738
+
739
+ return to_object
740
+
741
+
742
+ def _RagEmbeddingModelConfigSparseEmbeddingConfigBm25_from_vertex(
743
+ from_object: Union[dict[str, Any], object],
744
+ parent_object: Optional[dict[str, Any]] = None,
745
+ ) -> dict[str, Any]:
746
+ to_object: dict[str, Any] = {}
747
+ if getv(from_object, ["b"]) is not None:
748
+ setv(to_object, ["b"], getv(from_object, ["b"]))
749
+
750
+ if getv(from_object, ["k1"]) is not None:
751
+ setv(to_object, ["k1"], getv(from_object, ["k1"]))
752
+
753
+ if getv(from_object, ["multilingual"]) is not None:
754
+ setv(to_object, ["multilingual"], getv(from_object, ["multilingual"]))
755
+
756
+ return to_object
757
+
758
+
759
+ def _RagEmbeddingModelConfigSparseEmbeddingConfigBm25_to_vertex(
760
+ from_object: Union[dict[str, Any], object],
761
+ parent_object: Optional[dict[str, Any]] = None,
762
+ ) -> dict[str, Any]:
763
+ to_object: dict[str, Any] = {}
764
+ if getv(from_object, ["b"]) is not None:
765
+ setv(to_object, ["b"], getv(from_object, ["b"]))
766
+
767
+ if getv(from_object, ["k1"]) is not None:
768
+ setv(to_object, ["k1"], getv(from_object, ["k1"]))
769
+
770
+ if getv(from_object, ["multilingual"]) is not None:
771
+ setv(to_object, ["multilingual"], getv(from_object, ["multilingual"]))
772
+
773
+ return to_object
774
+
775
+
776
+ def _RagEmbeddingModelConfigSparseEmbeddingConfig_from_vertex(
777
+ from_object: Union[dict[str, Any], object],
778
+ parent_object: Optional[dict[str, Any]] = None,
779
+ ) -> dict[str, Any]:
780
+ to_object: dict[str, Any] = {}
781
+ if getv(from_object, ["bm25"]) is not None:
782
+ setv(
783
+ to_object,
784
+ ["bm25"],
785
+ _RagEmbeddingModelConfigSparseEmbeddingConfigBm25_from_vertex(
786
+ getv(from_object, ["bm25"]), to_object
787
+ ),
788
+ )
789
+
790
+ return to_object
791
+
792
+
793
+ def _RagEmbeddingModelConfigSparseEmbeddingConfig_to_vertex(
794
+ from_object: Union[dict[str, Any], object],
795
+ parent_object: Optional[dict[str, Any]] = None,
796
+ ) -> dict[str, Any]:
797
+ to_object: dict[str, Any] = {}
798
+ if getv(from_object, ["bm25"]) is not None:
799
+ setv(
800
+ to_object,
801
+ ["bm25"],
802
+ _RagEmbeddingModelConfigSparseEmbeddingConfigBm25_to_vertex(
803
+ getv(from_object, ["bm25"]), to_object
804
+ ),
805
+ )
806
+
807
+ return to_object
808
+
809
+
810
+ def _RagEmbeddingModelConfigVertexPredictionEndpoint_from_vertex(
811
+ from_object: Union[dict[str, Any], object],
812
+ parent_object: Optional[dict[str, Any]] = None,
813
+ ) -> dict[str, Any]:
814
+ to_object: dict[str, Any] = {}
815
+ if getv(from_object, ["endpoint"]) is not None:
816
+ setv(to_object, ["endpoint"], getv(from_object, ["endpoint"]))
817
+
818
+ if getv(from_object, ["model"]) is not None:
819
+ setv(to_object, ["model"], getv(from_object, ["model"]))
820
+
821
+ if getv(from_object, ["modelVersionId"]) is not None:
822
+ setv(to_object, ["model_version_id"], getv(from_object, ["modelVersionId"]))
823
+
824
+ return to_object
825
+
826
+
827
+ def _RagEmbeddingModelConfigVertexPredictionEndpoint_to_vertex(
828
+ from_object: Union[dict[str, Any], object],
829
+ parent_object: Optional[dict[str, Any]] = None,
830
+ ) -> dict[str, Any]:
831
+ to_object: dict[str, Any] = {}
832
+ if getv(from_object, ["endpoint"]) is not None:
833
+ setv(to_object, ["endpoint"], getv(from_object, ["endpoint"]))
834
+
835
+ if getv(from_object, ["model"]) is not None:
836
+ setv(to_object, ["model"], getv(from_object, ["model"]))
837
+
838
+ if getv(from_object, ["model_version_id"]) is not None:
839
+ setv(to_object, ["modelVersionId"], getv(from_object, ["model_version_id"]))
840
+
841
+ return to_object
842
+
843
+
844
+ def _RagEmbeddingModelConfig_from_vertex(
845
+ from_object: Union[dict[str, Any], object],
846
+ parent_object: Optional[dict[str, Any]] = None,
847
+ ) -> dict[str, Any]:
848
+ to_object: dict[str, Any] = {}
849
+ if getv(from_object, ["hybridSearchConfig"]) is not None:
850
+ setv(
851
+ to_object,
852
+ ["hybrid_search_config"],
853
+ _RagEmbeddingModelConfigHybridSearchConfig_from_vertex(
854
+ getv(from_object, ["hybridSearchConfig"]), to_object
855
+ ),
856
+ )
857
+
858
+ if getv(from_object, ["vertexPredictionEndpoint"]) is not None:
859
+ setv(
860
+ to_object,
861
+ ["vertex_prediction_endpoint"],
862
+ _RagEmbeddingModelConfigVertexPredictionEndpoint_from_vertex(
863
+ getv(from_object, ["vertexPredictionEndpoint"]), to_object
864
+ ),
865
+ )
866
+
867
+ return to_object
868
+
869
+
870
+ def _RagEmbeddingModelConfig_to_vertex(
871
+ from_object: Union[dict[str, Any], object],
872
+ parent_object: Optional[dict[str, Any]] = None,
873
+ ) -> dict[str, Any]:
874
+ to_object: dict[str, Any] = {}
875
+ if getv(from_object, ["hybrid_search_config"]) is not None:
876
+ setv(
877
+ to_object,
878
+ ["hybridSearchConfig"],
879
+ _RagEmbeddingModelConfigHybridSearchConfig_to_vertex(
880
+ getv(from_object, ["hybrid_search_config"]), to_object
881
+ ),
882
+ )
883
+
884
+ if getv(from_object, ["vertex_prediction_endpoint"]) is not None:
885
+ setv(
886
+ to_object,
887
+ ["vertexPredictionEndpoint"],
888
+ _RagEmbeddingModelConfigVertexPredictionEndpoint_to_vertex(
889
+ getv(from_object, ["vertex_prediction_endpoint"]), to_object
890
+ ),
891
+ )
892
+
893
+ return to_object
894
+
895
+
896
+ def _RagEngineConfig_from_vertex(
897
+ from_object: Union[dict[str, Any], object],
898
+ parent_object: Optional[dict[str, Any]] = None,
899
+ ) -> dict[str, Any]:
900
+ to_object: dict[str, Any] = {}
901
+ if getv(from_object, ["name"]) is not None:
902
+ setv(to_object, ["name"], getv(from_object, ["name"]))
903
+
904
+ if getv(from_object, ["ragManagedDbConfig"]) is not None:
905
+ setv(
906
+ to_object,
907
+ ["rag_managed_db_config"],
908
+ _RagManagedDbConfig_from_vertex(
909
+ getv(from_object, ["ragManagedDbConfig"]), to_object
910
+ ),
911
+ )
912
+
913
+ return to_object
914
+
915
+
916
+ def _RagEngineConfig_to_vertex(
917
+ from_object: Union[dict[str, Any], object],
918
+ parent_object: Optional[dict[str, Any]] = None,
919
+ ) -> dict[str, Any]:
920
+ to_object: dict[str, Any] = {}
921
+ if getv(from_object, ["name"]) is not None:
922
+ setv(to_object, ["name"], getv(from_object, ["name"]))
923
+
924
+ if getv(from_object, ["rag_managed_db_config"]) is not None:
925
+ setv(
926
+ to_object,
927
+ ["ragManagedDbConfig"],
928
+ _RagManagedDbConfig_to_vertex(
929
+ getv(from_object, ["rag_managed_db_config"]), to_object
930
+ ),
931
+ )
932
+
933
+ return to_object
934
+
935
+
936
+ def _RagFileParsingConfigLlmParser_from_vertex(
937
+ from_object: Union[dict[str, Any], object],
938
+ parent_object: Optional[dict[str, Any]] = None,
939
+ ) -> dict[str, Any]:
940
+ to_object: dict[str, Any] = {}
941
+ if getv(from_object, ["customParsingPrompt"]) is not None:
942
+ setv(
943
+ to_object,
944
+ ["custom_parsing_prompt"],
945
+ getv(from_object, ["customParsingPrompt"]),
946
+ )
947
+
948
+ if getv(from_object, ["globalMaxParsingRequestsPerMin"]) is not None:
949
+ setv(
950
+ to_object,
951
+ ["global_max_parsing_requests_per_min"],
952
+ getv(from_object, ["globalMaxParsingRequestsPerMin"]),
953
+ )
954
+
955
+ if getv(from_object, ["maxParsingRequestsPerMin"]) is not None:
956
+ setv(
957
+ to_object,
958
+ ["max_parsing_requests_per_min"],
959
+ getv(from_object, ["maxParsingRequestsPerMin"]),
960
+ )
961
+
962
+ if getv(from_object, ["modelName"]) is not None:
963
+ setv(to_object, ["model_name"], getv(from_object, ["modelName"]))
964
+
965
+ return to_object
966
+
967
+
968
+ def _RagFileParsingConfigLlmParser_to_vertex(
969
+ from_object: Union[dict[str, Any], object],
970
+ parent_object: Optional[dict[str, Any]] = None,
971
+ ) -> dict[str, Any]:
972
+ to_object: dict[str, Any] = {}
973
+ if getv(from_object, ["custom_parsing_prompt"]) is not None:
974
+ setv(
975
+ to_object,
976
+ ["customParsingPrompt"],
977
+ getv(from_object, ["custom_parsing_prompt"]),
978
+ )
979
+
980
+ if getv(from_object, ["global_max_parsing_requests_per_min"]) is not None:
981
+ setv(
982
+ to_object,
983
+ ["globalMaxParsingRequestsPerMin"],
984
+ getv(from_object, ["global_max_parsing_requests_per_min"]),
985
+ )
986
+
987
+ if getv(from_object, ["max_parsing_requests_per_min"]) is not None:
988
+ setv(
989
+ to_object,
990
+ ["maxParsingRequestsPerMin"],
991
+ getv(from_object, ["max_parsing_requests_per_min"]),
992
+ )
993
+
994
+ if getv(from_object, ["model_name"]) is not None:
995
+ setv(to_object, ["modelName"], getv(from_object, ["model_name"]))
996
+
997
+ return to_object
998
+
999
+
1000
+ def _RagFileParsingConfig_to_vertex(
1001
+ from_object: Union[dict[str, Any], object],
1002
+ parent_object: Optional[dict[str, Any]] = None,
1003
+ ) -> dict[str, Any]:
1004
+ to_object: dict[str, Any] = {}
1005
+ if getv(from_object, ["advanced_parser"]) is not None:
1006
+ setv(to_object, ["advancedParser"], getv(from_object, ["advanced_parser"]))
1007
+
1008
+ if getv(from_object, ["layout_parser"]) is not None:
1009
+ setv(to_object, ["layoutParser"], getv(from_object, ["layout_parser"]))
1010
+
1011
+ if getv(from_object, ["llm_parser"]) is not None:
1012
+ setv(
1013
+ to_object,
1014
+ ["llmParser"],
1015
+ _RagFileParsingConfigLlmParser_to_vertex(
1016
+ getv(from_object, ["llm_parser"]), to_object
1017
+ ),
1018
+ )
1019
+
1020
+ if getv(from_object, ["use_advanced_pdf_parsing"]) is not None:
1021
+ setv(
1022
+ to_object,
1023
+ ["useAdvancedPdfParsing"],
1024
+ getv(from_object, ["use_advanced_pdf_parsing"]),
1025
+ )
1026
+
1027
+ return to_object
1028
+
1029
+
1030
+ def _RagManagedDbConfigSpanner_from_vertex(
1031
+ from_object: Union[dict[str, Any], object],
1032
+ parent_object: Optional[dict[str, Any]] = None,
1033
+ ) -> dict[str, Any]:
1034
+ to_object: dict[str, Any] = {}
1035
+ if getv(from_object, ["basic"]) is not None:
1036
+ setv(to_object, ["basic"], getv(from_object, ["basic"]))
1037
+
1038
+ if getv(from_object, ["scaled"]) is not None:
1039
+ setv(to_object, ["scaled"], getv(from_object, ["scaled"]))
1040
+
1041
+ if getv(from_object, ["unprovisioned"]) is not None:
1042
+ setv(to_object, ["unprovisioned"], getv(from_object, ["unprovisioned"]))
1043
+
1044
+ return to_object
1045
+
1046
+
1047
+ def _RagManagedDbConfigSpanner_to_vertex(
1048
+ from_object: Union[dict[str, Any], object],
1049
+ parent_object: Optional[dict[str, Any]] = None,
1050
+ ) -> dict[str, Any]:
1051
+ to_object: dict[str, Any] = {}
1052
+ if getv(from_object, ["basic"]) is not None:
1053
+ setv(to_object, ["basic"], getv(from_object, ["basic"]))
1054
+
1055
+ if getv(from_object, ["scaled"]) is not None:
1056
+ setv(to_object, ["scaled"], getv(from_object, ["scaled"]))
1057
+
1058
+ if getv(from_object, ["unprovisioned"]) is not None:
1059
+ setv(to_object, ["unprovisioned"], getv(from_object, ["unprovisioned"]))
1060
+
1061
+ return to_object
1062
+
1063
+
1064
+ def _RagManagedDbConfig_from_vertex(
1065
+ from_object: Union[dict[str, Any], object],
1066
+ parent_object: Optional[dict[str, Any]] = None,
1067
+ ) -> dict[str, Any]:
1068
+ to_object: dict[str, Any] = {}
1069
+ if getv(from_object, ["basic"]) is not None:
1070
+ setv(to_object, ["basic"], getv(from_object, ["basic"]))
1071
+
1072
+ if getv(from_object, ["enterprise"]) is not None:
1073
+ setv(to_object, ["enterprise"], getv(from_object, ["enterprise"]))
1074
+
1075
+ if getv(from_object, ["scaled"]) is not None:
1076
+ setv(to_object, ["scaled"], getv(from_object, ["scaled"]))
1077
+
1078
+ if getv(from_object, ["serverless"]) is not None:
1079
+ setv(to_object, ["serverless"], getv(from_object, ["serverless"]))
1080
+
1081
+ if getv(from_object, ["spanner"]) is not None:
1082
+ setv(
1083
+ to_object,
1084
+ ["spanner"],
1085
+ _RagManagedDbConfigSpanner_from_vertex(
1086
+ getv(from_object, ["spanner"]), to_object
1087
+ ),
1088
+ )
1089
+
1090
+ if getv(from_object, ["unprovisioned"]) is not None:
1091
+ setv(to_object, ["unprovisioned"], getv(from_object, ["unprovisioned"]))
1092
+
1093
+ return to_object
1094
+
1095
+
1096
+ def _RagManagedDbConfig_to_vertex(
1097
+ from_object: Union[dict[str, Any], object],
1098
+ parent_object: Optional[dict[str, Any]] = None,
1099
+ ) -> dict[str, Any]:
1100
+ to_object: dict[str, Any] = {}
1101
+ if getv(from_object, ["basic"]) is not None:
1102
+ setv(to_object, ["basic"], getv(from_object, ["basic"]))
1103
+
1104
+ if getv(from_object, ["enterprise"]) is not None:
1105
+ setv(to_object, ["enterprise"], getv(from_object, ["enterprise"]))
1106
+
1107
+ if getv(from_object, ["scaled"]) is not None:
1108
+ setv(to_object, ["scaled"], getv(from_object, ["scaled"]))
1109
+
1110
+ if getv(from_object, ["serverless"]) is not None:
1111
+ setv(to_object, ["serverless"], getv(from_object, ["serverless"]))
1112
+
1113
+ if getv(from_object, ["spanner"]) is not None:
1114
+ setv(
1115
+ to_object,
1116
+ ["spanner"],
1117
+ _RagManagedDbConfigSpanner_to_vertex(
1118
+ getv(from_object, ["spanner"]), to_object
1119
+ ),
1120
+ )
1121
+
1122
+ if getv(from_object, ["unprovisioned"]) is not None:
1123
+ setv(to_object, ["unprovisioned"], getv(from_object, ["unprovisioned"]))
1124
+
1125
+ return to_object
1126
+
1127
+
1128
+ def _RagVectorDbConfigPinecone_from_vertex(
1129
+ from_object: Union[dict[str, Any], object],
1130
+ parent_object: Optional[dict[str, Any]] = None,
1131
+ ) -> dict[str, Any]:
1132
+ to_object: dict[str, Any] = {}
1133
+ if getv(from_object, ["indexName"]) is not None:
1134
+ setv(to_object, ["index_name"], getv(from_object, ["indexName"]))
1135
+
1136
+ return to_object
1137
+
1138
+
1139
+ def _RagVectorDbConfigPinecone_to_vertex(
1140
+ from_object: Union[dict[str, Any], object],
1141
+ parent_object: Optional[dict[str, Any]] = None,
1142
+ ) -> dict[str, Any]:
1143
+ to_object: dict[str, Any] = {}
1144
+ if getv(from_object, ["index_name"]) is not None:
1145
+ setv(to_object, ["indexName"], getv(from_object, ["index_name"]))
1146
+
1147
+ return to_object
1148
+
1149
+
1150
+ def _RagVectorDbConfigRagManagedDbANN_from_vertex(
1151
+ from_object: Union[dict[str, Any], object],
1152
+ parent_object: Optional[dict[str, Any]] = None,
1153
+ ) -> dict[str, Any]:
1154
+ to_object: dict[str, Any] = {}
1155
+ if getv(from_object, ["leafCount"]) is not None:
1156
+ setv(to_object, ["leaf_count"], getv(from_object, ["leafCount"]))
1157
+
1158
+ if getv(from_object, ["treeDepth"]) is not None:
1159
+ setv(to_object, ["tree_depth"], getv(from_object, ["treeDepth"]))
1160
+
1161
+ return to_object
1162
+
1163
+
1164
+ def _RagVectorDbConfigRagManagedDbANN_to_vertex(
1165
+ from_object: Union[dict[str, Any], object],
1166
+ parent_object: Optional[dict[str, Any]] = None,
1167
+ ) -> dict[str, Any]:
1168
+ to_object: dict[str, Any] = {}
1169
+ if getv(from_object, ["leaf_count"]) is not None:
1170
+ setv(to_object, ["leafCount"], getv(from_object, ["leaf_count"]))
1171
+
1172
+ if getv(from_object, ["tree_depth"]) is not None:
1173
+ setv(to_object, ["treeDepth"], getv(from_object, ["tree_depth"]))
1174
+
1175
+ return to_object
1176
+
1177
+
1178
+ def _RagVectorDbConfigRagManagedDbKNN_from_vertex(
1179
+ from_object: Union[dict[str, Any], object],
1180
+ parent_object: Optional[dict[str, Any]] = None,
1181
+ ) -> dict[str, Any]:
1182
+ to_object: dict[str, Any] = {}
1183
+
1184
+ return to_object
1185
+
1186
+
1187
+ def _RagVectorDbConfigRagManagedDbKNN_to_vertex(
1188
+ from_object: Union[dict[str, Any], object],
1189
+ parent_object: Optional[dict[str, Any]] = None,
1190
+ ) -> dict[str, Any]:
1191
+ to_object: dict[str, Any] = {}
1192
+
1193
+ return to_object
1194
+
1195
+
1196
+ def _RagVectorDbConfigRagManagedDb_from_vertex(
1197
+ from_object: Union[dict[str, Any], object],
1198
+ parent_object: Optional[dict[str, Any]] = None,
1199
+ ) -> dict[str, Any]:
1200
+ to_object: dict[str, Any] = {}
1201
+ if getv(from_object, ["ann"]) is not None:
1202
+ setv(
1203
+ to_object,
1204
+ ["ann"],
1205
+ _RagVectorDbConfigRagManagedDbANN_from_vertex(
1206
+ getv(from_object, ["ann"]), to_object
1207
+ ),
1208
+ )
1209
+
1210
+ if getv(from_object, ["knn"]) is not None:
1211
+ setv(
1212
+ to_object,
1213
+ ["knn"],
1214
+ _RagVectorDbConfigRagManagedDbKNN_from_vertex(
1215
+ getv(from_object, ["knn"]), to_object
1216
+ ),
1217
+ )
1218
+
1219
+ return to_object
1220
+
1221
+
1222
+ def _RagVectorDbConfigRagManagedDb_to_vertex(
1223
+ from_object: Union[dict[str, Any], object],
1224
+ parent_object: Optional[dict[str, Any]] = None,
1225
+ ) -> dict[str, Any]:
1226
+ to_object: dict[str, Any] = {}
1227
+ if getv(from_object, ["ann"]) is not None:
1228
+ setv(
1229
+ to_object,
1230
+ ["ann"],
1231
+ _RagVectorDbConfigRagManagedDbANN_to_vertex(
1232
+ getv(from_object, ["ann"]), to_object
1233
+ ),
1234
+ )
1235
+
1236
+ if getv(from_object, ["knn"]) is not None:
1237
+ setv(
1238
+ to_object,
1239
+ ["knn"],
1240
+ _RagVectorDbConfigRagManagedDbKNN_to_vertex(
1241
+ getv(from_object, ["knn"]), to_object
1242
+ ),
1243
+ )
1244
+
1245
+ return to_object
1246
+
1247
+
1248
+ def _RagVectorDbConfigRagManagedVertexVectorSearch_from_vertex(
1249
+ from_object: Union[dict[str, Any], object],
1250
+ parent_object: Optional[dict[str, Any]] = None,
1251
+ ) -> dict[str, Any]:
1252
+ to_object: dict[str, Any] = {}
1253
+ if getv(from_object, ["collectionName"]) is not None:
1254
+ setv(to_object, ["collection_name"], getv(from_object, ["collectionName"]))
1255
+
1256
+ return to_object
1257
+
1258
+
1259
+ def _RagVectorDbConfigRagManagedVertexVectorSearch_to_vertex(
1260
+ from_object: Union[dict[str, Any], object],
1261
+ parent_object: Optional[dict[str, Any]] = None,
1262
+ ) -> dict[str, Any]:
1263
+ to_object: dict[str, Any] = {}
1264
+ if getv(from_object, ["collection_name"]) is not None:
1265
+ setv(to_object, ["collectionName"], getv(from_object, ["collection_name"]))
1266
+
1267
+ return to_object
1268
+
1269
+
1270
+ def _RagVectorDbConfigVertexFeatureStore_from_vertex(
1271
+ from_object: Union[dict[str, Any], object],
1272
+ parent_object: Optional[dict[str, Any]] = None,
1273
+ ) -> dict[str, Any]:
1274
+ to_object: dict[str, Any] = {}
1275
+ if getv(from_object, ["featureViewResourceName"]) is not None:
1276
+ setv(
1277
+ to_object,
1278
+ ["feature_view_resource_name"],
1279
+ getv(from_object, ["featureViewResourceName"]),
1280
+ )
1281
+
1282
+ return to_object
1283
+
1284
+
1285
+ def _RagVectorDbConfigVertexFeatureStore_to_vertex(
1286
+ from_object: Union[dict[str, Any], object],
1287
+ parent_object: Optional[dict[str, Any]] = None,
1288
+ ) -> dict[str, Any]:
1289
+ to_object: dict[str, Any] = {}
1290
+ if getv(from_object, ["feature_view_resource_name"]) is not None:
1291
+ setv(
1292
+ to_object,
1293
+ ["featureViewResourceName"],
1294
+ getv(from_object, ["feature_view_resource_name"]),
1295
+ )
1296
+
1297
+ return to_object
1298
+
1299
+
1300
+ def _RagVectorDbConfigVertexVectorSearch_from_vertex(
1301
+ from_object: Union[dict[str, Any], object],
1302
+ parent_object: Optional[dict[str, Any]] = None,
1303
+ ) -> dict[str, Any]:
1304
+ to_object: dict[str, Any] = {}
1305
+ if getv(from_object, ["index"]) is not None:
1306
+ setv(to_object, ["index"], getv(from_object, ["index"]))
1307
+
1308
+ if getv(from_object, ["indexEndpoint"]) is not None:
1309
+ setv(to_object, ["index_endpoint"], getv(from_object, ["indexEndpoint"]))
1310
+
1311
+ return to_object
1312
+
1313
+
1314
+ def _RagVectorDbConfigVertexVectorSearch_to_vertex(
1315
+ from_object: Union[dict[str, Any], object],
1316
+ parent_object: Optional[dict[str, Any]] = None,
1317
+ ) -> dict[str, Any]:
1318
+ to_object: dict[str, Any] = {}
1319
+ if getv(from_object, ["index"]) is not None:
1320
+ setv(to_object, ["index"], getv(from_object, ["index"]))
1321
+
1322
+ if getv(from_object, ["index_endpoint"]) is not None:
1323
+ setv(to_object, ["indexEndpoint"], getv(from_object, ["index_endpoint"]))
1324
+
1325
+ return to_object
1326
+
1327
+
1328
+ def _RagVectorDbConfigWeaviate_from_vertex(
1329
+ from_object: Union[dict[str, Any], object],
1330
+ parent_object: Optional[dict[str, Any]] = None,
1331
+ ) -> dict[str, Any]:
1332
+ to_object: dict[str, Any] = {}
1333
+ if getv(from_object, ["collectionName"]) is not None:
1334
+ setv(to_object, ["collection_name"], getv(from_object, ["collectionName"]))
1335
+
1336
+ if getv(from_object, ["httpEndpoint"]) is not None:
1337
+ setv(to_object, ["http_endpoint"], getv(from_object, ["httpEndpoint"]))
1338
+
1339
+ return to_object
1340
+
1341
+
1342
+ def _RagVectorDbConfigWeaviate_to_vertex(
1343
+ from_object: Union[dict[str, Any], object],
1344
+ parent_object: Optional[dict[str, Any]] = None,
1345
+ ) -> dict[str, Any]:
1346
+ to_object: dict[str, Any] = {}
1347
+ if getv(from_object, ["collection_name"]) is not None:
1348
+ setv(to_object, ["collectionName"], getv(from_object, ["collection_name"]))
1349
+
1350
+ if getv(from_object, ["http_endpoint"]) is not None:
1351
+ setv(to_object, ["httpEndpoint"], getv(from_object, ["http_endpoint"]))
1352
+
1353
+ return to_object
1354
+
1355
+
1356
+ def _RagVectorDbConfig_from_vertex(
1357
+ from_object: Union[dict[str, Any], object],
1358
+ parent_object: Optional[dict[str, Any]] = None,
1359
+ ) -> dict[str, Any]:
1360
+ to_object: dict[str, Any] = {}
1361
+ if getv(from_object, ["apiAuth"]) is not None:
1362
+ setv(to_object, ["api_auth"], getv(from_object, ["apiAuth"]))
1363
+
1364
+ if getv(from_object, ["pinecone"]) is not None:
1365
+ setv(
1366
+ to_object,
1367
+ ["pinecone"],
1368
+ _RagVectorDbConfigPinecone_from_vertex(
1369
+ getv(from_object, ["pinecone"]), to_object
1370
+ ),
1371
+ )
1372
+
1373
+ if getv(from_object, ["ragEmbeddingModelConfig"]) is not None:
1374
+ setv(
1375
+ to_object,
1376
+ ["rag_embedding_model_config"],
1377
+ _RagEmbeddingModelConfig_from_vertex(
1378
+ getv(from_object, ["ragEmbeddingModelConfig"]), to_object
1379
+ ),
1380
+ )
1381
+
1382
+ if getv(from_object, ["ragManagedDb"]) is not None:
1383
+ setv(
1384
+ to_object,
1385
+ ["rag_managed_db"],
1386
+ _RagVectorDbConfigRagManagedDb_from_vertex(
1387
+ getv(from_object, ["ragManagedDb"]), to_object
1388
+ ),
1389
+ )
1390
+
1391
+ if getv(from_object, ["ragManagedVertexVectorSearch"]) is not None:
1392
+ setv(
1393
+ to_object,
1394
+ ["rag_managed_vertex_vector_search"],
1395
+ _RagVectorDbConfigRagManagedVertexVectorSearch_from_vertex(
1396
+ getv(from_object, ["ragManagedVertexVectorSearch"]), to_object
1397
+ ),
1398
+ )
1399
+
1400
+ if getv(from_object, ["vertexFeatureStore"]) is not None:
1401
+ setv(
1402
+ to_object,
1403
+ ["vertex_feature_store"],
1404
+ _RagVectorDbConfigVertexFeatureStore_from_vertex(
1405
+ getv(from_object, ["vertexFeatureStore"]), to_object
1406
+ ),
1407
+ )
1408
+
1409
+ if getv(from_object, ["vertexVectorSearch"]) is not None:
1410
+ setv(
1411
+ to_object,
1412
+ ["vertex_vector_search"],
1413
+ _RagVectorDbConfigVertexVectorSearch_from_vertex(
1414
+ getv(from_object, ["vertexVectorSearch"]), to_object
1415
+ ),
1416
+ )
1417
+
1418
+ if getv(from_object, ["weaviate"]) is not None:
1419
+ setv(
1420
+ to_object,
1421
+ ["weaviate"],
1422
+ _RagVectorDbConfigWeaviate_from_vertex(
1423
+ getv(from_object, ["weaviate"]), to_object
1424
+ ),
1425
+ )
1426
+
1427
+ return to_object
1428
+
1429
+
1430
+ def _RagVectorDbConfig_to_vertex(
1431
+ from_object: Union[dict[str, Any], object],
1432
+ parent_object: Optional[dict[str, Any]] = None,
1433
+ ) -> dict[str, Any]:
1434
+ to_object: dict[str, Any] = {}
1435
+ if getv(from_object, ["api_auth"]) is not None:
1436
+ setv(to_object, ["apiAuth"], getv(from_object, ["api_auth"]))
1437
+
1438
+ if getv(from_object, ["pinecone"]) is not None:
1439
+ setv(
1440
+ to_object,
1441
+ ["pinecone"],
1442
+ _RagVectorDbConfigPinecone_to_vertex(
1443
+ getv(from_object, ["pinecone"]), to_object
1444
+ ),
1445
+ )
1446
+
1447
+ if getv(from_object, ["rag_embedding_model_config"]) is not None:
1448
+ setv(
1449
+ to_object,
1450
+ ["ragEmbeddingModelConfig"],
1451
+ _RagEmbeddingModelConfig_to_vertex(
1452
+ getv(from_object, ["rag_embedding_model_config"]), to_object
1453
+ ),
1454
+ )
1455
+
1456
+ if getv(from_object, ["rag_managed_db"]) is not None:
1457
+ setv(
1458
+ to_object,
1459
+ ["ragManagedDb"],
1460
+ _RagVectorDbConfigRagManagedDb_to_vertex(
1461
+ getv(from_object, ["rag_managed_db"]), to_object
1462
+ ),
1463
+ )
1464
+
1465
+ if getv(from_object, ["rag_managed_vertex_vector_search"]) is not None:
1466
+ setv(
1467
+ to_object,
1468
+ ["ragManagedVertexVectorSearch"],
1469
+ _RagVectorDbConfigRagManagedVertexVectorSearch_to_vertex(
1470
+ getv(from_object, ["rag_managed_vertex_vector_search"]), to_object
1471
+ ),
1472
+ )
1473
+
1474
+ if getv(from_object, ["vertex_feature_store"]) is not None:
1475
+ setv(
1476
+ to_object,
1477
+ ["vertexFeatureStore"],
1478
+ _RagVectorDbConfigVertexFeatureStore_to_vertex(
1479
+ getv(from_object, ["vertex_feature_store"]), to_object
1480
+ ),
1481
+ )
1482
+
1483
+ if getv(from_object, ["vertex_vector_search"]) is not None:
1484
+ setv(
1485
+ to_object,
1486
+ ["vertexVectorSearch"],
1487
+ _RagVectorDbConfigVertexVectorSearch_to_vertex(
1488
+ getv(from_object, ["vertex_vector_search"]), to_object
1489
+ ),
1490
+ )
1491
+
1492
+ if getv(from_object, ["weaviate"]) is not None:
1493
+ setv(
1494
+ to_object,
1495
+ ["weaviate"],
1496
+ _RagVectorDbConfigWeaviate_to_vertex(
1497
+ getv(from_object, ["weaviate"]), to_object
1498
+ ),
1499
+ )
1500
+
1501
+ return to_object
1502
+
1503
+
1504
+ def _RetrieveRagContextsRequestParameters_to_vertex(
1505
+ from_object: Union[dict[str, Any], object],
1506
+ parent_object: Optional[dict[str, Any]] = None,
1507
+ ) -> dict[str, Any]:
1508
+ to_object: dict[str, Any] = {}
1509
+ if getv(from_object, ["vertex_rag_store"]) is not None:
1510
+ setv(to_object, ["vertexRagStore"], getv(from_object, ["vertex_rag_store"]))
1511
+
1512
+ if getv(from_object, ["query"]) is not None:
1513
+ setv(to_object, ["query"], getv(from_object, ["query"]))
1514
+
1515
+ if getv(from_object, ["config"]) is not None:
1516
+ setv(to_object, ["config"], getv(from_object, ["config"]))
1517
+
1518
+ return to_object
1519
+
1520
+
1521
+ def _UpdateRagConfigRequestParameters_to_vertex(
1522
+ from_object: Union[dict[str, Any], object],
1523
+ parent_object: Optional[dict[str, Any]] = None,
1524
+ ) -> dict[str, Any]:
1525
+ to_object: dict[str, Any] = {}
1526
+ if getv(from_object, ["updated_config"]) is not None:
1527
+ setv(
1528
+ to_object,
1529
+ ["_self"],
1530
+ _RagEngineConfig_to_vertex(
1531
+ getv(from_object, ["updated_config"]), to_object
1532
+ ),
1533
+ )
1534
+
1535
+ if getv(from_object, ["config"]) is not None:
1536
+ setv(to_object, ["config"], getv(from_object, ["config"]))
1537
+
1538
+ return to_object
1539
+
1540
+
1541
+ def _UpdateRagCorpusRequestParameters_to_vertex(
1542
+ from_object: Union[dict[str, Any], object],
1543
+ parent_object: Optional[dict[str, Any]] = None,
1544
+ ) -> dict[str, Any]:
1545
+ to_object: dict[str, Any] = {}
1546
+ if getv(from_object, ["config"]) is not None:
1547
+ setv(to_object, ["config"], getv(from_object, ["config"]))
1548
+
1549
+ if getv(from_object, ["name"]) is not None:
1550
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
1551
+
1552
+ if getv(from_object, ["rag_corpus"]) is not None:
1553
+ setv(
1554
+ to_object,
1555
+ ["_self"],
1556
+ _RagCorpus_to_vertex(getv(from_object, ["rag_corpus"]), to_object),
1557
+ )
1558
+
1559
+ return to_object
1560
+
1561
+
1562
+ def _UploadRagFileConfig_to_vertex(
1563
+ from_object: Union[dict[str, Any], object],
1564
+ parent_object: Optional[dict[str, Any]] = None,
1565
+ ) -> dict[str, Any]:
1566
+ to_object: dict[str, Any] = {}
1567
+ if getv(from_object, ["rag_file_chunking_config"]) is not None:
1568
+ setv(
1569
+ to_object,
1570
+ ["ragFileChunkingConfig"],
1571
+ getv(from_object, ["rag_file_chunking_config"]),
1572
+ )
1573
+
1574
+ if getv(from_object, ["rag_file_metadata_config"]) is not None:
1575
+ setv(
1576
+ to_object,
1577
+ ["ragFileMetadataConfig"],
1578
+ getv(from_object, ["rag_file_metadata_config"]),
1579
+ )
1580
+
1581
+ if getv(from_object, ["rag_file_parsing_config"]) is not None:
1582
+ setv(
1583
+ to_object,
1584
+ ["ragFileParsingConfig"],
1585
+ _RagFileParsingConfig_to_vertex(
1586
+ getv(from_object, ["rag_file_parsing_config"]), to_object
1587
+ ),
1588
+ )
1589
+
1590
+ if getv(from_object, ["rag_file_transformation_config"]) is not None:
1591
+ setv(
1592
+ to_object,
1593
+ ["ragFileTransformationConfig"],
1594
+ getv(from_object, ["rag_file_transformation_config"]),
1595
+ )
1596
+
1597
+ return to_object
1598
+
1599
+
1600
+ def _UploadRagFileParameters_to_vertex(
1601
+ from_object: Union[dict[str, Any], object],
1602
+ parent_object: Optional[dict[str, Any]] = None,
1603
+ ) -> dict[str, Any]:
1604
+ to_object: dict[str, Any] = {}
1605
+ if getv(from_object, ["name"]) is not None:
1606
+ setv(to_object, ["_url", "name"], getv(from_object, ["name"]))
1607
+
1608
+ if getv(from_object, ["rag_file"]) is not None:
1609
+ setv(to_object, ["ragFile"], getv(from_object, ["rag_file"]))
1610
+
1611
+ if getv(from_object, ["upload_rag_file_config"]) is not None:
1612
+ setv(
1613
+ to_object,
1614
+ ["uploadRagFileConfig"],
1615
+ _UploadRagFileConfig_to_vertex(
1616
+ getv(from_object, ["upload_rag_file_config"]), to_object
1617
+ ),
1618
+ )
1619
+
1620
+ return to_object
1621
+
1622
+
1623
+ def _VertexAiSearchConfig_from_vertex(
1624
+ from_object: Union[dict[str, Any], object],
1625
+ parent_object: Optional[dict[str, Any]] = None,
1626
+ ) -> dict[str, Any]:
1627
+ to_object: dict[str, Any] = {}
1628
+ if getv(from_object, ["servingConfig"]) is not None:
1629
+ setv(to_object, ["serving_config"], getv(from_object, ["servingConfig"]))
1630
+
1631
+ return to_object
1632
+
1633
+
1634
+ def _VertexAiSearchConfig_to_vertex(
1635
+ from_object: Union[dict[str, Any], object],
1636
+ parent_object: Optional[dict[str, Any]] = None,
1637
+ ) -> dict[str, Any]:
1638
+ to_object: dict[str, Any] = {}
1639
+ if getv(from_object, ["serving_config"]) is not None:
1640
+ setv(to_object, ["servingConfig"], getv(from_object, ["serving_config"]))
1641
+
1642
+ return to_object
1643
+
1644
+
1645
+ class Rag(_api_module.BaseModule):
1646
+
1647
+ def ask_contexts(
1648
+ self,
1649
+ *,
1650
+ query: types.RagQueryOrDict,
1651
+ config: Optional[types.AskContextsConfigOrDict] = None,
1652
+ ) -> types.AskContextsResponse:
1653
+ """
1654
+ Agentic Retrieval Ask API for RAG.
1655
+
1656
+ Args:
1657
+ query: The query to ask.
1658
+ config: Optional configuration for the request.
1659
+
1660
+ Returns:
1661
+ The AskContextsResponse.
1662
+
1663
+ """
1664
+
1665
+ parameter_model = types._AskContextsRequestParameters(
1666
+ query=query,
1667
+ config=config,
1668
+ )
1669
+
1670
+ request_url_dict: Optional[dict[str, str]]
1671
+ if not self._api_client.vertexai:
1672
+ raise ValueError(
1673
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
1674
+ )
1675
+ else:
1676
+ request_dict = _AskContextsRequestParameters_to_vertex(parameter_model)
1677
+ request_url_dict = request_dict.get("_url")
1678
+ if request_url_dict:
1679
+ path = ":askContexts".format_map(request_url_dict)
1680
+ else:
1681
+ path = ":askContexts"
1682
+
1683
+ query_params = request_dict.get("_query")
1684
+ if query_params:
1685
+ path = f"{path}?{urlencode(query_params)}"
1686
+ # TODO: remove the hack that pops config.
1687
+ request_dict.pop("config", None)
1688
+
1689
+ http_options: Optional[types.HttpOptions] = None
1690
+ if (
1691
+ parameter_model.config is not None
1692
+ and parameter_model.config.http_options is not None
1693
+ ):
1694
+ http_options = parameter_model.config.http_options
1695
+
1696
+ request_dict = _common.convert_to_dict(request_dict)
1697
+ request_dict = _common.encode_unserializable_types(request_dict)
1698
+
1699
+ response = self._api_client.request("post", path, request_dict, http_options)
1700
+
1701
+ response_dict = {} if not response.body else json.loads(response.body)
1702
+
1703
+ return_value = types.AskContextsResponse._from_response(
1704
+ response=response_dict,
1705
+ kwargs=(
1706
+ {
1707
+ "config": {
1708
+ "response_schema": getattr(
1709
+ parameter_model.config, "response_schema", None
1710
+ ),
1711
+ "response_json_schema": getattr(
1712
+ parameter_model.config, "response_json_schema", None
1713
+ ),
1714
+ "include_all_fields": getattr(
1715
+ parameter_model.config, "include_all_fields", None
1716
+ ),
1717
+ }
1718
+ }
1719
+ if getattr(parameter_model, "config", None)
1720
+ else {}
1721
+ ),
1722
+ )
1723
+
1724
+ self._api_client._verify_response(return_value)
1725
+ return return_value
1726
+
1727
+ def _create_corpus(
1728
+ self,
1729
+ *,
1730
+ rag_corpus: types.RagCorpusOrDict,
1731
+ config: Optional[types.CreateRagCorpusConfigOrDict] = None,
1732
+ ) -> types.CreateRagCorpusOperation:
1733
+ """
1734
+ Creates a new Rag Corpus.
1735
+ """
1736
+
1737
+ parameter_model = types._CreateRagCorpusRequestParameters(
1738
+ rag_corpus=rag_corpus,
1739
+ config=config,
1740
+ )
1741
+
1742
+ request_url_dict: Optional[dict[str, str]]
1743
+ if not self._api_client.vertexai:
1744
+ raise ValueError(
1745
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
1746
+ )
1747
+ else:
1748
+ request_dict = _CreateRagCorpusRequestParameters_to_vertex(parameter_model)
1749
+ request_url_dict = request_dict.get("_url")
1750
+ if request_url_dict:
1751
+ path = "ragCorpora".format_map(request_url_dict)
1752
+ else:
1753
+ path = "ragCorpora"
1754
+
1755
+ query_params = request_dict.get("_query")
1756
+ if query_params:
1757
+ path = f"{path}?{urlencode(query_params)}"
1758
+ # TODO: remove the hack that pops config.
1759
+ request_dict.pop("config", None)
1760
+
1761
+ http_options: Optional[types.HttpOptions] = None
1762
+ if (
1763
+ parameter_model.config is not None
1764
+ and parameter_model.config.http_options is not None
1765
+ ):
1766
+ http_options = parameter_model.config.http_options
1767
+
1768
+ request_dict = _common.convert_to_dict(request_dict)
1769
+ request_dict = _common.encode_unserializable_types(request_dict)
1770
+
1771
+ response = self._api_client.request("post", path, request_dict, http_options)
1772
+
1773
+ response_dict = {} if not response.body else json.loads(response.body)
1774
+
1775
+ return_value = types.CreateRagCorpusOperation._from_response(
1776
+ response=response_dict,
1777
+ kwargs=(
1778
+ {
1779
+ "config": {
1780
+ "response_schema": getattr(
1781
+ parameter_model.config, "response_schema", None
1782
+ ),
1783
+ "response_json_schema": getattr(
1784
+ parameter_model.config, "response_json_schema", None
1785
+ ),
1786
+ "include_all_fields": getattr(
1787
+ parameter_model.config, "include_all_fields", None
1788
+ ),
1789
+ }
1790
+ }
1791
+ if getattr(parameter_model, "config", None)
1792
+ else {}
1793
+ ),
1794
+ )
1795
+
1796
+ self._api_client._verify_response(return_value)
1797
+ return return_value
1798
+
1799
+ def _get_corpus_operation(
1800
+ self,
1801
+ *,
1802
+ operation_name: str,
1803
+ config: Optional[types.GetCorpusOperationConfigOrDict] = None,
1804
+ ) -> types.CorpusOperation:
1805
+ parameter_model = types._GetCorpusOperationParameters(
1806
+ operation_name=operation_name,
1807
+ config=config,
1808
+ )
1809
+
1810
+ request_url_dict: Optional[dict[str, str]]
1811
+ if not self._api_client.vertexai:
1812
+ raise ValueError(
1813
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
1814
+ )
1815
+ else:
1816
+ request_dict = _GetCorpusOperationParameters_to_vertex(parameter_model)
1817
+ request_url_dict = request_dict.get("_url")
1818
+ if request_url_dict:
1819
+ path = "{operationName}".format_map(request_url_dict)
1820
+ else:
1821
+ path = "{operationName}"
1822
+
1823
+ query_params = request_dict.get("_query")
1824
+ if query_params:
1825
+ path = f"{path}?{urlencode(query_params)}"
1826
+ # TODO: remove the hack that pops config.
1827
+ request_dict.pop("config", None)
1828
+
1829
+ http_options: Optional[types.HttpOptions] = None
1830
+ if (
1831
+ parameter_model.config is not None
1832
+ and parameter_model.config.http_options is not None
1833
+ ):
1834
+ http_options = parameter_model.config.http_options
1835
+
1836
+ request_dict = _common.convert_to_dict(request_dict)
1837
+ request_dict = _common.encode_unserializable_types(request_dict)
1838
+
1839
+ response = self._api_client.request("get", path, request_dict, http_options)
1840
+
1841
+ response_dict = {} if not response.body else json.loads(response.body)
1842
+
1843
+ if self._api_client.vertexai:
1844
+ response_dict = _CorpusOperation_from_vertex(response_dict)
1845
+
1846
+ return_value = types.CorpusOperation._from_response(
1847
+ response=response_dict,
1848
+ kwargs=(
1849
+ {
1850
+ "config": {
1851
+ "response_schema": getattr(
1852
+ parameter_model.config, "response_schema", None
1853
+ ),
1854
+ "response_json_schema": getattr(
1855
+ parameter_model.config, "response_json_schema", None
1856
+ ),
1857
+ "include_all_fields": getattr(
1858
+ parameter_model.config, "include_all_fields", None
1859
+ ),
1860
+ }
1861
+ }
1862
+ if getattr(parameter_model, "config", None)
1863
+ else {}
1864
+ ),
1865
+ )
1866
+
1867
+ self._api_client._verify_response(return_value)
1868
+ return return_value
1869
+
1870
+ def get_corpus(
1871
+ self, *, config: Optional[types.GetRagCorpusConfigOrDict] = None, name: str
1872
+ ) -> types.RagCorpus:
1873
+ """
1874
+ Gets a RAG Corpus.
1875
+
1876
+ Args:
1877
+ name: The name of the RagCorpus to retrieve.
1878
+ config: Optional configuration for the request.
1879
+
1880
+ Returns:
1881
+ The requested RagCorpus.
1882
+
1883
+ """
1884
+
1885
+ parameter_model = types._GetRagCorpusRequestParameters(
1886
+ config=config,
1887
+ name=name,
1888
+ )
1889
+
1890
+ request_url_dict: Optional[dict[str, str]]
1891
+ if not self._api_client.vertexai:
1892
+ raise ValueError(
1893
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
1894
+ )
1895
+ else:
1896
+ request_dict = _GetRagCorpusRequestParameters_to_vertex(parameter_model)
1897
+ request_url_dict = request_dict.get("_url")
1898
+ if request_url_dict:
1899
+ path = "{name}".format_map(request_url_dict)
1900
+ else:
1901
+ path = "{name}"
1902
+
1903
+ query_params = request_dict.get("_query")
1904
+ if query_params:
1905
+ path = f"{path}?{urlencode(query_params)}"
1906
+ # TODO: remove the hack that pops config.
1907
+ request_dict.pop("config", None)
1908
+
1909
+ http_options: Optional[types.HttpOptions] = None
1910
+ if (
1911
+ parameter_model.config is not None
1912
+ and parameter_model.config.http_options is not None
1913
+ ):
1914
+ http_options = parameter_model.config.http_options
1915
+
1916
+ request_dict = _common.convert_to_dict(request_dict)
1917
+ request_dict = _common.encode_unserializable_types(request_dict)
1918
+
1919
+ response = self._api_client.request("get", path, request_dict, http_options)
1920
+
1921
+ response_dict = {} if not response.body else json.loads(response.body)
1922
+
1923
+ if self._api_client.vertexai:
1924
+ response_dict = _RagCorpus_from_vertex(response_dict)
1925
+
1926
+ return_value = types.RagCorpus._from_response(
1927
+ response=response_dict,
1928
+ kwargs=(
1929
+ {
1930
+ "config": {
1931
+ "response_schema": getattr(
1932
+ parameter_model.config, "response_schema", None
1933
+ ),
1934
+ "response_json_schema": getattr(
1935
+ parameter_model.config, "response_json_schema", None
1936
+ ),
1937
+ "include_all_fields": getattr(
1938
+ parameter_model.config, "include_all_fields", None
1939
+ ),
1940
+ }
1941
+ }
1942
+ if getattr(parameter_model, "config", None)
1943
+ else {}
1944
+ ),
1945
+ )
1946
+
1947
+ self._api_client._verify_response(return_value)
1948
+ return return_value
1949
+
1950
+ def list_corpora(
1951
+ self, *, config: Optional[types.ListRagCorporaConfigOrDict] = None
1952
+ ) -> types.ListRagCorporaResponse:
1953
+ """
1954
+ Lists RagCorpora for a project.
1955
+
1956
+ Args:
1957
+ config: Optional configuration for listing corpora.
1958
+
1959
+ Returns:
1960
+ A ListRagCorporaResponse containing the corpora.
1961
+
1962
+ """
1963
+
1964
+ parameter_model = types._ListRagCorporaRequestParameters(
1965
+ config=config,
1966
+ )
1967
+
1968
+ request_url_dict: Optional[dict[str, str]]
1969
+ if not self._api_client.vertexai:
1970
+ raise ValueError(
1971
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
1972
+ )
1973
+ else:
1974
+ request_dict = _ListRagCorporaRequestParameters_to_vertex(parameter_model)
1975
+ request_url_dict = request_dict.get("_url")
1976
+ if request_url_dict:
1977
+ path = "ragCorpora".format_map(request_url_dict)
1978
+ else:
1979
+ path = "ragCorpora"
1980
+
1981
+ query_params = request_dict.get("_query")
1982
+ if query_params:
1983
+ path = f"{path}?{urlencode(query_params)}"
1984
+ # TODO: remove the hack that pops config.
1985
+ request_dict.pop("config", None)
1986
+
1987
+ http_options: Optional[types.HttpOptions] = None
1988
+ if (
1989
+ parameter_model.config is not None
1990
+ and parameter_model.config.http_options is not None
1991
+ ):
1992
+ http_options = parameter_model.config.http_options
1993
+
1994
+ request_dict = _common.convert_to_dict(request_dict)
1995
+ request_dict = _common.encode_unserializable_types(request_dict)
1996
+
1997
+ response = self._api_client.request("get", path, request_dict, http_options)
1998
+
1999
+ response_dict = {} if not response.body else json.loads(response.body)
2000
+
2001
+ if self._api_client.vertexai:
2002
+ response_dict = _ListRagCorporaResponse_from_vertex(response_dict)
2003
+
2004
+ return_value = types.ListRagCorporaResponse._from_response(
2005
+ response=response_dict,
2006
+ kwargs=(
2007
+ {
2008
+ "config": {
2009
+ "response_schema": getattr(
2010
+ parameter_model.config, "response_schema", None
2011
+ ),
2012
+ "response_json_schema": getattr(
2013
+ parameter_model.config, "response_json_schema", None
2014
+ ),
2015
+ "include_all_fields": getattr(
2016
+ parameter_model.config, "include_all_fields", None
2017
+ ),
2018
+ }
2019
+ }
2020
+ if getattr(parameter_model, "config", None)
2021
+ else {}
2022
+ ),
2023
+ )
2024
+
2025
+ self._api_client._verify_response(return_value)
2026
+ return return_value
2027
+
2028
+ def get_file(
2029
+ self, *, config: Optional[types.GetRagFileConfigOrDict] = None, name: str
2030
+ ) -> types.RagFile:
2031
+ """
2032
+ Gets a RagFile.
2033
+
2034
+ Args:
2035
+ name: The name of the RagFile to retrieve.
2036
+ config: Optional configuration for the request.
2037
+
2038
+ Returns:
2039
+ The requested RagFile.
2040
+
2041
+ """
2042
+
2043
+ parameter_model = types._GetRagFileRequestParameters(
2044
+ config=config,
2045
+ name=name,
2046
+ )
2047
+
2048
+ request_url_dict: Optional[dict[str, str]]
2049
+ if not self._api_client.vertexai:
2050
+ raise ValueError(
2051
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2052
+ )
2053
+ else:
2054
+ request_dict = _GetRagFileRequestParameters_to_vertex(parameter_model)
2055
+ request_url_dict = request_dict.get("_url")
2056
+ if request_url_dict:
2057
+ path = "{name}".format_map(request_url_dict)
2058
+ else:
2059
+ path = "{name}"
2060
+
2061
+ query_params = request_dict.get("_query")
2062
+ if query_params:
2063
+ path = f"{path}?{urlencode(query_params)}"
2064
+ # TODO: remove the hack that pops config.
2065
+ request_dict.pop("config", None)
2066
+
2067
+ http_options: Optional[types.HttpOptions] = None
2068
+ if (
2069
+ parameter_model.config is not None
2070
+ and parameter_model.config.http_options is not None
2071
+ ):
2072
+ http_options = parameter_model.config.http_options
2073
+
2074
+ request_dict = _common.convert_to_dict(request_dict)
2075
+ request_dict = _common.encode_unserializable_types(request_dict)
2076
+
2077
+ response = self._api_client.request("get", path, request_dict, http_options)
2078
+
2079
+ response_dict = {} if not response.body else json.loads(response.body)
2080
+
2081
+ return_value = types.RagFile._from_response(
2082
+ response=response_dict,
2083
+ kwargs=(
2084
+ {
2085
+ "config": {
2086
+ "response_schema": getattr(
2087
+ parameter_model.config, "response_schema", None
2088
+ ),
2089
+ "response_json_schema": getattr(
2090
+ parameter_model.config, "response_json_schema", None
2091
+ ),
2092
+ "include_all_fields": getattr(
2093
+ parameter_model.config, "include_all_fields", None
2094
+ ),
2095
+ }
2096
+ }
2097
+ if getattr(parameter_model, "config", None)
2098
+ else {}
2099
+ ),
2100
+ )
2101
+
2102
+ self._api_client._verify_response(return_value)
2103
+ return return_value
2104
+
2105
+ def list_files(
2106
+ self, *, config: Optional[types.ListRagFilesConfigOrDict] = None, name: str
2107
+ ) -> types.ListRagFilesResponse:
2108
+ """
2109
+ Lists RagFile instances within a RagCorpus.
2110
+
2111
+ Args:
2112
+ name: The name of the RagCorpus to list files from.
2113
+ config: Optional configuration for the request (e.g., pagination details).
2114
+
2115
+ Returns:
2116
+ A ListRagFilesResponse containing the files.
2117
+
2118
+ """
2119
+
2120
+ parameter_model = types._ListRagFilesRequestParameters(
2121
+ config=config,
2122
+ name=name,
2123
+ )
2124
+
2125
+ request_url_dict: Optional[dict[str, str]]
2126
+ if not self._api_client.vertexai:
2127
+ raise ValueError(
2128
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2129
+ )
2130
+ else:
2131
+ request_dict = _ListRagFilesRequestParameters_to_vertex(parameter_model)
2132
+ request_url_dict = request_dict.get("_url")
2133
+ if request_url_dict:
2134
+ path = "{name}/ragFiles".format_map(request_url_dict)
2135
+ else:
2136
+ path = "{name}/ragFiles"
2137
+
2138
+ query_params = request_dict.get("_query")
2139
+ if query_params:
2140
+ path = f"{path}?{urlencode(query_params)}"
2141
+ # TODO: remove the hack that pops config.
2142
+ request_dict.pop("config", None)
2143
+
2144
+ http_options: Optional[types.HttpOptions] = None
2145
+ if (
2146
+ parameter_model.config is not None
2147
+ and parameter_model.config.http_options is not None
2148
+ ):
2149
+ http_options = parameter_model.config.http_options
2150
+
2151
+ request_dict = _common.convert_to_dict(request_dict)
2152
+ request_dict = _common.encode_unserializable_types(request_dict)
2153
+
2154
+ response = self._api_client.request("get", path, request_dict, http_options)
2155
+
2156
+ response_dict = {} if not response.body else json.loads(response.body)
2157
+
2158
+ return_value = types.ListRagFilesResponse._from_response(
2159
+ response=response_dict,
2160
+ kwargs=(
2161
+ {
2162
+ "config": {
2163
+ "response_schema": getattr(
2164
+ parameter_model.config, "response_schema", None
2165
+ ),
2166
+ "response_json_schema": getattr(
2167
+ parameter_model.config, "response_json_schema", None
2168
+ ),
2169
+ "include_all_fields": getattr(
2170
+ parameter_model.config, "include_all_fields", None
2171
+ ),
2172
+ }
2173
+ }
2174
+ if getattr(parameter_model, "config", None)
2175
+ else {}
2176
+ ),
2177
+ )
2178
+
2179
+ self._api_client._verify_response(return_value)
2180
+ return return_value
2181
+
2182
+ def get_config(
2183
+ self, *, config: Optional[types.GetRagConfigOrDict] = None
2184
+ ) -> types.RagEngineConfig:
2185
+ """
2186
+ Gets the project-level RAG Engine Config.
2187
+
2188
+ Args:
2189
+ config: Optional configuration for the request.
2190
+
2191
+ Returns:
2192
+ The requested RagEngineConfig.
2193
+
2194
+ """
2195
+
2196
+ parameter_model = types._GetRagConfigRequestParameters(
2197
+ config=config,
2198
+ )
2199
+
2200
+ request_url_dict: Optional[dict[str, str]]
2201
+ if not self._api_client.vertexai:
2202
+ raise ValueError(
2203
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2204
+ )
2205
+ else:
2206
+ request_dict = _GetRagConfigRequestParameters_to_vertex(parameter_model)
2207
+ request_url_dict = request_dict.get("_url")
2208
+ if request_url_dict:
2209
+ path = "ragEngineConfig".format_map(request_url_dict)
2210
+ else:
2211
+ path = "ragEngineConfig"
2212
+
2213
+ query_params = request_dict.get("_query")
2214
+ if query_params:
2215
+ path = f"{path}?{urlencode(query_params)}"
2216
+ # TODO: remove the hack that pops config.
2217
+ request_dict.pop("config", None)
2218
+
2219
+ http_options: Optional[types.HttpOptions] = None
2220
+ if (
2221
+ parameter_model.config is not None
2222
+ and parameter_model.config.http_options is not None
2223
+ ):
2224
+ http_options = parameter_model.config.http_options
2225
+
2226
+ request_dict = _common.convert_to_dict(request_dict)
2227
+ request_dict = _common.encode_unserializable_types(request_dict)
2228
+
2229
+ response = self._api_client.request("get", path, request_dict, http_options)
2230
+
2231
+ response_dict = {} if not response.body else json.loads(response.body)
2232
+
2233
+ if self._api_client.vertexai:
2234
+ response_dict = _RagEngineConfig_from_vertex(response_dict)
2235
+
2236
+ return_value = types.RagEngineConfig._from_response(
2237
+ response=response_dict,
2238
+ kwargs=(
2239
+ {
2240
+ "config": {
2241
+ "response_schema": getattr(
2242
+ parameter_model.config, "response_schema", None
2243
+ ),
2244
+ "response_json_schema": getattr(
2245
+ parameter_model.config, "response_json_schema", None
2246
+ ),
2247
+ "include_all_fields": getattr(
2248
+ parameter_model.config, "include_all_fields", None
2249
+ ),
2250
+ }
2251
+ }
2252
+ if getattr(parameter_model, "config", None)
2253
+ else {}
2254
+ ),
2255
+ )
2256
+
2257
+ self._api_client._verify_response(return_value)
2258
+ return return_value
2259
+
2260
+ def _update_corpus(
2261
+ self,
2262
+ *,
2263
+ config: Optional[types.UpdateRagCorpusConfigOrDict] = None,
2264
+ name: Optional[str] = None,
2265
+ rag_corpus: types.RagCorpusOrDict,
2266
+ ) -> types.UpdateRagCorpusOperation:
2267
+ """
2268
+ Updates an existing Rag Corpus.
2269
+ """
2270
+
2271
+ parameter_model = types._UpdateRagCorpusRequestParameters(
2272
+ config=config,
2273
+ name=name,
2274
+ rag_corpus=rag_corpus,
2275
+ )
2276
+
2277
+ request_url_dict: Optional[dict[str, str]]
2278
+ if not self._api_client.vertexai:
2279
+ raise ValueError(
2280
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2281
+ )
2282
+ else:
2283
+ request_dict = _UpdateRagCorpusRequestParameters_to_vertex(parameter_model)
2284
+ request_url_dict = request_dict.get("_url")
2285
+ if request_url_dict:
2286
+ path = "{name}".format_map(request_url_dict)
2287
+ else:
2288
+ path = "{name}"
2289
+
2290
+ query_params = request_dict.get("_query")
2291
+ if query_params:
2292
+ path = f"{path}?{urlencode(query_params)}"
2293
+ # TODO: remove the hack that pops config.
2294
+ request_dict.pop("config", None)
2295
+
2296
+ http_options: Optional[types.HttpOptions] = None
2297
+ if (
2298
+ parameter_model.config is not None
2299
+ and parameter_model.config.http_options is not None
2300
+ ):
2301
+ http_options = parameter_model.config.http_options
2302
+
2303
+ request_dict = _common.convert_to_dict(request_dict)
2304
+ request_dict = _common.encode_unserializable_types(request_dict)
2305
+
2306
+ response = self._api_client.request("patch", path, request_dict, http_options)
2307
+
2308
+ response_dict = {} if not response.body else json.loads(response.body)
2309
+
2310
+ return_value = types.UpdateRagCorpusOperation._from_response(
2311
+ response=response_dict,
2312
+ kwargs=(
2313
+ {
2314
+ "config": {
2315
+ "response_schema": getattr(
2316
+ parameter_model.config, "response_schema", None
2317
+ ),
2318
+ "response_json_schema": getattr(
2319
+ parameter_model.config, "response_json_schema", None
2320
+ ),
2321
+ "include_all_fields": getattr(
2322
+ parameter_model.config, "include_all_fields", None
2323
+ ),
2324
+ }
2325
+ }
2326
+ if getattr(parameter_model, "config", None)
2327
+ else {}
2328
+ ),
2329
+ )
2330
+
2331
+ self._api_client._verify_response(return_value)
2332
+ return return_value
2333
+
2334
+ def _delete_corpus(
2335
+ self,
2336
+ *,
2337
+ config: Optional[types.DeleteRagCorpusConfigOrDict] = None,
2338
+ name: Optional[str] = None,
2339
+ ) -> types.DeleteRagCorpusOperation:
2340
+ """
2341
+ Deletes a RAG Corpus.
2342
+ """
2343
+
2344
+ parameter_model = types._DeleteRagCorpusRequestParameters(
2345
+ config=config,
2346
+ name=name,
2347
+ )
2348
+
2349
+ request_url_dict: Optional[dict[str, str]]
2350
+ if not self._api_client.vertexai:
2351
+ raise ValueError(
2352
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2353
+ )
2354
+ else:
2355
+ request_dict = _DeleteRagCorpusRequestParameters_to_vertex(parameter_model)
2356
+ request_url_dict = request_dict.get("_url")
2357
+ if request_url_dict:
2358
+ path = "{name}".format_map(request_url_dict)
2359
+ else:
2360
+ path = "{name}"
2361
+
2362
+ query_params = request_dict.get("_query")
2363
+ if query_params:
2364
+ path = f"{path}?{urlencode(query_params)}"
2365
+ # TODO: remove the hack that pops config.
2366
+ request_dict.pop("config", None)
2367
+
2368
+ http_options: Optional[types.HttpOptions] = None
2369
+ if (
2370
+ parameter_model.config is not None
2371
+ and parameter_model.config.http_options is not None
2372
+ ):
2373
+ http_options = parameter_model.config.http_options
2374
+
2375
+ request_dict = _common.convert_to_dict(request_dict)
2376
+ request_dict = _common.encode_unserializable_types(request_dict)
2377
+
2378
+ response = self._api_client.request("delete", path, request_dict, http_options)
2379
+
2380
+ response_dict = {} if not response.body else json.loads(response.body)
2381
+
2382
+ return_value = types.DeleteRagCorpusOperation._from_response(
2383
+ response=response_dict,
2384
+ kwargs=(
2385
+ {
2386
+ "config": {
2387
+ "response_schema": getattr(
2388
+ parameter_model.config, "response_schema", None
2389
+ ),
2390
+ "response_json_schema": getattr(
2391
+ parameter_model.config, "response_json_schema", None
2392
+ ),
2393
+ "include_all_fields": getattr(
2394
+ parameter_model.config, "include_all_fields", None
2395
+ ),
2396
+ }
2397
+ }
2398
+ if getattr(parameter_model, "config", None)
2399
+ else {}
2400
+ ),
2401
+ )
2402
+
2403
+ self._api_client._verify_response(return_value)
2404
+ return return_value
2405
+
2406
+ def _delete_file(
2407
+ self, *, config: Optional[types.DeleteRagFileConfigOrDict] = None, name: str
2408
+ ) -> types.DeleteRagFileOperation:
2409
+ """
2410
+ Deletes a RAG File.
2411
+ """
2412
+
2413
+ parameter_model = types._DeleteRagFileRequestParameters(
2414
+ config=config,
2415
+ name=name,
2416
+ )
2417
+
2418
+ request_url_dict: Optional[dict[str, str]]
2419
+ if not self._api_client.vertexai:
2420
+ raise ValueError(
2421
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2422
+ )
2423
+ else:
2424
+ request_dict = _DeleteRagFileRequestParameters_to_vertex(parameter_model)
2425
+ request_url_dict = request_dict.get("_url")
2426
+ if request_url_dict:
2427
+ path = "{name}".format_map(request_url_dict)
2428
+ else:
2429
+ path = "{name}"
2430
+
2431
+ query_params = request_dict.get("_query")
2432
+ if query_params:
2433
+ path = f"{path}?{urlencode(query_params)}"
2434
+ # TODO: remove the hack that pops config.
2435
+ request_dict.pop("config", None)
2436
+
2437
+ http_options: Optional[types.HttpOptions] = None
2438
+ if (
2439
+ parameter_model.config is not None
2440
+ and parameter_model.config.http_options is not None
2441
+ ):
2442
+ http_options = parameter_model.config.http_options
2443
+
2444
+ request_dict = _common.convert_to_dict(request_dict)
2445
+ request_dict = _common.encode_unserializable_types(request_dict)
2446
+
2447
+ response = self._api_client.request("delete", path, request_dict, http_options)
2448
+
2449
+ response_dict = {} if not response.body else json.loads(response.body)
2450
+
2451
+ return_value = types.DeleteRagFileOperation._from_response(
2452
+ response=response_dict,
2453
+ kwargs=(
2454
+ {
2455
+ "config": {
2456
+ "response_schema": getattr(
2457
+ parameter_model.config, "response_schema", None
2458
+ ),
2459
+ "response_json_schema": getattr(
2460
+ parameter_model.config, "response_json_schema", None
2461
+ ),
2462
+ "include_all_fields": getattr(
2463
+ parameter_model.config, "include_all_fields", None
2464
+ ),
2465
+ }
2466
+ }
2467
+ if getattr(parameter_model, "config", None)
2468
+ else {}
2469
+ ),
2470
+ )
2471
+
2472
+ self._api_client._verify_response(return_value)
2473
+ return return_value
2474
+
2475
+ def _update_config(
2476
+ self,
2477
+ *,
2478
+ updated_config: types.RagEngineConfigOrDict,
2479
+ config: Optional[types.UpdateRagConfigOrDict] = None,
2480
+ ) -> types.UpdateRagConfigOperation:
2481
+ """
2482
+ Updates a RAG Engine Config.
2483
+ """
2484
+
2485
+ parameter_model = types._UpdateRagConfigRequestParameters(
2486
+ updated_config=updated_config,
2487
+ config=config,
2488
+ )
2489
+
2490
+ request_url_dict: Optional[dict[str, str]]
2491
+ if not self._api_client.vertexai:
2492
+ raise ValueError(
2493
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2494
+ )
2495
+ else:
2496
+ request_dict = _UpdateRagConfigRequestParameters_to_vertex(parameter_model)
2497
+ request_url_dict = request_dict.get("_url")
2498
+ if request_url_dict:
2499
+ path = "ragEngineConfig".format_map(request_url_dict)
2500
+ else:
2501
+ path = "ragEngineConfig"
2502
+
2503
+ query_params = request_dict.get("_query")
2504
+ if query_params:
2505
+ path = f"{path}?{urlencode(query_params)}"
2506
+ # TODO: remove the hack that pops config.
2507
+ request_dict.pop("config", None)
2508
+
2509
+ http_options: Optional[types.HttpOptions] = None
2510
+ if (
2511
+ parameter_model.config is not None
2512
+ and parameter_model.config.http_options is not None
2513
+ ):
2514
+ http_options = parameter_model.config.http_options
2515
+
2516
+ request_dict = _common.convert_to_dict(request_dict)
2517
+ request_dict = _common.encode_unserializable_types(request_dict)
2518
+
2519
+ response = self._api_client.request("patch", path, request_dict, http_options)
2520
+
2521
+ response_dict = {} if not response.body else json.loads(response.body)
2522
+
2523
+ return_value = types.UpdateRagConfigOperation._from_response(
2524
+ response=response_dict,
2525
+ kwargs=(
2526
+ {
2527
+ "config": {
2528
+ "response_schema": getattr(
2529
+ parameter_model.config, "response_schema", None
2530
+ ),
2531
+ "response_json_schema": getattr(
2532
+ parameter_model.config, "response_json_schema", None
2533
+ ),
2534
+ "include_all_fields": getattr(
2535
+ parameter_model.config, "include_all_fields", None
2536
+ ),
2537
+ }
2538
+ }
2539
+ if getattr(parameter_model, "config", None)
2540
+ else {}
2541
+ ),
2542
+ )
2543
+
2544
+ self._api_client._verify_response(return_value)
2545
+ return return_value
2546
+
2547
+ def retrieve_contexts(
2548
+ self,
2549
+ *,
2550
+ vertex_rag_store: genai_types.VertexRagStoreOrDict,
2551
+ query: types.RagQueryOrDict,
2552
+ config: Optional[types.RetrieveContextsConfigOrDict] = None,
2553
+ ) -> types.RetrieveContextsResponse:
2554
+ """
2555
+ Retrieves contexts from a Vertex RAG store based on a query.
2556
+
2557
+ Args:
2558
+ vertex_rag_store: The Vertex RAG store to retrieve contexts from.
2559
+ query: The query to retrieve contexts for.
2560
+ config: Optional configuration for the request.
2561
+
2562
+ Returns:
2563
+ The RetrieveContextsResponse containing the relevant contexts.
2564
+
2565
+ """
2566
+
2567
+ parameter_model = types._RetrieveRagContextsRequestParameters(
2568
+ vertex_rag_store=vertex_rag_store,
2569
+ query=query,
2570
+ config=config,
2571
+ )
2572
+
2573
+ request_url_dict: Optional[dict[str, str]]
2574
+ if not self._api_client.vertexai:
2575
+ raise ValueError(
2576
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2577
+ )
2578
+ else:
2579
+ request_dict = _RetrieveRagContextsRequestParameters_to_vertex(
2580
+ parameter_model
2581
+ )
2582
+ request_url_dict = request_dict.get("_url")
2583
+ if request_url_dict:
2584
+ path = ":retrieveContexts".format_map(request_url_dict)
2585
+ else:
2586
+ path = ":retrieveContexts"
2587
+
2588
+ query_params = request_dict.get("_query")
2589
+ if query_params:
2590
+ path = f"{path}?{urlencode(query_params)}"
2591
+ # TODO: remove the hack that pops config.
2592
+ request_dict.pop("config", None)
2593
+
2594
+ http_options: Optional[types.HttpOptions] = None
2595
+ if (
2596
+ parameter_model.config is not None
2597
+ and parameter_model.config.http_options is not None
2598
+ ):
2599
+ http_options = parameter_model.config.http_options
2600
+
2601
+ request_dict = _common.convert_to_dict(request_dict)
2602
+ request_dict = _common.encode_unserializable_types(request_dict)
2603
+
2604
+ response = self._api_client.request("post", path, request_dict, http_options)
2605
+
2606
+ response_dict = {} if not response.body else json.loads(response.body)
2607
+
2608
+ return_value = types.RetrieveContextsResponse._from_response(
2609
+ response=response_dict,
2610
+ kwargs=(
2611
+ {
2612
+ "config": {
2613
+ "response_schema": getattr(
2614
+ parameter_model.config, "response_schema", None
2615
+ ),
2616
+ "response_json_schema": getattr(
2617
+ parameter_model.config, "response_json_schema", None
2618
+ ),
2619
+ "include_all_fields": getattr(
2620
+ parameter_model.config, "include_all_fields", None
2621
+ ),
2622
+ }
2623
+ }
2624
+ if getattr(parameter_model, "config", None)
2625
+ else {}
2626
+ ),
2627
+ )
2628
+
2629
+ self._api_client._verify_response(return_value)
2630
+ return return_value
2631
+
2632
+ def _get_rag_config_operation(
2633
+ self,
2634
+ *,
2635
+ operation_name: str,
2636
+ config: Optional[types.GetRagConfigOperationConfigOrDict] = None,
2637
+ ) -> types.RagEngineConfigOperation:
2638
+ parameter_model = types._GetRagConfigOperationParameters(
2639
+ operation_name=operation_name,
2640
+ config=config,
2641
+ )
2642
+
2643
+ request_url_dict: Optional[dict[str, str]]
2644
+ if not self._api_client.vertexai:
2645
+ raise ValueError(
2646
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2647
+ )
2648
+ else:
2649
+ request_dict = _GetRagConfigOperationParameters_to_vertex(parameter_model)
2650
+ request_url_dict = request_dict.get("_url")
2651
+ if request_url_dict:
2652
+ path = "{operation_name}".format_map(request_url_dict)
2653
+ else:
2654
+ path = "{operation_name}"
2655
+
2656
+ query_params = request_dict.get("_query")
2657
+ if query_params:
2658
+ path = f"{path}?{urlencode(query_params)}"
2659
+ # TODO: remove the hack that pops config.
2660
+ request_dict.pop("config", None)
2661
+
2662
+ http_options: Optional[types.HttpOptions] = None
2663
+ if (
2664
+ parameter_model.config is not None
2665
+ and parameter_model.config.http_options is not None
2666
+ ):
2667
+ http_options = parameter_model.config.http_options
2668
+
2669
+ request_dict = _common.convert_to_dict(request_dict)
2670
+ request_dict = _common.encode_unserializable_types(request_dict)
2671
+
2672
+ response = self._api_client.request("get", path, request_dict, http_options)
2673
+
2674
+ response_dict = {} if not response.body else json.loads(response.body)
2675
+
2676
+ return_value = types.RagEngineConfigOperation._from_response(
2677
+ response=response_dict,
2678
+ kwargs=(
2679
+ {
2680
+ "config": {
2681
+ "response_schema": getattr(
2682
+ parameter_model.config, "response_schema", None
2683
+ ),
2684
+ "response_json_schema": getattr(
2685
+ parameter_model.config, "response_json_schema", None
2686
+ ),
2687
+ "include_all_fields": getattr(
2688
+ parameter_model.config, "include_all_fields", None
2689
+ ),
2690
+ }
2691
+ }
2692
+ if getattr(parameter_model, "config", None)
2693
+ else {}
2694
+ ),
2695
+ )
2696
+
2697
+ self._api_client._verify_response(return_value)
2698
+ return return_value
2699
+
2700
+ def _import_files(
2701
+ self,
2702
+ *,
2703
+ name: str,
2704
+ import_rag_files_request: types.ImportRagFilesRequestOrDict,
2705
+ config: Optional[types.ImportRagFilesRequestConfigOrDict] = None,
2706
+ ) -> types.ImportRagFilesOperation:
2707
+ """
2708
+ Imports files into a RAG Corpus.
2709
+ """
2710
+
2711
+ parameter_model = types._ImportRagFilesRequestParameters(
2712
+ name=name,
2713
+ import_rag_files_request=import_rag_files_request,
2714
+ config=config,
2715
+ )
2716
+
2717
+ request_url_dict: Optional[dict[str, str]]
2718
+ if not self._api_client.vertexai:
2719
+ raise ValueError(
2720
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2721
+ )
2722
+ else:
2723
+ request_dict = _ImportRagFilesRequestParameters_to_vertex(parameter_model)
2724
+ request_url_dict = request_dict.get("_url")
2725
+ if request_url_dict:
2726
+ path = "{name}/ragFiles:import".format_map(request_url_dict)
2727
+ else:
2728
+ path = "{name}/ragFiles:import"
2729
+
2730
+ query_params = request_dict.get("_query")
2731
+ if query_params:
2732
+ path = f"{path}?{urlencode(query_params)}"
2733
+ # TODO: remove the hack that pops config.
2734
+ request_dict.pop("config", None)
2735
+
2736
+ http_options: Optional[types.HttpOptions] = None
2737
+ if (
2738
+ parameter_model.config is not None
2739
+ and parameter_model.config.http_options is not None
2740
+ ):
2741
+ http_options = parameter_model.config.http_options
2742
+
2743
+ request_dict = _common.convert_to_dict(request_dict)
2744
+ request_dict = _common.encode_unserializable_types(request_dict)
2745
+
2746
+ response = self._api_client.request("post", path, request_dict, http_options)
2747
+
2748
+ response_dict = {} if not response.body else json.loads(response.body)
2749
+
2750
+ return_value = types.ImportRagFilesOperation._from_response(
2751
+ response=response_dict,
2752
+ kwargs=(
2753
+ {
2754
+ "config": {
2755
+ "response_schema": getattr(
2756
+ parameter_model.config, "response_schema", None
2757
+ ),
2758
+ "response_json_schema": getattr(
2759
+ parameter_model.config, "response_json_schema", None
2760
+ ),
2761
+ "include_all_fields": getattr(
2762
+ parameter_model.config, "include_all_fields", None
2763
+ ),
2764
+ }
2765
+ }
2766
+ if getattr(parameter_model, "config", None)
2767
+ else {}
2768
+ ),
2769
+ )
2770
+
2771
+ self._api_client._verify_response(return_value)
2772
+ return return_value
2773
+
2774
+ def _get_import_files_operation(
2775
+ self,
2776
+ *,
2777
+ operation_name: str,
2778
+ config: Optional[types.GetImportFilesOperationConfigOrDict] = None,
2779
+ ) -> types.ImportRagFilesOperation:
2780
+ parameter_model = types._GetImportFilesOperationParameters(
2781
+ operation_name=operation_name,
2782
+ config=config,
2783
+ )
2784
+
2785
+ request_url_dict: Optional[dict[str, str]]
2786
+ if not self._api_client.vertexai:
2787
+ raise ValueError(
2788
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2789
+ )
2790
+ else:
2791
+ request_dict = _GetImportFilesOperationParameters_to_vertex(parameter_model)
2792
+ request_url_dict = request_dict.get("_url")
2793
+ if request_url_dict:
2794
+ path = "{operation_name}".format_map(request_url_dict)
2795
+ else:
2796
+ path = "{operation_name}"
2797
+
2798
+ query_params = request_dict.get("_query")
2799
+ if query_params:
2800
+ path = f"{path}?{urlencode(query_params)}"
2801
+ # TODO: remove the hack that pops config.
2802
+ request_dict.pop("config", None)
2803
+
2804
+ http_options: Optional[types.HttpOptions] = None
2805
+ if (
2806
+ parameter_model.config is not None
2807
+ and parameter_model.config.http_options is not None
2808
+ ):
2809
+ http_options = parameter_model.config.http_options
2810
+
2811
+ request_dict = _common.convert_to_dict(request_dict)
2812
+ request_dict = _common.encode_unserializable_types(request_dict)
2813
+
2814
+ response = self._api_client.request("get", path, request_dict, http_options)
2815
+
2816
+ response_dict = {} if not response.body else json.loads(response.body)
2817
+
2818
+ return_value = types.ImportRagFilesOperation._from_response(
2819
+ response=response_dict,
2820
+ kwargs=(
2821
+ {
2822
+ "config": {
2823
+ "response_schema": getattr(
2824
+ parameter_model.config, "response_schema", None
2825
+ ),
2826
+ "response_json_schema": getattr(
2827
+ parameter_model.config, "response_json_schema", None
2828
+ ),
2829
+ "include_all_fields": getattr(
2830
+ parameter_model.config, "include_all_fields", None
2831
+ ),
2832
+ }
2833
+ }
2834
+ if getattr(parameter_model, "config", None)
2835
+ else {}
2836
+ ),
2837
+ )
2838
+
2839
+ self._api_client._verify_response(return_value)
2840
+ return return_value
2841
+
2842
+ def _upload_file(
2843
+ self,
2844
+ *,
2845
+ name: str,
2846
+ rag_file: types.RagFileOrDict,
2847
+ upload_rag_file_config: Optional[types.UploadRagFileConfigOrDict] = None,
2848
+ config: Optional[types.UploadRagFileRequestConfigOrDict] = None,
2849
+ ) -> types.UploadRagFileResponse:
2850
+ parameter_model = types._UploadRagFileParameters(
2851
+ name=name,
2852
+ rag_file=rag_file,
2853
+ upload_rag_file_config=upload_rag_file_config,
2854
+ config=config,
2855
+ )
2856
+
2857
+ request_url_dict: Optional[dict[str, str]]
2858
+ if not self._api_client.vertexai:
2859
+ raise ValueError(
2860
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
2861
+ )
2862
+ else:
2863
+ request_dict = _UploadRagFileParameters_to_vertex(parameter_model)
2864
+ request_url_dict = request_dict.get("_url")
2865
+ if request_url_dict:
2866
+ path = "{name}/ragFiles:upload".format_map(request_url_dict)
2867
+ else:
2868
+ path = "{name}/ragFiles:upload"
2869
+
2870
+ query_params = request_dict.get("_query")
2871
+ if query_params:
2872
+ path = f"{path}?{urlencode(query_params)}"
2873
+ # TODO: remove the hack that pops config.
2874
+ request_dict.pop("config", None)
2875
+
2876
+ http_options: Optional[types.HttpOptions] = None
2877
+ if (
2878
+ parameter_model.config is not None
2879
+ and parameter_model.config.http_options is not None
2880
+ ):
2881
+ http_options = parameter_model.config.http_options
2882
+
2883
+ request_dict = _common.convert_to_dict(request_dict)
2884
+ request_dict = _common.encode_unserializable_types(request_dict)
2885
+
2886
+ response = self._api_client.request("post", path, request_dict, http_options)
2887
+
2888
+ response_dict = {} if not response.body else json.loads(response.body)
2889
+
2890
+ return_value = types.UploadRagFileResponse._from_response(
2891
+ response=response_dict,
2892
+ kwargs=(
2893
+ {
2894
+ "config": {
2895
+ "response_schema": getattr(
2896
+ parameter_model.config, "response_schema", None
2897
+ ),
2898
+ "response_json_schema": getattr(
2899
+ parameter_model.config, "response_json_schema", None
2900
+ ),
2901
+ "include_all_fields": getattr(
2902
+ parameter_model.config, "include_all_fields", None
2903
+ ),
2904
+ }
2905
+ }
2906
+ if getattr(parameter_model, "config", None)
2907
+ else {}
2908
+ ),
2909
+ )
2910
+
2911
+ self._api_client._verify_response(return_value)
2912
+ return return_value
2913
+
2914
+ def create_corpus(
2915
+ self,
2916
+ *,
2917
+ rag_corpus: types.RagCorpusOrDict,
2918
+ config: Optional[types.CreateRagCorpusConfigOrDict] = None,
2919
+ ) -> types.RagCorpus:
2920
+ """
2921
+ Creates a new RAG Corpus and waits for completion.
2922
+
2923
+ Args:
2924
+ rag_corpus: The RagCorpus to create.
2925
+ config: The configuration to use for the RagCorpus.
2926
+
2927
+ Returns:
2928
+ The created RagCorpus.
2929
+
2930
+ Example usage:
2931
+
2932
+ ```
2933
+ corpus = client.rag.create_corpus(
2934
+ rag_corpus=types.RagCorpus(
2935
+ display_name="test-corpus",
2936
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
2937
+ ),
2938
+ )
2939
+ ```
2940
+ """
2941
+ operation = self._create_corpus(rag_corpus=rag_corpus, config=config)
2942
+
2943
+ operation = _operations_utils.await_operation(
2944
+ operation_name=operation.name,
2945
+ get_operation_fn=self._get_corpus_operation,
2946
+ )
2947
+
2948
+ if operation.error:
2949
+ raise RuntimeError(
2950
+ f"Operation {operation.name} failed to create RagCorpus: {operation.error}"
2951
+ )
2952
+
2953
+ return self.get_corpus(name=operation.response.name)
2954
+
2955
+ def delete_corpus(
2956
+ self,
2957
+ *,
2958
+ name: str,
2959
+ config: Optional[types.DeleteRagCorpusConfigOrDict] = None,
2960
+ ) -> None:
2961
+ """
2962
+ Deletes a RAG Corpus and waits for the delete operation to complete.
2963
+
2964
+ Args:
2965
+ name: The name of the RagCorpus to delete, formatted as
2966
+ `projects/{project}/locations/{location}/ragCorpora/{corpus_id}`.
2967
+ config: The configuration to use for the RagCorpus delete request.
2968
+
2969
+ Example usage:
2970
+
2971
+ ```
2972
+ client.rag.delete_corpus(
2973
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
2974
+ )
2975
+ ```
2976
+ """
2977
+
2978
+ operation = self._delete_corpus(name=name, config=config)
2979
+
2980
+ operation = _operations_utils.await_operation(
2981
+ operation_name=operation.name,
2982
+ get_operation_fn=self._get_corpus_operation,
2983
+ )
2984
+
2985
+ if operation.error:
2986
+ raise RuntimeError(
2987
+ f"Operation {operation.name} failed to delete RagCorpus: {operation.error}"
2988
+ )
2989
+
2990
+ return None
2991
+
2992
+ def delete_file(
2993
+ self,
2994
+ *,
2995
+ name: str,
2996
+ config: Optional[types.DeleteRagFileConfigOrDict] = None,
2997
+ ) -> None:
2998
+ """
2999
+ Deletes a file from a RAG Corpus and waits for the delete operation to complete.
3000
+
3001
+ Args:
3002
+ name: The name of the RagFile to delete, formatted as
3003
+ `projects/{project}/locations/{location}/ragCorpora/{corpus_id}/ragFiles/{file_id}`.
3004
+ config: The configuration to use for the RagFile delete request.
3005
+
3006
+ Example usage:
3007
+
3008
+ ```
3009
+ client.rag.delete_file(
3010
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragFiles/987654321",
3011
+ )
3012
+ ```
3013
+ """
3014
+ operation = self._delete_file(name=name, config=config)
3015
+
3016
+ operation = _operations_utils.await_operation(
3017
+ operation_name=operation.name,
3018
+ get_operation_fn=self._get_corpus_operation,
3019
+ )
3020
+
3021
+ if operation.error:
3022
+ raise RuntimeError(
3023
+ f"Operation {operation.name} failed to delete file from RagCorpus: {operation.error}"
3024
+ )
3025
+
3026
+ return None
3027
+
3028
+ def update_corpus(
3029
+ self,
3030
+ *,
3031
+ name: str,
3032
+ rag_corpus: types.RagCorpusOrDict,
3033
+ config: Optional[types.UpdateRagCorpusConfigOrDict] = None,
3034
+ ) -> types.RagCorpus:
3035
+ """
3036
+ Updates a RAG Corpus and waits for completion.
3037
+
3038
+ Args:
3039
+ name: The name of the RagCorpus to update, formatted as
3040
+ `projects/{project}/locations/{location}/ragCorpora/{corpus_id}`.
3041
+ rag_corpus: The RagCorpus to update.
3042
+ config: The configuration to use for the RagCorpus update request.
3043
+
3044
+ Returns:
3045
+ The updated RagCorpus.
3046
+
3047
+ Example usage:
3048
+
3049
+ ```
3050
+ client.rag.update_corpus(
3051
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
3052
+ rag_corpus=types.RagCorpus(
3053
+ display_name="Updated corpus name",
3054
+ ),
3055
+ )
3056
+ ```
3057
+ """
3058
+
3059
+ operation = self._update_corpus(name=name, rag_corpus=rag_corpus, config=config)
3060
+
3061
+ operation = _operations_utils.await_operation(
3062
+ operation_name=operation.name,
3063
+ get_operation_fn=self._get_corpus_operation,
3064
+ )
3065
+
3066
+ if operation.error:
3067
+ raise RuntimeError(
3068
+ f"Operation {operation.name} failed to update RagCorpus: {operation.error}"
3069
+ )
3070
+
3071
+ return self.get_corpus(name=operation.response.name)
3072
+
3073
+ def update_config(
3074
+ self,
3075
+ *,
3076
+ updated_config: types.RagEngineConfigOrDict,
3077
+ request_config: Optional[types.UpdateRagConfigOrDict] = None,
3078
+ ) -> types.RagEngineConfig:
3079
+ """
3080
+ Updates a RagEngineConfig and waits for completion.
3081
+
3082
+ Args:
3083
+ updated_config: The RagEngineConfig to update.
3084
+ request_config: The configuration to use for the RagEngineConfig update request.
3085
+
3086
+ Returns:
3087
+ The updated RagEngineConfig.
3088
+
3089
+ Example usage:
3090
+
3091
+ ```
3092
+ client.rag.update_config(
3093
+ updated_config=types.RagEngineConfig(
3094
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragEngineConfig/123456789",
3095
+ rag_managed_db_config=types.RagManagedDbConfig(
3096
+ basic=types.RagManagedDbConfigBasic()
3097
+ ),
3098
+ ),
3099
+ )
3100
+ ```
3101
+ """
3102
+ operation = self._update_config(
3103
+ updated_config=updated_config, config=request_config
3104
+ )
3105
+
3106
+ operation = _operations_utils.await_operation(
3107
+ operation_name=operation.name,
3108
+ get_operation_fn=self._get_rag_config_operation,
3109
+ )
3110
+
3111
+ if operation.error:
3112
+ raise RuntimeError(
3113
+ f"Operation {operation.name} failed to update RagEngineConfig: {operation.error}"
3114
+ )
3115
+
3116
+ return self.get_config()
3117
+
3118
+ def import_files(
3119
+ self,
3120
+ *,
3121
+ name: str,
3122
+ import_config: types.ImportRagFilesConfigOrDict,
3123
+ config: Optional[types.ImportRagFilesRequestConfigOrDict] = None,
3124
+ ) -> types.ImportRagFilesResponse:
3125
+ """
3126
+ Imports files into a Rag Corpus. To get a list of all files on the corpus after calling import_files, call list_files.
3127
+
3128
+ Args:
3129
+ name: The name of the Rag Corpus to import files into, format:
3130
+ `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
3131
+ import_config: The configuration for importing files, including source files and processing options.
3132
+ config: The configuration to use for the import request.
3133
+
3134
+ Returns:
3135
+ The ImportRagFilesResponse from the import files operation.
3136
+
3137
+ Example usage:
3138
+
3139
+ ```
3140
+ import_files_response = client.rag.import_files(
3141
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
3142
+ import_config=types.ImportRagFilesConfig(
3143
+ gcs_source=types.GcsSource(uris=["gs://test-bucket/test-file.pdf"]),
3144
+ ),
3145
+ )
3146
+ ```
3147
+ """
3148
+ if isinstance(import_config, dict):
3149
+ import_config = types.ImportRagFilesConfig.model_validate(import_config)
3150
+
3151
+ if import_config.gcs_source is not None:
3152
+ for uri in import_config.gcs_source.uris:
3153
+ if not _gcs_utils.GcsUtils(self._api_client)._verify_bucket_ownership(
3154
+ bucket_name=uri.split("/")[2],
3155
+ expected_project=self._api_client.project,
3156
+ ):
3157
+ raise ValueError(
3158
+ f"Bucket {uri} does not belong to"
3159
+ f" project {self._api_client.project}."
3160
+ )
3161
+
3162
+ operation = self._import_files(
3163
+ name=name,
3164
+ import_rag_files_request=types.ImportRagFilesRequest(
3165
+ import_rag_files_config=import_config
3166
+ ),
3167
+ config=config,
3168
+ )
3169
+
3170
+ operation = _operations_utils.await_operation(
3171
+ operation_name=operation.name,
3172
+ get_operation_fn=self._get_import_files_operation,
3173
+ )
3174
+
3175
+ if operation.error:
3176
+ raise RuntimeError(
3177
+ f"Operation {operation.name} failed to import files into RagCorpus: {operation.error}"
3178
+ )
3179
+
3180
+ return operation.response
3181
+
3182
+ def upload_file(
3183
+ self,
3184
+ *,
3185
+ corpus_name: str,
3186
+ path: str,
3187
+ display_name: Optional[str] = None,
3188
+ upload_rag_file_config: Optional[types.UploadRagFileConfigOrDict] = None,
3189
+ request_config: Optional[types.UploadRagFileRequestConfigOrDict] = None,
3190
+ ) -> types.RagFile:
3191
+ """
3192
+ Uploads a file to a RAG Corpus.
3193
+
3194
+ Args:
3195
+ corpus_name: The name of the RAG Corpus to upload to.
3196
+ path: The path to the file to upload.
3197
+ display_name: Optional. The display name for the uploaded file. If not provided, a display name will be generated.
3198
+ upload_rag_file_config: Optional. The configuration to use for the upload.
3199
+ request_config: Optional. The configuration to use for the request.
3200
+
3201
+ Returns:
3202
+ The uploaded RagFile.
3203
+
3204
+ Example usage:
3205
+
3206
+ ```
3207
+ rag_file = client.rag.upload_file(
3208
+ corpus_name="projects/test-project/locations/us-central1/ragCorpora/123456789",
3209
+ path="/path/to/file.pdf",
3210
+ display_name="test-file",
3211
+ upload_rag_file_config=types.UploadRagFileConfig(
3212
+ chunk_config=types.ChunkConfig(
3213
+ chunk_size=1024,
3214
+ chunk_overlap=128,
3215
+ ),
3216
+ ),
3217
+ )
3218
+ ```
3219
+ """
3220
+
3221
+ if not display_name:
3222
+ display_name = f"file_{_common.timestamped_unique_name()}"
3223
+
3224
+ rag_file = types.RagFile(display_name=display_name)
3225
+
3226
+ mime_type, _ = mimetypes.guess_type(path)
3227
+
3228
+ if mime_type is None:
3229
+ mime_type = "application/octet-stream"
3230
+
3231
+ http_options, size_bytes, mime_type = _extra_utils.prepare_resumable_upload(
3232
+ path,
3233
+ user_http_options=request_config.http_options if request_config else None,
3234
+ user_mime_type=mime_type,
3235
+ )
3236
+
3237
+ current_api_version = self._api_client._http_options.api_version or "v1beta1"
3238
+ upload_api_version = f"upload/{current_api_version}"
3239
+
3240
+ http_options.api_version = upload_api_version
3241
+
3242
+ parameter_model = types._UploadRagFileParameters(
3243
+ name=corpus_name,
3244
+ rag_file=rag_file,
3245
+ upload_rag_file_config=upload_rag_file_config,
3246
+ )
3247
+ request_dict = _UploadRagFileParameters_to_vertex(parameter_model)
3248
+
3249
+ request_dict.pop("_url", None)
3250
+ request_dict.pop("_query", None)
3251
+
3252
+ request_path = f"{corpus_name}/ragFiles:upload"
3253
+
3254
+ request_dict = _common.convert_to_dict(request_dict)
3255
+ request_dict = _common.encode_unserializable_types(request_dict)
3256
+
3257
+ response = self._api_client.request(
3258
+ "post",
3259
+ request_path,
3260
+ request_dict,
3261
+ http_options,
3262
+ )
3263
+
3264
+ if response.headers is None or (
3265
+ "x-goog-upload-url" not in response.headers
3266
+ and "X-Goog-Upload-URL" not in response.headers
3267
+ ):
3268
+ raise KeyError(
3269
+ "Failed to create file. Upload URL was not returned from the create file request."
3270
+ )
3271
+
3272
+ upload_url = response.headers.get(
3273
+ "x-goog-upload-url", response.headers.get("X-Goog-Upload-URL")
3274
+ )
3275
+
3276
+ fs_path = os.fspath(path)
3277
+ return_file = self._api_client.upload_file(
3278
+ fs_path, upload_url, size_bytes, http_options=http_options
3279
+ )
3280
+
3281
+ rag_file_payload = return_file.json.get("ragFile") or return_file.json.get(
3282
+ "rag_file", {}
3283
+ )
3284
+ return types.RagFile(**rag_file_payload)
3285
+
3286
+
3287
+ class AsyncRag(_api_module.BaseModule):
3288
+
3289
+ async def ask_contexts(
3290
+ self,
3291
+ *,
3292
+ query: types.RagQueryOrDict,
3293
+ config: Optional[types.AskContextsConfigOrDict] = None,
3294
+ ) -> types.AskContextsResponse:
3295
+ """
3296
+ Agentic Retrieval Ask API for RAG.
3297
+
3298
+ Args:
3299
+ query: The query to ask.
3300
+ config: Optional configuration for the request.
3301
+
3302
+ Returns:
3303
+ The AskContextsResponse.
3304
+
3305
+ """
3306
+
3307
+ parameter_model = types._AskContextsRequestParameters(
3308
+ query=query,
3309
+ config=config,
3310
+ )
3311
+
3312
+ request_url_dict: Optional[dict[str, str]]
3313
+ if not self._api_client.vertexai:
3314
+ raise ValueError(
3315
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3316
+ )
3317
+ else:
3318
+ request_dict = _AskContextsRequestParameters_to_vertex(parameter_model)
3319
+ request_url_dict = request_dict.get("_url")
3320
+ if request_url_dict:
3321
+ path = ":askContexts".format_map(request_url_dict)
3322
+ else:
3323
+ path = ":askContexts"
3324
+
3325
+ query_params = request_dict.get("_query")
3326
+ if query_params:
3327
+ path = f"{path}?{urlencode(query_params)}"
3328
+ # TODO: remove the hack that pops config.
3329
+ request_dict.pop("config", None)
3330
+
3331
+ http_options: Optional[types.HttpOptions] = None
3332
+ if (
3333
+ parameter_model.config is not None
3334
+ and parameter_model.config.http_options is not None
3335
+ ):
3336
+ http_options = parameter_model.config.http_options
3337
+
3338
+ request_dict = _common.convert_to_dict(request_dict)
3339
+ request_dict = _common.encode_unserializable_types(request_dict)
3340
+
3341
+ response = await self._api_client.async_request(
3342
+ "post", path, request_dict, http_options
3343
+ )
3344
+
3345
+ response_dict = {} if not response.body else json.loads(response.body)
3346
+
3347
+ return_value = types.AskContextsResponse._from_response(
3348
+ response=response_dict,
3349
+ kwargs=(
3350
+ {
3351
+ "config": {
3352
+ "response_schema": getattr(
3353
+ parameter_model.config, "response_schema", None
3354
+ ),
3355
+ "response_json_schema": getattr(
3356
+ parameter_model.config, "response_json_schema", None
3357
+ ),
3358
+ "include_all_fields": getattr(
3359
+ parameter_model.config, "include_all_fields", None
3360
+ ),
3361
+ }
3362
+ }
3363
+ if getattr(parameter_model, "config", None)
3364
+ else {}
3365
+ ),
3366
+ )
3367
+
3368
+ self._api_client._verify_response(return_value)
3369
+ return return_value
3370
+
3371
+ async def _create_corpus(
3372
+ self,
3373
+ *,
3374
+ rag_corpus: types.RagCorpusOrDict,
3375
+ config: Optional[types.CreateRagCorpusConfigOrDict] = None,
3376
+ ) -> types.CreateRagCorpusOperation:
3377
+ """
3378
+ Creates a new Rag Corpus.
3379
+ """
3380
+
3381
+ parameter_model = types._CreateRagCorpusRequestParameters(
3382
+ rag_corpus=rag_corpus,
3383
+ config=config,
3384
+ )
3385
+
3386
+ request_url_dict: Optional[dict[str, str]]
3387
+ if not self._api_client.vertexai:
3388
+ raise ValueError(
3389
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3390
+ )
3391
+ else:
3392
+ request_dict = _CreateRagCorpusRequestParameters_to_vertex(parameter_model)
3393
+ request_url_dict = request_dict.get("_url")
3394
+ if request_url_dict:
3395
+ path = "ragCorpora".format_map(request_url_dict)
3396
+ else:
3397
+ path = "ragCorpora"
3398
+
3399
+ query_params = request_dict.get("_query")
3400
+ if query_params:
3401
+ path = f"{path}?{urlencode(query_params)}"
3402
+ # TODO: remove the hack that pops config.
3403
+ request_dict.pop("config", None)
3404
+
3405
+ http_options: Optional[types.HttpOptions] = None
3406
+ if (
3407
+ parameter_model.config is not None
3408
+ and parameter_model.config.http_options is not None
3409
+ ):
3410
+ http_options = parameter_model.config.http_options
3411
+
3412
+ request_dict = _common.convert_to_dict(request_dict)
3413
+ request_dict = _common.encode_unserializable_types(request_dict)
3414
+
3415
+ response = await self._api_client.async_request(
3416
+ "post", path, request_dict, http_options
3417
+ )
3418
+
3419
+ response_dict = {} if not response.body else json.loads(response.body)
3420
+
3421
+ return_value = types.CreateRagCorpusOperation._from_response(
3422
+ response=response_dict,
3423
+ kwargs=(
3424
+ {
3425
+ "config": {
3426
+ "response_schema": getattr(
3427
+ parameter_model.config, "response_schema", None
3428
+ ),
3429
+ "response_json_schema": getattr(
3430
+ parameter_model.config, "response_json_schema", None
3431
+ ),
3432
+ "include_all_fields": getattr(
3433
+ parameter_model.config, "include_all_fields", None
3434
+ ),
3435
+ }
3436
+ }
3437
+ if getattr(parameter_model, "config", None)
3438
+ else {}
3439
+ ),
3440
+ )
3441
+
3442
+ self._api_client._verify_response(return_value)
3443
+ return return_value
3444
+
3445
+ async def _get_corpus_operation(
3446
+ self,
3447
+ *,
3448
+ operation_name: str,
3449
+ config: Optional[types.GetCorpusOperationConfigOrDict] = None,
3450
+ ) -> types.CorpusOperation:
3451
+ parameter_model = types._GetCorpusOperationParameters(
3452
+ operation_name=operation_name,
3453
+ config=config,
3454
+ )
3455
+
3456
+ request_url_dict: Optional[dict[str, str]]
3457
+ if not self._api_client.vertexai:
3458
+ raise ValueError(
3459
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3460
+ )
3461
+ else:
3462
+ request_dict = _GetCorpusOperationParameters_to_vertex(parameter_model)
3463
+ request_url_dict = request_dict.get("_url")
3464
+ if request_url_dict:
3465
+ path = "{operationName}".format_map(request_url_dict)
3466
+ else:
3467
+ path = "{operationName}"
3468
+
3469
+ query_params = request_dict.get("_query")
3470
+ if query_params:
3471
+ path = f"{path}?{urlencode(query_params)}"
3472
+ # TODO: remove the hack that pops config.
3473
+ request_dict.pop("config", None)
3474
+
3475
+ http_options: Optional[types.HttpOptions] = None
3476
+ if (
3477
+ parameter_model.config is not None
3478
+ and parameter_model.config.http_options is not None
3479
+ ):
3480
+ http_options = parameter_model.config.http_options
3481
+
3482
+ request_dict = _common.convert_to_dict(request_dict)
3483
+ request_dict = _common.encode_unserializable_types(request_dict)
3484
+
3485
+ response = await self._api_client.async_request(
3486
+ "get", path, request_dict, http_options
3487
+ )
3488
+
3489
+ response_dict = {} if not response.body else json.loads(response.body)
3490
+
3491
+ if self._api_client.vertexai:
3492
+ response_dict = _CorpusOperation_from_vertex(response_dict)
3493
+
3494
+ return_value = types.CorpusOperation._from_response(
3495
+ response=response_dict,
3496
+ kwargs=(
3497
+ {
3498
+ "config": {
3499
+ "response_schema": getattr(
3500
+ parameter_model.config, "response_schema", None
3501
+ ),
3502
+ "response_json_schema": getattr(
3503
+ parameter_model.config, "response_json_schema", None
3504
+ ),
3505
+ "include_all_fields": getattr(
3506
+ parameter_model.config, "include_all_fields", None
3507
+ ),
3508
+ }
3509
+ }
3510
+ if getattr(parameter_model, "config", None)
3511
+ else {}
3512
+ ),
3513
+ )
3514
+
3515
+ self._api_client._verify_response(return_value)
3516
+ return return_value
3517
+
3518
+ async def get_corpus(
3519
+ self, *, config: Optional[types.GetRagCorpusConfigOrDict] = None, name: str
3520
+ ) -> types.RagCorpus:
3521
+ """
3522
+ Gets a RAG Corpus.
3523
+
3524
+ Args:
3525
+ name: The name of the RagCorpus to retrieve.
3526
+ config: Optional configuration for the request.
3527
+
3528
+ Returns:
3529
+ The requested RagCorpus.
3530
+
3531
+ """
3532
+
3533
+ parameter_model = types._GetRagCorpusRequestParameters(
3534
+ config=config,
3535
+ name=name,
3536
+ )
3537
+
3538
+ request_url_dict: Optional[dict[str, str]]
3539
+ if not self._api_client.vertexai:
3540
+ raise ValueError(
3541
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3542
+ )
3543
+ else:
3544
+ request_dict = _GetRagCorpusRequestParameters_to_vertex(parameter_model)
3545
+ request_url_dict = request_dict.get("_url")
3546
+ if request_url_dict:
3547
+ path = "{name}".format_map(request_url_dict)
3548
+ else:
3549
+ path = "{name}"
3550
+
3551
+ query_params = request_dict.get("_query")
3552
+ if query_params:
3553
+ path = f"{path}?{urlencode(query_params)}"
3554
+ # TODO: remove the hack that pops config.
3555
+ request_dict.pop("config", None)
3556
+
3557
+ http_options: Optional[types.HttpOptions] = None
3558
+ if (
3559
+ parameter_model.config is not None
3560
+ and parameter_model.config.http_options is not None
3561
+ ):
3562
+ http_options = parameter_model.config.http_options
3563
+
3564
+ request_dict = _common.convert_to_dict(request_dict)
3565
+ request_dict = _common.encode_unserializable_types(request_dict)
3566
+
3567
+ response = await self._api_client.async_request(
3568
+ "get", path, request_dict, http_options
3569
+ )
3570
+
3571
+ response_dict = {} if not response.body else json.loads(response.body)
3572
+
3573
+ if self._api_client.vertexai:
3574
+ response_dict = _RagCorpus_from_vertex(response_dict)
3575
+
3576
+ return_value = types.RagCorpus._from_response(
3577
+ response=response_dict,
3578
+ kwargs=(
3579
+ {
3580
+ "config": {
3581
+ "response_schema": getattr(
3582
+ parameter_model.config, "response_schema", None
3583
+ ),
3584
+ "response_json_schema": getattr(
3585
+ parameter_model.config, "response_json_schema", None
3586
+ ),
3587
+ "include_all_fields": getattr(
3588
+ parameter_model.config, "include_all_fields", None
3589
+ ),
3590
+ }
3591
+ }
3592
+ if getattr(parameter_model, "config", None)
3593
+ else {}
3594
+ ),
3595
+ )
3596
+
3597
+ self._api_client._verify_response(return_value)
3598
+ return return_value
3599
+
3600
+ async def list_corpora(
3601
+ self, *, config: Optional[types.ListRagCorporaConfigOrDict] = None
3602
+ ) -> types.ListRagCorporaResponse:
3603
+ """
3604
+ Lists RagCorpora for a project.
3605
+
3606
+ Args:
3607
+ config: Optional configuration for listing corpora.
3608
+
3609
+ Returns:
3610
+ A ListRagCorporaResponse containing the corpora.
3611
+
3612
+ """
3613
+
3614
+ parameter_model = types._ListRagCorporaRequestParameters(
3615
+ config=config,
3616
+ )
3617
+
3618
+ request_url_dict: Optional[dict[str, str]]
3619
+ if not self._api_client.vertexai:
3620
+ raise ValueError(
3621
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3622
+ )
3623
+ else:
3624
+ request_dict = _ListRagCorporaRequestParameters_to_vertex(parameter_model)
3625
+ request_url_dict = request_dict.get("_url")
3626
+ if request_url_dict:
3627
+ path = "ragCorpora".format_map(request_url_dict)
3628
+ else:
3629
+ path = "ragCorpora"
3630
+
3631
+ query_params = request_dict.get("_query")
3632
+ if query_params:
3633
+ path = f"{path}?{urlencode(query_params)}"
3634
+ # TODO: remove the hack that pops config.
3635
+ request_dict.pop("config", None)
3636
+
3637
+ http_options: Optional[types.HttpOptions] = None
3638
+ if (
3639
+ parameter_model.config is not None
3640
+ and parameter_model.config.http_options is not None
3641
+ ):
3642
+ http_options = parameter_model.config.http_options
3643
+
3644
+ request_dict = _common.convert_to_dict(request_dict)
3645
+ request_dict = _common.encode_unserializable_types(request_dict)
3646
+
3647
+ response = await self._api_client.async_request(
3648
+ "get", path, request_dict, http_options
3649
+ )
3650
+
3651
+ response_dict = {} if not response.body else json.loads(response.body)
3652
+
3653
+ if self._api_client.vertexai:
3654
+ response_dict = _ListRagCorporaResponse_from_vertex(response_dict)
3655
+
3656
+ return_value = types.ListRagCorporaResponse._from_response(
3657
+ response=response_dict,
3658
+ kwargs=(
3659
+ {
3660
+ "config": {
3661
+ "response_schema": getattr(
3662
+ parameter_model.config, "response_schema", None
3663
+ ),
3664
+ "response_json_schema": getattr(
3665
+ parameter_model.config, "response_json_schema", None
3666
+ ),
3667
+ "include_all_fields": getattr(
3668
+ parameter_model.config, "include_all_fields", None
3669
+ ),
3670
+ }
3671
+ }
3672
+ if getattr(parameter_model, "config", None)
3673
+ else {}
3674
+ ),
3675
+ )
3676
+
3677
+ self._api_client._verify_response(return_value)
3678
+ return return_value
3679
+
3680
+ async def get_file(
3681
+ self, *, config: Optional[types.GetRagFileConfigOrDict] = None, name: str
3682
+ ) -> types.RagFile:
3683
+ """
3684
+ Gets a RagFile.
3685
+
3686
+ Args:
3687
+ name: The name of the RagFile to retrieve.
3688
+ config: Optional configuration for the request.
3689
+
3690
+ Returns:
3691
+ The requested RagFile.
3692
+
3693
+ """
3694
+
3695
+ parameter_model = types._GetRagFileRequestParameters(
3696
+ config=config,
3697
+ name=name,
3698
+ )
3699
+
3700
+ request_url_dict: Optional[dict[str, str]]
3701
+ if not self._api_client.vertexai:
3702
+ raise ValueError(
3703
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3704
+ )
3705
+ else:
3706
+ request_dict = _GetRagFileRequestParameters_to_vertex(parameter_model)
3707
+ request_url_dict = request_dict.get("_url")
3708
+ if request_url_dict:
3709
+ path = "{name}".format_map(request_url_dict)
3710
+ else:
3711
+ path = "{name}"
3712
+
3713
+ query_params = request_dict.get("_query")
3714
+ if query_params:
3715
+ path = f"{path}?{urlencode(query_params)}"
3716
+ # TODO: remove the hack that pops config.
3717
+ request_dict.pop("config", None)
3718
+
3719
+ http_options: Optional[types.HttpOptions] = None
3720
+ if (
3721
+ parameter_model.config is not None
3722
+ and parameter_model.config.http_options is not None
3723
+ ):
3724
+ http_options = parameter_model.config.http_options
3725
+
3726
+ request_dict = _common.convert_to_dict(request_dict)
3727
+ request_dict = _common.encode_unserializable_types(request_dict)
3728
+
3729
+ response = await self._api_client.async_request(
3730
+ "get", path, request_dict, http_options
3731
+ )
3732
+
3733
+ response_dict = {} if not response.body else json.loads(response.body)
3734
+
3735
+ return_value = types.RagFile._from_response(
3736
+ response=response_dict,
3737
+ kwargs=(
3738
+ {
3739
+ "config": {
3740
+ "response_schema": getattr(
3741
+ parameter_model.config, "response_schema", None
3742
+ ),
3743
+ "response_json_schema": getattr(
3744
+ parameter_model.config, "response_json_schema", None
3745
+ ),
3746
+ "include_all_fields": getattr(
3747
+ parameter_model.config, "include_all_fields", None
3748
+ ),
3749
+ }
3750
+ }
3751
+ if getattr(parameter_model, "config", None)
3752
+ else {}
3753
+ ),
3754
+ )
3755
+
3756
+ self._api_client._verify_response(return_value)
3757
+ return return_value
3758
+
3759
+ async def list_files(
3760
+ self, *, config: Optional[types.ListRagFilesConfigOrDict] = None, name: str
3761
+ ) -> types.ListRagFilesResponse:
3762
+ """
3763
+ Lists RagFile instances within a RagCorpus.
3764
+
3765
+ Args:
3766
+ name: The name of the RagCorpus to list files from.
3767
+ config: Optional configuration for the request (e.g., pagination details).
3768
+
3769
+ Returns:
3770
+ A ListRagFilesResponse containing the files.
3771
+
3772
+ """
3773
+
3774
+ parameter_model = types._ListRagFilesRequestParameters(
3775
+ config=config,
3776
+ name=name,
3777
+ )
3778
+
3779
+ request_url_dict: Optional[dict[str, str]]
3780
+ if not self._api_client.vertexai:
3781
+ raise ValueError(
3782
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3783
+ )
3784
+ else:
3785
+ request_dict = _ListRagFilesRequestParameters_to_vertex(parameter_model)
3786
+ request_url_dict = request_dict.get("_url")
3787
+ if request_url_dict:
3788
+ path = "{name}/ragFiles".format_map(request_url_dict)
3789
+ else:
3790
+ path = "{name}/ragFiles"
3791
+
3792
+ query_params = request_dict.get("_query")
3793
+ if query_params:
3794
+ path = f"{path}?{urlencode(query_params)}"
3795
+ # TODO: remove the hack that pops config.
3796
+ request_dict.pop("config", None)
3797
+
3798
+ http_options: Optional[types.HttpOptions] = None
3799
+ if (
3800
+ parameter_model.config is not None
3801
+ and parameter_model.config.http_options is not None
3802
+ ):
3803
+ http_options = parameter_model.config.http_options
3804
+
3805
+ request_dict = _common.convert_to_dict(request_dict)
3806
+ request_dict = _common.encode_unserializable_types(request_dict)
3807
+
3808
+ response = await self._api_client.async_request(
3809
+ "get", path, request_dict, http_options
3810
+ )
3811
+
3812
+ response_dict = {} if not response.body else json.loads(response.body)
3813
+
3814
+ return_value = types.ListRagFilesResponse._from_response(
3815
+ response=response_dict,
3816
+ kwargs=(
3817
+ {
3818
+ "config": {
3819
+ "response_schema": getattr(
3820
+ parameter_model.config, "response_schema", None
3821
+ ),
3822
+ "response_json_schema": getattr(
3823
+ parameter_model.config, "response_json_schema", None
3824
+ ),
3825
+ "include_all_fields": getattr(
3826
+ parameter_model.config, "include_all_fields", None
3827
+ ),
3828
+ }
3829
+ }
3830
+ if getattr(parameter_model, "config", None)
3831
+ else {}
3832
+ ),
3833
+ )
3834
+
3835
+ self._api_client._verify_response(return_value)
3836
+ return return_value
3837
+
3838
+ async def get_config(
3839
+ self, *, config: Optional[types.GetRagConfigOrDict] = None
3840
+ ) -> types.RagEngineConfig:
3841
+ """
3842
+ Gets the project-level RAG Engine Config.
3843
+
3844
+ Args:
3845
+ config: Optional configuration for the request.
3846
+
3847
+ Returns:
3848
+ The requested RagEngineConfig.
3849
+
3850
+ """
3851
+
3852
+ parameter_model = types._GetRagConfigRequestParameters(
3853
+ config=config,
3854
+ )
3855
+
3856
+ request_url_dict: Optional[dict[str, str]]
3857
+ if not self._api_client.vertexai:
3858
+ raise ValueError(
3859
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3860
+ )
3861
+ else:
3862
+ request_dict = _GetRagConfigRequestParameters_to_vertex(parameter_model)
3863
+ request_url_dict = request_dict.get("_url")
3864
+ if request_url_dict:
3865
+ path = "ragEngineConfig".format_map(request_url_dict)
3866
+ else:
3867
+ path = "ragEngineConfig"
3868
+
3869
+ query_params = request_dict.get("_query")
3870
+ if query_params:
3871
+ path = f"{path}?{urlencode(query_params)}"
3872
+ # TODO: remove the hack that pops config.
3873
+ request_dict.pop("config", None)
3874
+
3875
+ http_options: Optional[types.HttpOptions] = None
3876
+ if (
3877
+ parameter_model.config is not None
3878
+ and parameter_model.config.http_options is not None
3879
+ ):
3880
+ http_options = parameter_model.config.http_options
3881
+
3882
+ request_dict = _common.convert_to_dict(request_dict)
3883
+ request_dict = _common.encode_unserializable_types(request_dict)
3884
+
3885
+ response = await self._api_client.async_request(
3886
+ "get", path, request_dict, http_options
3887
+ )
3888
+
3889
+ response_dict = {} if not response.body else json.loads(response.body)
3890
+
3891
+ if self._api_client.vertexai:
3892
+ response_dict = _RagEngineConfig_from_vertex(response_dict)
3893
+
3894
+ return_value = types.RagEngineConfig._from_response(
3895
+ response=response_dict,
3896
+ kwargs=(
3897
+ {
3898
+ "config": {
3899
+ "response_schema": getattr(
3900
+ parameter_model.config, "response_schema", None
3901
+ ),
3902
+ "response_json_schema": getattr(
3903
+ parameter_model.config, "response_json_schema", None
3904
+ ),
3905
+ "include_all_fields": getattr(
3906
+ parameter_model.config, "include_all_fields", None
3907
+ ),
3908
+ }
3909
+ }
3910
+ if getattr(parameter_model, "config", None)
3911
+ else {}
3912
+ ),
3913
+ )
3914
+
3915
+ self._api_client._verify_response(return_value)
3916
+ return return_value
3917
+
3918
+ async def _update_corpus(
3919
+ self,
3920
+ *,
3921
+ config: Optional[types.UpdateRagCorpusConfigOrDict] = None,
3922
+ name: Optional[str] = None,
3923
+ rag_corpus: types.RagCorpusOrDict,
3924
+ ) -> types.UpdateRagCorpusOperation:
3925
+ """
3926
+ Updates an existing Rag Corpus.
3927
+ """
3928
+
3929
+ parameter_model = types._UpdateRagCorpusRequestParameters(
3930
+ config=config,
3931
+ name=name,
3932
+ rag_corpus=rag_corpus,
3933
+ )
3934
+
3935
+ request_url_dict: Optional[dict[str, str]]
3936
+ if not self._api_client.vertexai:
3937
+ raise ValueError(
3938
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
3939
+ )
3940
+ else:
3941
+ request_dict = _UpdateRagCorpusRequestParameters_to_vertex(parameter_model)
3942
+ request_url_dict = request_dict.get("_url")
3943
+ if request_url_dict:
3944
+ path = "{name}".format_map(request_url_dict)
3945
+ else:
3946
+ path = "{name}"
3947
+
3948
+ query_params = request_dict.get("_query")
3949
+ if query_params:
3950
+ path = f"{path}?{urlencode(query_params)}"
3951
+ # TODO: remove the hack that pops config.
3952
+ request_dict.pop("config", None)
3953
+
3954
+ http_options: Optional[types.HttpOptions] = None
3955
+ if (
3956
+ parameter_model.config is not None
3957
+ and parameter_model.config.http_options is not None
3958
+ ):
3959
+ http_options = parameter_model.config.http_options
3960
+
3961
+ request_dict = _common.convert_to_dict(request_dict)
3962
+ request_dict = _common.encode_unserializable_types(request_dict)
3963
+
3964
+ response = await self._api_client.async_request(
3965
+ "patch", path, request_dict, http_options
3966
+ )
3967
+
3968
+ response_dict = {} if not response.body else json.loads(response.body)
3969
+
3970
+ return_value = types.UpdateRagCorpusOperation._from_response(
3971
+ response=response_dict,
3972
+ kwargs=(
3973
+ {
3974
+ "config": {
3975
+ "response_schema": getattr(
3976
+ parameter_model.config, "response_schema", None
3977
+ ),
3978
+ "response_json_schema": getattr(
3979
+ parameter_model.config, "response_json_schema", None
3980
+ ),
3981
+ "include_all_fields": getattr(
3982
+ parameter_model.config, "include_all_fields", None
3983
+ ),
3984
+ }
3985
+ }
3986
+ if getattr(parameter_model, "config", None)
3987
+ else {}
3988
+ ),
3989
+ )
3990
+
3991
+ self._api_client._verify_response(return_value)
3992
+ return return_value
3993
+
3994
+ async def _delete_corpus(
3995
+ self,
3996
+ *,
3997
+ config: Optional[types.DeleteRagCorpusConfigOrDict] = None,
3998
+ name: Optional[str] = None,
3999
+ ) -> types.DeleteRagCorpusOperation:
4000
+ """
4001
+ Deletes a RAG Corpus.
4002
+ """
4003
+
4004
+ parameter_model = types._DeleteRagCorpusRequestParameters(
4005
+ config=config,
4006
+ name=name,
4007
+ )
4008
+
4009
+ request_url_dict: Optional[dict[str, str]]
4010
+ if not self._api_client.vertexai:
4011
+ raise ValueError(
4012
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4013
+ )
4014
+ else:
4015
+ request_dict = _DeleteRagCorpusRequestParameters_to_vertex(parameter_model)
4016
+ request_url_dict = request_dict.get("_url")
4017
+ if request_url_dict:
4018
+ path = "{name}".format_map(request_url_dict)
4019
+ else:
4020
+ path = "{name}"
4021
+
4022
+ query_params = request_dict.get("_query")
4023
+ if query_params:
4024
+ path = f"{path}?{urlencode(query_params)}"
4025
+ # TODO: remove the hack that pops config.
4026
+ request_dict.pop("config", None)
4027
+
4028
+ http_options: Optional[types.HttpOptions] = None
4029
+ if (
4030
+ parameter_model.config is not None
4031
+ and parameter_model.config.http_options is not None
4032
+ ):
4033
+ http_options = parameter_model.config.http_options
4034
+
4035
+ request_dict = _common.convert_to_dict(request_dict)
4036
+ request_dict = _common.encode_unserializable_types(request_dict)
4037
+
4038
+ response = await self._api_client.async_request(
4039
+ "delete", path, request_dict, http_options
4040
+ )
4041
+
4042
+ response_dict = {} if not response.body else json.loads(response.body)
4043
+
4044
+ return_value = types.DeleteRagCorpusOperation._from_response(
4045
+ response=response_dict,
4046
+ kwargs=(
4047
+ {
4048
+ "config": {
4049
+ "response_schema": getattr(
4050
+ parameter_model.config, "response_schema", None
4051
+ ),
4052
+ "response_json_schema": getattr(
4053
+ parameter_model.config, "response_json_schema", None
4054
+ ),
4055
+ "include_all_fields": getattr(
4056
+ parameter_model.config, "include_all_fields", None
4057
+ ),
4058
+ }
4059
+ }
4060
+ if getattr(parameter_model, "config", None)
4061
+ else {}
4062
+ ),
4063
+ )
4064
+
4065
+ self._api_client._verify_response(return_value)
4066
+ return return_value
4067
+
4068
+ async def _delete_file(
4069
+ self, *, config: Optional[types.DeleteRagFileConfigOrDict] = None, name: str
4070
+ ) -> types.DeleteRagFileOperation:
4071
+ """
4072
+ Deletes a RAG File.
4073
+ """
4074
+
4075
+ parameter_model = types._DeleteRagFileRequestParameters(
4076
+ config=config,
4077
+ name=name,
4078
+ )
4079
+
4080
+ request_url_dict: Optional[dict[str, str]]
4081
+ if not self._api_client.vertexai:
4082
+ raise ValueError(
4083
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4084
+ )
4085
+ else:
4086
+ request_dict = _DeleteRagFileRequestParameters_to_vertex(parameter_model)
4087
+ request_url_dict = request_dict.get("_url")
4088
+ if request_url_dict:
4089
+ path = "{name}".format_map(request_url_dict)
4090
+ else:
4091
+ path = "{name}"
4092
+
4093
+ query_params = request_dict.get("_query")
4094
+ if query_params:
4095
+ path = f"{path}?{urlencode(query_params)}"
4096
+ # TODO: remove the hack that pops config.
4097
+ request_dict.pop("config", None)
4098
+
4099
+ http_options: Optional[types.HttpOptions] = None
4100
+ if (
4101
+ parameter_model.config is not None
4102
+ and parameter_model.config.http_options is not None
4103
+ ):
4104
+ http_options = parameter_model.config.http_options
4105
+
4106
+ request_dict = _common.convert_to_dict(request_dict)
4107
+ request_dict = _common.encode_unserializable_types(request_dict)
4108
+
4109
+ response = await self._api_client.async_request(
4110
+ "delete", path, request_dict, http_options
4111
+ )
4112
+
4113
+ response_dict = {} if not response.body else json.loads(response.body)
4114
+
4115
+ return_value = types.DeleteRagFileOperation._from_response(
4116
+ response=response_dict,
4117
+ kwargs=(
4118
+ {
4119
+ "config": {
4120
+ "response_schema": getattr(
4121
+ parameter_model.config, "response_schema", None
4122
+ ),
4123
+ "response_json_schema": getattr(
4124
+ parameter_model.config, "response_json_schema", None
4125
+ ),
4126
+ "include_all_fields": getattr(
4127
+ parameter_model.config, "include_all_fields", None
4128
+ ),
4129
+ }
4130
+ }
4131
+ if getattr(parameter_model, "config", None)
4132
+ else {}
4133
+ ),
4134
+ )
4135
+
4136
+ self._api_client._verify_response(return_value)
4137
+ return return_value
4138
+
4139
+ async def _update_config(
4140
+ self,
4141
+ *,
4142
+ updated_config: types.RagEngineConfigOrDict,
4143
+ config: Optional[types.UpdateRagConfigOrDict] = None,
4144
+ ) -> types.UpdateRagConfigOperation:
4145
+ """
4146
+ Updates a RAG Engine Config.
4147
+ """
4148
+
4149
+ parameter_model = types._UpdateRagConfigRequestParameters(
4150
+ updated_config=updated_config,
4151
+ config=config,
4152
+ )
4153
+
4154
+ request_url_dict: Optional[dict[str, str]]
4155
+ if not self._api_client.vertexai:
4156
+ raise ValueError(
4157
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4158
+ )
4159
+ else:
4160
+ request_dict = _UpdateRagConfigRequestParameters_to_vertex(parameter_model)
4161
+ request_url_dict = request_dict.get("_url")
4162
+ if request_url_dict:
4163
+ path = "ragEngineConfig".format_map(request_url_dict)
4164
+ else:
4165
+ path = "ragEngineConfig"
4166
+
4167
+ query_params = request_dict.get("_query")
4168
+ if query_params:
4169
+ path = f"{path}?{urlencode(query_params)}"
4170
+ # TODO: remove the hack that pops config.
4171
+ request_dict.pop("config", None)
4172
+
4173
+ http_options: Optional[types.HttpOptions] = None
4174
+ if (
4175
+ parameter_model.config is not None
4176
+ and parameter_model.config.http_options is not None
4177
+ ):
4178
+ http_options = parameter_model.config.http_options
4179
+
4180
+ request_dict = _common.convert_to_dict(request_dict)
4181
+ request_dict = _common.encode_unserializable_types(request_dict)
4182
+
4183
+ response = await self._api_client.async_request(
4184
+ "patch", path, request_dict, http_options
4185
+ )
4186
+
4187
+ response_dict = {} if not response.body else json.loads(response.body)
4188
+
4189
+ return_value = types.UpdateRagConfigOperation._from_response(
4190
+ response=response_dict,
4191
+ kwargs=(
4192
+ {
4193
+ "config": {
4194
+ "response_schema": getattr(
4195
+ parameter_model.config, "response_schema", None
4196
+ ),
4197
+ "response_json_schema": getattr(
4198
+ parameter_model.config, "response_json_schema", None
4199
+ ),
4200
+ "include_all_fields": getattr(
4201
+ parameter_model.config, "include_all_fields", None
4202
+ ),
4203
+ }
4204
+ }
4205
+ if getattr(parameter_model, "config", None)
4206
+ else {}
4207
+ ),
4208
+ )
4209
+
4210
+ self._api_client._verify_response(return_value)
4211
+ return return_value
4212
+
4213
+ async def retrieve_contexts(
4214
+ self,
4215
+ *,
4216
+ vertex_rag_store: genai_types.VertexRagStoreOrDict,
4217
+ query: types.RagQueryOrDict,
4218
+ config: Optional[types.RetrieveContextsConfigOrDict] = None,
4219
+ ) -> types.RetrieveContextsResponse:
4220
+ """
4221
+ Retrieves contexts from a Vertex RAG store based on a query.
4222
+
4223
+ Args:
4224
+ vertex_rag_store: The Vertex RAG store to retrieve contexts from.
4225
+ query: The query to retrieve contexts for.
4226
+ config: Optional configuration for the request.
4227
+
4228
+ Returns:
4229
+ The RetrieveContextsResponse containing the relevant contexts.
4230
+
4231
+ """
4232
+
4233
+ parameter_model = types._RetrieveRagContextsRequestParameters(
4234
+ vertex_rag_store=vertex_rag_store,
4235
+ query=query,
4236
+ config=config,
4237
+ )
4238
+
4239
+ request_url_dict: Optional[dict[str, str]]
4240
+ if not self._api_client.vertexai:
4241
+ raise ValueError(
4242
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4243
+ )
4244
+ else:
4245
+ request_dict = _RetrieveRagContextsRequestParameters_to_vertex(
4246
+ parameter_model
4247
+ )
4248
+ request_url_dict = request_dict.get("_url")
4249
+ if request_url_dict:
4250
+ path = ":retrieveContexts".format_map(request_url_dict)
4251
+ else:
4252
+ path = ":retrieveContexts"
4253
+
4254
+ query_params = request_dict.get("_query")
4255
+ if query_params:
4256
+ path = f"{path}?{urlencode(query_params)}"
4257
+ # TODO: remove the hack that pops config.
4258
+ request_dict.pop("config", None)
4259
+
4260
+ http_options: Optional[types.HttpOptions] = None
4261
+ if (
4262
+ parameter_model.config is not None
4263
+ and parameter_model.config.http_options is not None
4264
+ ):
4265
+ http_options = parameter_model.config.http_options
4266
+
4267
+ request_dict = _common.convert_to_dict(request_dict)
4268
+ request_dict = _common.encode_unserializable_types(request_dict)
4269
+
4270
+ response = await self._api_client.async_request(
4271
+ "post", path, request_dict, http_options
4272
+ )
4273
+
4274
+ response_dict = {} if not response.body else json.loads(response.body)
4275
+
4276
+ return_value = types.RetrieveContextsResponse._from_response(
4277
+ response=response_dict,
4278
+ kwargs=(
4279
+ {
4280
+ "config": {
4281
+ "response_schema": getattr(
4282
+ parameter_model.config, "response_schema", None
4283
+ ),
4284
+ "response_json_schema": getattr(
4285
+ parameter_model.config, "response_json_schema", None
4286
+ ),
4287
+ "include_all_fields": getattr(
4288
+ parameter_model.config, "include_all_fields", None
4289
+ ),
4290
+ }
4291
+ }
4292
+ if getattr(parameter_model, "config", None)
4293
+ else {}
4294
+ ),
4295
+ )
4296
+
4297
+ self._api_client._verify_response(return_value)
4298
+ return return_value
4299
+
4300
+ async def _get_rag_config_operation(
4301
+ self,
4302
+ *,
4303
+ operation_name: str,
4304
+ config: Optional[types.GetRagConfigOperationConfigOrDict] = None,
4305
+ ) -> types.RagEngineConfigOperation:
4306
+ parameter_model = types._GetRagConfigOperationParameters(
4307
+ operation_name=operation_name,
4308
+ config=config,
4309
+ )
4310
+
4311
+ request_url_dict: Optional[dict[str, str]]
4312
+ if not self._api_client.vertexai:
4313
+ raise ValueError(
4314
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4315
+ )
4316
+ else:
4317
+ request_dict = _GetRagConfigOperationParameters_to_vertex(parameter_model)
4318
+ request_url_dict = request_dict.get("_url")
4319
+ if request_url_dict:
4320
+ path = "{operation_name}".format_map(request_url_dict)
4321
+ else:
4322
+ path = "{operation_name}"
4323
+
4324
+ query_params = request_dict.get("_query")
4325
+ if query_params:
4326
+ path = f"{path}?{urlencode(query_params)}"
4327
+ # TODO: remove the hack that pops config.
4328
+ request_dict.pop("config", None)
4329
+
4330
+ http_options: Optional[types.HttpOptions] = None
4331
+ if (
4332
+ parameter_model.config is not None
4333
+ and parameter_model.config.http_options is not None
4334
+ ):
4335
+ http_options = parameter_model.config.http_options
4336
+
4337
+ request_dict = _common.convert_to_dict(request_dict)
4338
+ request_dict = _common.encode_unserializable_types(request_dict)
4339
+
4340
+ response = await self._api_client.async_request(
4341
+ "get", path, request_dict, http_options
4342
+ )
4343
+
4344
+ response_dict = {} if not response.body else json.loads(response.body)
4345
+
4346
+ return_value = types.RagEngineConfigOperation._from_response(
4347
+ response=response_dict,
4348
+ kwargs=(
4349
+ {
4350
+ "config": {
4351
+ "response_schema": getattr(
4352
+ parameter_model.config, "response_schema", None
4353
+ ),
4354
+ "response_json_schema": getattr(
4355
+ parameter_model.config, "response_json_schema", None
4356
+ ),
4357
+ "include_all_fields": getattr(
4358
+ parameter_model.config, "include_all_fields", None
4359
+ ),
4360
+ }
4361
+ }
4362
+ if getattr(parameter_model, "config", None)
4363
+ else {}
4364
+ ),
4365
+ )
4366
+
4367
+ self._api_client._verify_response(return_value)
4368
+ return return_value
4369
+
4370
+ async def _import_files(
4371
+ self,
4372
+ *,
4373
+ name: str,
4374
+ import_rag_files_request: types.ImportRagFilesRequestOrDict,
4375
+ config: Optional[types.ImportRagFilesRequestConfigOrDict] = None,
4376
+ ) -> types.ImportRagFilesOperation:
4377
+ """
4378
+ Imports files into a RAG Corpus.
4379
+ """
4380
+
4381
+ parameter_model = types._ImportRagFilesRequestParameters(
4382
+ name=name,
4383
+ import_rag_files_request=import_rag_files_request,
4384
+ config=config,
4385
+ )
4386
+
4387
+ request_url_dict: Optional[dict[str, str]]
4388
+ if not self._api_client.vertexai:
4389
+ raise ValueError(
4390
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4391
+ )
4392
+ else:
4393
+ request_dict = _ImportRagFilesRequestParameters_to_vertex(parameter_model)
4394
+ request_url_dict = request_dict.get("_url")
4395
+ if request_url_dict:
4396
+ path = "{name}/ragFiles:import".format_map(request_url_dict)
4397
+ else:
4398
+ path = "{name}/ragFiles:import"
4399
+
4400
+ query_params = request_dict.get("_query")
4401
+ if query_params:
4402
+ path = f"{path}?{urlencode(query_params)}"
4403
+ # TODO: remove the hack that pops config.
4404
+ request_dict.pop("config", None)
4405
+
4406
+ http_options: Optional[types.HttpOptions] = None
4407
+ if (
4408
+ parameter_model.config is not None
4409
+ and parameter_model.config.http_options is not None
4410
+ ):
4411
+ http_options = parameter_model.config.http_options
4412
+
4413
+ request_dict = _common.convert_to_dict(request_dict)
4414
+ request_dict = _common.encode_unserializable_types(request_dict)
4415
+
4416
+ response = await self._api_client.async_request(
4417
+ "post", path, request_dict, http_options
4418
+ )
4419
+
4420
+ response_dict = {} if not response.body else json.loads(response.body)
4421
+
4422
+ return_value = types.ImportRagFilesOperation._from_response(
4423
+ response=response_dict,
4424
+ kwargs=(
4425
+ {
4426
+ "config": {
4427
+ "response_schema": getattr(
4428
+ parameter_model.config, "response_schema", None
4429
+ ),
4430
+ "response_json_schema": getattr(
4431
+ parameter_model.config, "response_json_schema", None
4432
+ ),
4433
+ "include_all_fields": getattr(
4434
+ parameter_model.config, "include_all_fields", None
4435
+ ),
4436
+ }
4437
+ }
4438
+ if getattr(parameter_model, "config", None)
4439
+ else {}
4440
+ ),
4441
+ )
4442
+
4443
+ self._api_client._verify_response(return_value)
4444
+ return return_value
4445
+
4446
+ async def _get_import_files_operation(
4447
+ self,
4448
+ *,
4449
+ operation_name: str,
4450
+ config: Optional[types.GetImportFilesOperationConfigOrDict] = None,
4451
+ ) -> types.ImportRagFilesOperation:
4452
+ parameter_model = types._GetImportFilesOperationParameters(
4453
+ operation_name=operation_name,
4454
+ config=config,
4455
+ )
4456
+
4457
+ request_url_dict: Optional[dict[str, str]]
4458
+ if not self._api_client.vertexai:
4459
+ raise ValueError(
4460
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4461
+ )
4462
+ else:
4463
+ request_dict = _GetImportFilesOperationParameters_to_vertex(parameter_model)
4464
+ request_url_dict = request_dict.get("_url")
4465
+ if request_url_dict:
4466
+ path = "{operation_name}".format_map(request_url_dict)
4467
+ else:
4468
+ path = "{operation_name}"
4469
+
4470
+ query_params = request_dict.get("_query")
4471
+ if query_params:
4472
+ path = f"{path}?{urlencode(query_params)}"
4473
+ # TODO: remove the hack that pops config.
4474
+ request_dict.pop("config", None)
4475
+
4476
+ http_options: Optional[types.HttpOptions] = None
4477
+ if (
4478
+ parameter_model.config is not None
4479
+ and parameter_model.config.http_options is not None
4480
+ ):
4481
+ http_options = parameter_model.config.http_options
4482
+
4483
+ request_dict = _common.convert_to_dict(request_dict)
4484
+ request_dict = _common.encode_unserializable_types(request_dict)
4485
+
4486
+ response = await self._api_client.async_request(
4487
+ "get", path, request_dict, http_options
4488
+ )
4489
+
4490
+ response_dict = {} if not response.body else json.loads(response.body)
4491
+
4492
+ return_value = types.ImportRagFilesOperation._from_response(
4493
+ response=response_dict,
4494
+ kwargs=(
4495
+ {
4496
+ "config": {
4497
+ "response_schema": getattr(
4498
+ parameter_model.config, "response_schema", None
4499
+ ),
4500
+ "response_json_schema": getattr(
4501
+ parameter_model.config, "response_json_schema", None
4502
+ ),
4503
+ "include_all_fields": getattr(
4504
+ parameter_model.config, "include_all_fields", None
4505
+ ),
4506
+ }
4507
+ }
4508
+ if getattr(parameter_model, "config", None)
4509
+ else {}
4510
+ ),
4511
+ )
4512
+
4513
+ self._api_client._verify_response(return_value)
4514
+ return return_value
4515
+
4516
+ async def _upload_file(
4517
+ self,
4518
+ *,
4519
+ name: str,
4520
+ rag_file: types.RagFileOrDict,
4521
+ upload_rag_file_config: Optional[types.UploadRagFileConfigOrDict] = None,
4522
+ config: Optional[types.UploadRagFileRequestConfigOrDict] = None,
4523
+ ) -> types.UploadRagFileResponse:
4524
+ parameter_model = types._UploadRagFileParameters(
4525
+ name=name,
4526
+ rag_file=rag_file,
4527
+ upload_rag_file_config=upload_rag_file_config,
4528
+ config=config,
4529
+ )
4530
+
4531
+ request_url_dict: Optional[dict[str, str]]
4532
+ if not self._api_client.vertexai:
4533
+ raise ValueError(
4534
+ "This method is only supported in Gemini Enterprise Agent Platform mode, not in Gemini Developer API mode."
4535
+ )
4536
+ else:
4537
+ request_dict = _UploadRagFileParameters_to_vertex(parameter_model)
4538
+ request_url_dict = request_dict.get("_url")
4539
+ if request_url_dict:
4540
+ path = "{name}/ragFiles:upload".format_map(request_url_dict)
4541
+ else:
4542
+ path = "{name}/ragFiles:upload"
4543
+
4544
+ query_params = request_dict.get("_query")
4545
+ if query_params:
4546
+ path = f"{path}?{urlencode(query_params)}"
4547
+ # TODO: remove the hack that pops config.
4548
+ request_dict.pop("config", None)
4549
+
4550
+ http_options: Optional[types.HttpOptions] = None
4551
+ if (
4552
+ parameter_model.config is not None
4553
+ and parameter_model.config.http_options is not None
4554
+ ):
4555
+ http_options = parameter_model.config.http_options
4556
+
4557
+ request_dict = _common.convert_to_dict(request_dict)
4558
+ request_dict = _common.encode_unserializable_types(request_dict)
4559
+
4560
+ response = await self._api_client.async_request(
4561
+ "post", path, request_dict, http_options
4562
+ )
4563
+
4564
+ response_dict = {} if not response.body else json.loads(response.body)
4565
+
4566
+ return_value = types.UploadRagFileResponse._from_response(
4567
+ response=response_dict,
4568
+ kwargs=(
4569
+ {
4570
+ "config": {
4571
+ "response_schema": getattr(
4572
+ parameter_model.config, "response_schema", None
4573
+ ),
4574
+ "response_json_schema": getattr(
4575
+ parameter_model.config, "response_json_schema", None
4576
+ ),
4577
+ "include_all_fields": getattr(
4578
+ parameter_model.config, "include_all_fields", None
4579
+ ),
4580
+ }
4581
+ }
4582
+ if getattr(parameter_model, "config", None)
4583
+ else {}
4584
+ ),
4585
+ )
4586
+
4587
+ self._api_client._verify_response(return_value)
4588
+ return return_value
4589
+
4590
+ async def create_corpus(
4591
+ self,
4592
+ *,
4593
+ rag_corpus: types.RagCorpusOrDict,
4594
+ config: Optional[types.CreateRagCorpusConfigOrDict] = None,
4595
+ ) -> types.RagCorpus:
4596
+ """
4597
+ Creates a new RAG Corpus and waits for completion asynchronously.
4598
+
4599
+ Args:
4600
+ rag_corpus: The RagCorpus to create.
4601
+ config: The configuration to use for the RagCorpus.
4602
+
4603
+ Returns:
4604
+ The created RagCorpus.
4605
+
4606
+ Example usage:
4607
+
4608
+ ```
4609
+ corpus = await client.aio.rag.create_corpus(
4610
+ rag_corpus=types.RagCorpus(
4611
+ display_name="test-corpus",
4612
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4613
+ ),
4614
+ )
4615
+ ```
4616
+ """
4617
+ operation = await self._create_corpus(rag_corpus=rag_corpus, config=config)
4618
+
4619
+ operation = await _operations_utils.await_operation_async(
4620
+ operation_name=operation.name,
4621
+ get_operation_fn=self._get_corpus_operation,
4622
+ )
4623
+
4624
+ if operation.error:
4625
+ raise RuntimeError(
4626
+ f"Operation {operation.name} failed to create RagCorpus: {operation.error}"
4627
+ )
4628
+
4629
+ return await self.get_corpus(name=operation.response.name)
4630
+
4631
+ async def delete_corpus(
4632
+ self,
4633
+ *,
4634
+ name: str,
4635
+ config: Optional[types.DeleteRagCorpusConfigOrDict] = None,
4636
+ ) -> None:
4637
+ """
4638
+ Deletes a RAG Corpus and waits for the delete operation to complete asynchronously.
4639
+
4640
+ Args:
4641
+ name: The name of the RagCorpus to delete, formatted as
4642
+ `projects/{project}/locations/{location}/ragCorpora/{corpus_id}`.
4643
+ config: The configuration to use for the RagCorpus delete request.
4644
+
4645
+ Example usage:
4646
+
4647
+ ```
4648
+ await client.aio.rag.delete_corpus(
4649
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4650
+ )
4651
+ ```
4652
+ """
4653
+ operation = await self._delete_corpus(name=name, config=config)
4654
+
4655
+ operation = await _operations_utils.await_operation_async(
4656
+ operation_name=operation.name,
4657
+ get_operation_fn=self._get_corpus_operation,
4658
+ )
4659
+
4660
+ if operation.error:
4661
+ raise RuntimeError(
4662
+ f"Operation {operation.name} failed to delete RagCorpus: {operation.error}"
4663
+ )
4664
+
4665
+ return None
4666
+
4667
+ async def delete_file(
4668
+ self,
4669
+ *,
4670
+ name: str,
4671
+ config: Optional[types.DeleteRagFileConfigOrDict] = None,
4672
+ ) -> None:
4673
+ """
4674
+ Deletes a file from a RAG Corpus and waits for the delete operation to complete.
4675
+
4676
+ Args:
4677
+ name: The name of the RagFile to delete, formatted as
4678
+ `projects/{project}/locations/{location}/ragCorpora/{corpus_id}/ragFiles/{file_id}`.
4679
+ config: The configuration to use for the RagFile delete request.
4680
+
4681
+ Example usage:
4682
+
4683
+ ```
4684
+ await client.aio.rag.delete_file(
4685
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragFiles/987654321",
4686
+ )
4687
+ ```
4688
+ """
4689
+ operation = await self._delete_file(name=name, config=config)
4690
+
4691
+ operation = await _operations_utils.await_operation_async(
4692
+ operation_name=operation.name,
4693
+ get_operation_fn=self._get_corpus_operation,
4694
+ )
4695
+
4696
+ if operation.error:
4697
+ raise RuntimeError(
4698
+ f"Operation {operation.name} failed to delete file from RagCorpus: {operation.error}"
4699
+ )
4700
+
4701
+ return None
4702
+
4703
+ async def update_corpus(
4704
+ self,
4705
+ *,
4706
+ name: str,
4707
+ rag_corpus: types.RagCorpusOrDict,
4708
+ config: Optional[types.UpdateRagCorpusConfigOrDict] = None,
4709
+ ) -> types.RagCorpus:
4710
+ """
4711
+ Updates a RAG Corpus and waits for completion asynchronously.
4712
+
4713
+ Args:
4714
+ name: The name of the RagCorpus to update, formatted as
4715
+ `projects/{project}/locations/{location}/ragCorpora/{corpus_id}`.
4716
+ rag_corpus: The RagCorpus to update.
4717
+ config: The configuration to use for the RagCorpus update request.
4718
+
4719
+ Returns:
4720
+ The updated RagCorpus.
4721
+
4722
+ Example usage:
4723
+
4724
+ ```
4725
+ await client.aio.rag.update_corpus(
4726
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4727
+ rag_corpus=types.RagCorpus(
4728
+ display_name="Updated corpus name",
4729
+ ),
4730
+ )
4731
+ ```
4732
+ """
4733
+ operation = await self._update_corpus(
4734
+ name=name, rag_corpus=rag_corpus, config=config
4735
+ )
4736
+
4737
+ operation = await _operations_utils.await_operation_async(
4738
+ operation_name=operation.name,
4739
+ get_operation_fn=self._get_corpus_operation,
4740
+ )
4741
+
4742
+ if operation.error:
4743
+ raise RuntimeError(
4744
+ f"Operation {operation.name} failed to update RagCorpus: {operation.error}"
4745
+ )
4746
+
4747
+ return await self.get_corpus(name=operation.response.name)
4748
+
4749
+ async def update_config(
4750
+ self,
4751
+ *,
4752
+ updated_config: types.RagEngineConfigOrDict,
4753
+ request_config: Optional[types.UpdateRagConfigOrDict] = None,
4754
+ ) -> types.RagEngineConfig:
4755
+ """
4756
+ Updates a RagEngineConfig and waits for completion asynchronously.
4757
+
4758
+ Args:
4759
+ updated_config: The RagEngineConfig to update.
4760
+ request_config: The configuration to use for the RagEngineConfig update request.
4761
+
4762
+ Returns:
4763
+ The updated RagEngineConfig.
4764
+
4765
+ Example usage:
4766
+
4767
+ ```
4768
+ await client.aio.rag.update_config(
4769
+ updated_config=types.RagEngineConfig(
4770
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789/ragEngineConfig/123456789",
4771
+ rag_managed_db_config=types.RagManagedDbConfig(
4772
+ basic=types.RagManagedDbConfigBasic()
4773
+ )
4774
+ ),
4775
+ )
4776
+ ```
4777
+ """
4778
+ operation = await self._update_config(
4779
+ updated_config=updated_config, config=request_config
4780
+ )
4781
+
4782
+ operation = await _operations_utils.await_operation_async(
4783
+ operation_name=operation.name,
4784
+ get_operation_fn=self._get_rag_config_operation,
4785
+ )
4786
+
4787
+ if operation.error:
4788
+ raise RuntimeError(
4789
+ f"Operation {operation.name} failed to update RagEngineConfig: {operation.error}"
4790
+ )
4791
+
4792
+ return await self.get_config()
4793
+
4794
+ async def import_files(
4795
+ self,
4796
+ *,
4797
+ name: str,
4798
+ import_config: types.ImportRagFilesConfigOrDict,
4799
+ config: Optional[types.ImportRagFilesRequestConfigOrDict] = None,
4800
+ ) -> types.ImportRagFilesResponse:
4801
+ """
4802
+ Imports files into a Rag Corpus. To get a list of all files on the corpus after calling import_files, call list_files.
4803
+
4804
+ Example usage:
4805
+
4806
+ ```
4807
+ import_files_response = await client.aio.rag.import_files(
4808
+ name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4809
+ import_config=types.ImportRagFilesConfig(
4810
+ gcs_source=types.GcsSource(uris=["gs://test-bucket/test-file.pdf"]),
4811
+ ),
4812
+ )
4813
+ ```
4814
+
4815
+ Args:
4816
+ name: The name of the Rag Corpus to import files into, format:
4817
+ `projects/{project}/locations/{location}/ragCorpora/{rag_corpus_id}`
4818
+ import_config: The configuration for importing files, including source files and processing options.
4819
+ config: The configuration to use for the import request.
4820
+
4821
+ Returns:
4822
+ The ImportRagFilesResponse from the import files operation.
4823
+ """
4824
+
4825
+ if isinstance(import_config, dict):
4826
+ import_config = types.ImportRagFilesConfig.model_validate(import_config)
4827
+
4828
+ if import_config.gcs_source is not None:
4829
+ for uri in import_config.gcs_source.uris:
4830
+ if not _gcs_utils.GcsUtils(self._api_client)._verify_bucket_ownership(
4831
+ bucket_name=uri.split("/")[2],
4832
+ expected_project=self._api_client.project,
4833
+ ):
4834
+ raise ValueError(
4835
+ f"Bucket {uri} does not belong to"
4836
+ f" project {self._api_client.project}."
4837
+ )
4838
+
4839
+ operation = await self._import_files(
4840
+ name=name,
4841
+ import_rag_files_request=types.ImportRagFilesRequest(
4842
+ import_rag_files_config=import_config
4843
+ ),
4844
+ config=config,
4845
+ )
4846
+
4847
+ operation = await _operations_utils.await_operation_async(
4848
+ operation_name=operation.name,
4849
+ get_operation_fn=self._get_import_files_operation,
4850
+ )
4851
+
4852
+ if operation.error:
4853
+ raise RuntimeError(
4854
+ f"Operation {operation.name} failed to import files into RagCorpus: {operation.error}"
4855
+ )
4856
+
4857
+ return operation.response
4858
+
4859
+ async def upload_file(
4860
+ self,
4861
+ *,
4862
+ corpus_name: str,
4863
+ path: str,
4864
+ display_name: Optional[str] = None,
4865
+ upload_rag_file_config: Optional[types.UploadRagFileConfigOrDict] = None,
4866
+ request_config: Optional[types.UploadRagFileRequestConfigOrDict] = None,
4867
+ ) -> types.RagFile:
4868
+ """
4869
+ Uploads a file to a RAG Corpus.
4870
+
4871
+ Args:
4872
+ corpus_name: The name of the RAG Corpus to upload to.
4873
+ path: The path to the file to upload.
4874
+ display_name: Optional. The display name for the uploaded file. If not provided, a display name will be generated.
4875
+ upload_rag_file_config: Optional. The configuration to use for the upload.
4876
+ request_config: Optional. The configuration to use for the request.
4877
+
4878
+ Returns:
4879
+ The uploaded RagFile.
4880
+
4881
+ Example usage:
4882
+
4883
+ ```
4884
+ rag_file = await client.aio.rag.upload_file(
4885
+ corpus_name="projects/test-project/locations/us-central1/ragCorpora/123456789",
4886
+ path="/path/to/file.pdf",
4887
+ display_name="test-file",
4888
+ upload_rag_file_config=types.UploadRagFileConfig(
4889
+ chunk_config=types.ChunkConfig(
4890
+ chunk_size=1024,
4891
+ chunk_overlap=128,
4892
+ ),
4893
+ ),
4894
+ )
4895
+ ```
4896
+ """
4897
+
4898
+ if not display_name:
4899
+ display_name = f"file_{_common.timestamped_unique_name()}"
4900
+
4901
+ rag_file = types.RagFile(display_name=display_name)
4902
+
4903
+ mime_type, _ = mimetypes.guess_type(path)
4904
+
4905
+ if mime_type is None:
4906
+ mime_type = "application/octet-stream"
4907
+
4908
+ http_options, size_bytes, mime_type = _extra_utils.prepare_resumable_upload(
4909
+ path,
4910
+ user_http_options=request_config.http_options if request_config else None,
4911
+ user_mime_type=mime_type,
4912
+ )
4913
+
4914
+ current_api_version = self._api_client._http_options.api_version or "v1beta1"
4915
+ upload_api_version = f"upload/{current_api_version}"
4916
+
4917
+ http_options.api_version = upload_api_version
4918
+
4919
+ parameter_model = types._UploadRagFileParameters(
4920
+ name=corpus_name,
4921
+ rag_file=rag_file,
4922
+ upload_rag_file_config=upload_rag_file_config,
4923
+ )
4924
+ request_dict = _UploadRagFileParameters_to_vertex(parameter_model)
4925
+
4926
+ request_dict.pop("_url", None)
4927
+ request_dict.pop("_query", None)
4928
+
4929
+ request_path = f"{corpus_name}/ragFiles:upload"
4930
+
4931
+ request_dict = _common.convert_to_dict(request_dict)
4932
+ request_dict = _common.encode_unserializable_types(request_dict)
4933
+
4934
+ response = await self._api_client.async_request(
4935
+ "post",
4936
+ request_path,
4937
+ request_dict,
4938
+ http_options,
4939
+ )
4940
+
4941
+ if response.headers is None or (
4942
+ "x-goog-upload-url" not in response.headers
4943
+ and "X-Goog-Upload-URL" not in response.headers
4944
+ ):
4945
+ raise KeyError(
4946
+ "Failed to create file. Upload URL was not returned from the create file request."
4947
+ )
4948
+
4949
+ upload_url = response.headers.get(
4950
+ "x-goog-upload-url", response.headers.get("X-Goog-Upload-URL")
4951
+ )
4952
+
4953
+ fs_path = os.fspath(path)
4954
+ return_file = await self._api_client.async_upload_file(
4955
+ fs_path, upload_url, size_bytes, http_options=http_options
4956
+ )
4957
+
4958
+ rag_file_payload = return_file.json.get("ragFile") or return_file.json.get(
4959
+ "rag_file", {}
4960
+ )
4961
+ return types.RagFile(**rag_file_payload)