@@ -73,24 +73,58 @@ def teardown_method(self):
73
73
74
74
@pytest .mark .usefixtures ("retrieve_contexts_mock" )
75
75
def test_retrieval_query_rag_resources_success (self ):
76
+ with pytest .warns (DeprecationWarning ):
77
+ response = rag .retrieval_query (
78
+ rag_resources = [test_rag_constants_preview .TEST_RAG_RESOURCE ],
79
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
80
+ similarity_top_k = 2 ,
81
+ vector_distance_threshold = 0.5 ,
82
+ vector_search_alpha = 0.5 ,
83
+ )
84
+ retrieve_contexts_eq (
85
+ response , test_rag_constants_preview .TEST_RETRIEVAL_RESPONSE
86
+ )
87
+
88
+ @pytest .mark .usefixtures ("retrieve_contexts_mock" )
89
+ def test_retrieval_query_rag_resources_config_success (self ):
90
+ response = rag .retrieval_query (
91
+ rag_resources = [test_rag_constants_preview .TEST_RAG_RESOURCE ],
92
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
93
+ rag_retrieval_config = test_rag_constants_preview .TEST_RAG_RETRIEVAL_CONFIG_ALPHA ,
94
+ )
95
+ retrieve_contexts_eq (
96
+ response , test_rag_constants_preview .TEST_RETRIEVAL_RESPONSE
97
+ )
98
+
99
+ @pytest .mark .usefixtures ("retrieve_contexts_mock" )
100
+ def test_retrieval_query_rag_resources_default_config_success (self ):
76
101
response = rag .retrieval_query (
77
102
rag_resources = [test_rag_constants_preview .TEST_RAG_RESOURCE ],
78
103
text = test_rag_constants_preview .TEST_QUERY_TEXT ,
79
- similarity_top_k = 2 ,
80
- vector_distance_threshold = 0.5 ,
81
- vector_search_alpha = 0.5 ,
82
104
)
83
105
retrieve_contexts_eq (
84
106
response , test_rag_constants_preview .TEST_RETRIEVAL_RESPONSE
85
107
)
86
108
87
109
@pytest .mark .usefixtures ("retrieve_contexts_mock" )
88
110
def test_retrieval_query_rag_corpora_success (self ):
111
+ with pytest .warns (DeprecationWarning ):
112
+ response = rag .retrieval_query (
113
+ rag_corpora = [test_rag_constants_preview .TEST_RAG_CORPUS_ID ],
114
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
115
+ similarity_top_k = 2 ,
116
+ vector_distance_threshold = 0.5 ,
117
+ )
118
+ retrieve_contexts_eq (
119
+ response , test_rag_constants_preview .TEST_RETRIEVAL_RESPONSE
120
+ )
121
+
122
+ @pytest .mark .usefixtures ("retrieve_contexts_mock" )
123
+ def test_retrieval_query_rag_corpora_config_success (self ):
89
124
response = rag .retrieval_query (
90
125
rag_corpora = [test_rag_constants_preview .TEST_RAG_CORPUS_ID ],
91
126
text = test_rag_constants_preview .TEST_QUERY_TEXT ,
92
- similarity_top_k = 2 ,
93
- vector_distance_threshold = 0.5 ,
127
+ rag_retrieval_config = test_rag_constants_preview .TEST_RAG_RETRIEVAL_CONFIG ,
94
128
)
95
129
retrieve_contexts_eq (
96
130
response , test_rag_constants_preview .TEST_RETRIEVAL_RESPONSE
@@ -107,6 +141,16 @@ def test_retrieval_query_failure(self):
107
141
)
108
142
e .match ("Failed in retrieving contexts due to" )
109
143
144
+ @pytest .mark .usefixtures ("rag_client_mock_exception" )
145
+ def test_retrieval_query_config_failure (self ):
146
+ with pytest .raises (RuntimeError ) as e :
147
+ rag .retrieval_query (
148
+ rag_resources = [test_rag_constants_preview .TEST_RAG_RESOURCE ],
149
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
150
+ rag_retrieval_config = test_rag_constants_preview .TEST_RAG_RETRIEVAL_CONFIG ,
151
+ )
152
+ e .match ("Failed in retrieving contexts due to" )
153
+
110
154
def test_retrieval_query_invalid_name (self ):
111
155
with pytest .raises (ValueError ) as e :
112
156
rag .retrieval_query (
@@ -119,6 +163,17 @@ def test_retrieval_query_invalid_name(self):
119
163
)
120
164
e .match ("Invalid RagCorpus name" )
121
165
166
+ def test_retrieval_query_invalid_name_config (self ):
167
+ with pytest .raises (ValueError ) as e :
168
+ rag .retrieval_query (
169
+ rag_resources = [
170
+ test_rag_constants_preview .TEST_RAG_RESOURCE_INVALID_NAME
171
+ ],
172
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
173
+ rag_retrieval_config = test_rag_constants_preview .TEST_RAG_RETRIEVAL_CONFIG ,
174
+ )
175
+ e .match ("Invalid RagCorpus name" )
176
+
122
177
def test_retrieval_query_multiple_rag_corpora (self ):
123
178
with pytest .raises (ValueError ) as e :
124
179
rag .retrieval_query (
@@ -132,6 +187,18 @@ def test_retrieval_query_multiple_rag_corpora(self):
132
187
)
133
188
e .match ("Currently only support 1 RagCorpus" )
134
189
190
+ def test_retrieval_query_multiple_rag_corpora_config (self ):
191
+ with pytest .raises (ValueError ) as e :
192
+ rag .retrieval_query (
193
+ rag_corpora = [
194
+ test_rag_constants_preview .TEST_RAG_CORPUS_ID ,
195
+ test_rag_constants_preview .TEST_RAG_CORPUS_ID ,
196
+ ],
197
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
198
+ rag_retrieval_config = test_rag_constants_preview .TEST_RAG_RETRIEVAL_CONFIG ,
199
+ )
200
+ e .match ("Currently only support 1 RagCorpus" )
201
+
135
202
def test_retrieval_query_multiple_rag_resources (self ):
136
203
with pytest .raises (ValueError ) as e :
137
204
rag .retrieval_query (
@@ -144,3 +211,15 @@ def test_retrieval_query_multiple_rag_resources(self):
144
211
vector_distance_threshold = 0.5 ,
145
212
)
146
213
e .match ("Currently only support 1 RagResource" )
214
+
215
+ def test_retrieval_query_multiple_rag_resources_config (self ):
216
+ with pytest .raises (ValueError ) as e :
217
+ rag .retrieval_query (
218
+ rag_resources = [
219
+ test_rag_constants_preview .TEST_RAG_RESOURCE ,
220
+ test_rag_constants_preview .TEST_RAG_RESOURCE ,
221
+ ],
222
+ text = test_rag_constants_preview .TEST_QUERY_TEXT ,
223
+ rag_retrieval_config = test_rag_constants_preview .TEST_RAG_RETRIEVAL_CONFIG ,
224
+ )
225
+ e .match ("Currently only support 1 RagResource" )
0 commit comments