@@ -85,6 +85,57 @@ def create_rag_corpus_mock_pinecone():
85
85
yield create_rag_corpus_mock_pinecone
86
86
87
87
88
+ @pytest .fixture
89
+ def create_rag_corpus_mock_vertex_ai_engine_search_config ():
90
+ with mock .patch .object (
91
+ VertexRagDataServiceClient ,
92
+ "create_rag_corpus" ,
93
+ ) as create_rag_corpus_mock_vertex_ai_engine_search_config :
94
+ create_rag_corpus_lro_mock = mock .Mock (ga_operation .Operation )
95
+ create_rag_corpus_lro_mock .done .return_value = True
96
+ create_rag_corpus_lro_mock .result .return_value = (
97
+ test_rag_constants .TEST_GAPIC_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG
98
+ )
99
+ create_rag_corpus_mock_vertex_ai_engine_search_config .return_value = (
100
+ create_rag_corpus_lro_mock
101
+ )
102
+ yield create_rag_corpus_mock_vertex_ai_engine_search_config
103
+
104
+
105
+ @pytest .fixture
106
+ def create_rag_corpus_mock_vertex_ai_datastore_search_config ():
107
+ with mock .patch .object (
108
+ VertexRagDataServiceClient ,
109
+ "create_rag_corpus" ,
110
+ ) as create_rag_corpus_mock_vertex_ai_datastore_search_config :
111
+ create_rag_corpus_lro_mock = mock .Mock (ga_operation .Operation )
112
+ create_rag_corpus_lro_mock .done .return_value = True
113
+ create_rag_corpus_lro_mock .result .return_value = (
114
+ test_rag_constants .TEST_GAPIC_RAG_CORPUS_VERTEX_AI_DATASTORE_SEARCH_CONFIG
115
+ )
116
+ create_rag_corpus_mock_vertex_ai_datastore_search_config .return_value = (
117
+ create_rag_corpus_lro_mock
118
+ )
119
+ yield create_rag_corpus_mock_vertex_ai_datastore_search_config
120
+
121
+
122
+ @pytest .fixture
123
+ def update_rag_corpus_mock_vertex_ai_engine_search_config ():
124
+ with mock .patch .object (
125
+ VertexRagDataServiceClient ,
126
+ "update_rag_corpus" ,
127
+ ) as update_rag_corpus_mock_vertex_ai_engine_search_config :
128
+ update_rag_corpus_lro_mock = mock .Mock (ga_operation .Operation )
129
+ update_rag_corpus_lro_mock .done .return_value = True
130
+ update_rag_corpus_lro_mock .result .return_value = (
131
+ test_rag_constants .TEST_GAPIC_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG
132
+ )
133
+ update_rag_corpus_mock_vertex_ai_engine_search_config .return_value = (
134
+ update_rag_corpus_lro_mock
135
+ )
136
+ yield update_rag_corpus_mock_vertex_ai_engine_search_config
137
+
138
+
88
139
@pytest .fixture
89
140
def update_rag_corpus_mock_vertex_vector_search ():
90
141
with mock .patch .object (
@@ -247,6 +298,9 @@ def rag_corpus_eq(returned_corpus, expected_corpus):
247
298
assert returned_corpus .name == expected_corpus .name
248
299
assert returned_corpus .display_name == expected_corpus .display_name
249
300
assert returned_corpus .backend_config .__eq__ (expected_corpus .backend_config )
301
+ assert returned_corpus .vertex_ai_search_config .__eq__ (
302
+ expected_corpus .vertex_ai_search_config
303
+ )
250
304
251
305
252
306
def rag_file_eq (returned_file , expected_file ):
@@ -328,12 +382,90 @@ def test_create_corpus_pinecone_success(self):
328
382
329
383
rag_corpus_eq (rag_corpus , test_rag_constants .TEST_RAG_CORPUS_PINECONE )
330
384
385
+ @pytest .mark .usefixtures ("create_rag_corpus_mock_vertex_ai_engine_search_config" )
386
+ def test_create_corpus_vais_engine_search_config_success (self ):
387
+ rag_corpus = rag .create_corpus (
388
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
389
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_ENGINE ,
390
+ )
391
+
392
+ rag_corpus_eq (
393
+ rag_corpus ,
394
+ test_rag_constants .TEST_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG ,
395
+ )
396
+
397
+ @pytest .mark .usefixtures ("create_rag_corpus_mock_vertex_ai_datastore_search_config" )
398
+ def test_create_corpus_vais_datastore_search_config_success (self ):
399
+ rag_corpus = rag .create_corpus (
400
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
401
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
402
+ )
403
+
404
+ rag_corpus_eq (
405
+ rag_corpus ,
406
+ test_rag_constants .TEST_RAG_CORPUS_VERTEX_AI_DATASTORE_SEARCH_CONFIG ,
407
+ )
408
+
409
+ def test_create_corpus_vais_datastore_search_config_with_backend_config_failure (
410
+ self ,
411
+ ):
412
+ with pytest .raises (ValueError ) as e :
413
+ rag .create_corpus (
414
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
415
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
416
+ backend_config = test_rag_constants .TEST_BACKEND_CONFIG_VERTEX_VECTOR_SEARCH_CONFIG ,
417
+ )
418
+ e .match ("Only one of vertex_ai_search_config or backend_config can be set." )
419
+
420
+ def test_set_vertex_ai_search_config_with_invalid_serving_config_failure (self ):
421
+ with pytest .raises (ValueError ) as e :
422
+ rag .create_corpus (
423
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
424
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_INVALID ,
425
+ )
426
+ e .match (
427
+ "serving_config must be of the format `projects/{project}/locations/{location}/collections/{collection}/engines/{engine}/servingConfigs/{serving_config}` or `projects/{project}/locations/{location}/collections/{collection}/dataStores/{data_store}/servingConfigs/{serving_config}`"
428
+ )
429
+
430
+ def test_set_vertex_ai_search_config_with_empty_serving_config_failure (self ):
431
+ with pytest .raises (ValueError ) as e :
432
+ rag .create_corpus (
433
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
434
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_EMPTY ,
435
+ )
436
+ e .match ("serving_config must be set." )
437
+
331
438
@pytest .mark .usefixtures ("rag_data_client_mock_exception" )
332
439
def test_create_corpus_failure (self ):
333
440
with pytest .raises (RuntimeError ) as e :
334
441
rag .create_corpus (display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME )
335
442
e .match ("Failed in RagCorpus creation due to" )
336
443
444
+ @pytest .mark .usefixtures ("update_rag_corpus_mock_vertex_ai_engine_search_config" )
445
+ def test_update_corpus_vais_engine_search_config_success (self ):
446
+ rag_corpus = rag .update_corpus (
447
+ corpus_name = test_rag_constants .TEST_RAG_CORPUS_RESOURCE_NAME ,
448
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
449
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_ENGINE ,
450
+ )
451
+
452
+ rag_corpus_eq (
453
+ rag_corpus ,
454
+ test_rag_constants .TEST_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG ,
455
+ )
456
+
457
+ def test_update_corpus_vais_datastore_search_config_with_backend_config_failure (
458
+ self ,
459
+ ):
460
+ with pytest .raises (ValueError ) as e :
461
+ rag .update_corpus (
462
+ corpus_name = test_rag_constants .TEST_RAG_CORPUS_RESOURCE_NAME ,
463
+ display_name = test_rag_constants .TEST_CORPUS_DISPLAY_NAME ,
464
+ vertex_ai_search_config = test_rag_constants .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
465
+ backend_config = test_rag_constants .TEST_BACKEND_CONFIG_VERTEX_VECTOR_SEARCH_CONFIG ,
466
+ )
467
+ e .match ("Only one of vertex_ai_search_config or backend_config can be set." )
468
+
337
469
@pytest .mark .usefixtures ("update_rag_corpus_mock_pinecone" )
338
470
def test_update_corpus_pinecone_success (self ):
339
471
rag_corpus = rag .update_corpus (
0 commit comments