@@ -113,6 +113,57 @@ def create_rag_corpus_mock_pinecone():
113
113
yield create_rag_corpus_mock_pinecone
114
114
115
115
116
+ @pytest .fixture
117
+ def create_rag_corpus_mock_vertex_ai_engine_search_config ():
118
+ with mock .patch .object (
119
+ VertexRagDataServiceClient ,
120
+ "create_rag_corpus" ,
121
+ ) as create_rag_corpus_mock_vertex_ai_engine_search_config :
122
+ create_rag_corpus_lro_mock = mock .Mock (ga_operation .Operation )
123
+ create_rag_corpus_lro_mock .done .return_value = True
124
+ create_rag_corpus_lro_mock .result .return_value = (
125
+ test_rag_constants_preview .TEST_GAPIC_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG
126
+ )
127
+ create_rag_corpus_mock_vertex_ai_engine_search_config .return_value = (
128
+ create_rag_corpus_lro_mock
129
+ )
130
+ yield create_rag_corpus_mock_vertex_ai_engine_search_config
131
+
132
+
133
+ @pytest .fixture
134
+ def create_rag_corpus_mock_vertex_ai_datastore_search_config ():
135
+ with mock .patch .object (
136
+ VertexRagDataServiceClient ,
137
+ "create_rag_corpus" ,
138
+ ) as create_rag_corpus_mock_vertex_ai_datastore_search_config :
139
+ create_rag_corpus_lro_mock = mock .Mock (ga_operation .Operation )
140
+ create_rag_corpus_lro_mock .done .return_value = True
141
+ create_rag_corpus_lro_mock .result .return_value = (
142
+ test_rag_constants_preview .TEST_GAPIC_RAG_CORPUS_VERTEX_AI_DATASTORE_SEARCH_CONFIG
143
+ )
144
+ create_rag_corpus_mock_vertex_ai_datastore_search_config .return_value = (
145
+ create_rag_corpus_lro_mock
146
+ )
147
+ yield create_rag_corpus_mock_vertex_ai_datastore_search_config
148
+
149
+
150
+ @pytest .fixture
151
+ def update_rag_corpus_mock_vertex_ai_engine_search_config ():
152
+ with mock .patch .object (
153
+ VertexRagDataServiceClient ,
154
+ "update_rag_corpus" ,
155
+ ) as update_rag_corpus_mock_vertex_ai_engine_search_config :
156
+ update_rag_corpus_lro_mock = mock .Mock (ga_operation .Operation )
157
+ update_rag_corpus_lro_mock .done .return_value = True
158
+ update_rag_corpus_lro_mock .result .return_value = (
159
+ test_rag_constants_preview .TEST_GAPIC_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG
160
+ )
161
+ update_rag_corpus_mock_vertex_ai_engine_search_config .return_value = (
162
+ update_rag_corpus_lro_mock
163
+ )
164
+ yield update_rag_corpus_mock_vertex_ai_engine_search_config
165
+
166
+
116
167
@pytest .fixture
117
168
def update_rag_corpus_mock_weaviate ():
118
169
with mock .patch .object (
@@ -280,6 +331,9 @@ def rag_corpus_eq(returned_corpus, expected_corpus):
280
331
assert returned_corpus .name == expected_corpus .name
281
332
assert returned_corpus .display_name == expected_corpus .display_name
282
333
assert returned_corpus .vector_db .__eq__ (expected_corpus .vector_db )
334
+ assert returned_corpus .vertex_ai_search_config .__eq__ (
335
+ expected_corpus .vertex_ai_search_config
336
+ )
283
337
284
338
285
339
def rag_file_eq (returned_file , expected_file ):
@@ -373,6 +427,70 @@ def test_create_corpus_pinecone_success(self):
373
427
374
428
rag_corpus_eq (rag_corpus , test_rag_constants_preview .TEST_RAG_CORPUS_PINECONE )
375
429
430
+ @pytest .mark .usefixtures ("create_rag_corpus_mock_vertex_ai_engine_search_config" )
431
+ def test_create_corpus_vais_engine_search_config_success (self ):
432
+ rag_corpus = rag .create_corpus (
433
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
434
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_ENGINE ,
435
+ )
436
+
437
+ rag_corpus_eq (
438
+ rag_corpus ,
439
+ test_rag_constants_preview .TEST_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG ,
440
+ )
441
+
442
+ @pytest .mark .usefixtures ("create_rag_corpus_mock_vertex_ai_datastore_search_config" )
443
+ def test_create_corpus_vais_datastore_search_config_success (self ):
444
+ rag_corpus = rag .create_corpus (
445
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
446
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
447
+ )
448
+
449
+ rag_corpus_eq (
450
+ rag_corpus ,
451
+ test_rag_constants_preview .TEST_RAG_CORPUS_VERTEX_AI_DATASTORE_SEARCH_CONFIG ,
452
+ )
453
+
454
+ def test_create_corpus_vais_datastore_search_config_with_vector_db_failure (self ):
455
+ with pytest .raises (ValueError ) as e :
456
+ rag .create_corpus (
457
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
458
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
459
+ vector_db = test_rag_constants_preview .TEST_VERTEX_VECTOR_SEARCH_CONFIG ,
460
+ )
461
+ e .match ("Only one of vertex_ai_search_config or vector_db can be set." )
462
+
463
+ def test_create_corpus_vais_datastore_search_config_with_embedding_model_config_failure (
464
+ self ,
465
+ ):
466
+ with pytest .raises (ValueError ) as e :
467
+ rag .create_corpus (
468
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
469
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
470
+ embedding_model_config = test_rag_constants_preview .TEST_EMBEDDING_MODEL_CONFIG ,
471
+ )
472
+ e .match (
473
+ "Only one of vertex_ai_search_config or embedding_model_config can be set."
474
+ )
475
+
476
+ def test_set_vertex_ai_search_config_with_invalid_serving_config_failure (self ):
477
+ with pytest .raises (ValueError ) as e :
478
+ rag .create_corpus (
479
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
480
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_INVALID ,
481
+ )
482
+ e .match (
483
+ "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}`"
484
+ )
485
+
486
+ def test_set_vertex_ai_search_config_with_empty_serving_config_failure (self ):
487
+ with pytest .raises (ValueError ) as e :
488
+ rag .create_corpus (
489
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
490
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_EMPTY ,
491
+ )
492
+ e .match ("serving_config must be set." )
493
+
376
494
@pytest .mark .usefixtures ("rag_data_client_preview_mock_exception" )
377
495
def test_create_corpus_failure (self ):
378
496
with pytest .raises (RuntimeError ) as e :
@@ -462,6 +580,29 @@ def test_update_corpus_failure(self):
462
580
)
463
581
e .match ("Failed in RagCorpus update due to" )
464
582
583
+ @pytest .mark .usefixtures ("update_rag_corpus_mock_vertex_ai_engine_search_config" )
584
+ def test_update_corpus_vais_engine_search_config_success (self ):
585
+ rag_corpus = rag .update_corpus (
586
+ corpus_name = test_rag_constants_preview .TEST_RAG_CORPUS_RESOURCE_NAME ,
587
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
588
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_ENGINE ,
589
+ )
590
+
591
+ rag_corpus_eq (
592
+ rag_corpus ,
593
+ test_rag_constants_preview .TEST_RAG_CORPUS_VERTEX_AI_ENGINE_SEARCH_CONFIG ,
594
+ )
595
+
596
+ def test_update_corpus_vais_datastore_search_config_with_vector_db_failure (self ):
597
+ with pytest .raises (ValueError ) as e :
598
+ rag .update_corpus (
599
+ corpus_name = test_rag_constants_preview .TEST_RAG_CORPUS_RESOURCE_NAME ,
600
+ display_name = test_rag_constants_preview .TEST_CORPUS_DISPLAY_NAME ,
601
+ vertex_ai_search_config = test_rag_constants_preview .TEST_VERTEX_AI_SEARCH_CONFIG_DATASTORE ,
602
+ vector_db = test_rag_constants_preview .TEST_VERTEX_VECTOR_SEARCH_CONFIG ,
603
+ )
604
+ e .match ("Only one of vertex_ai_search_config or vector_db can be set." )
605
+
465
606
@pytest .mark .usefixtures ("rag_data_client_preview_mock" )
466
607
def test_get_corpus_success (self ):
467
608
rag_corpus = rag .get_corpus (
0 commit comments