@@ -26,7 +26,7 @@ class TestFullTextHybridSearchQuery(unittest.TestCase):
26
26
masterKey = config .masterKey
27
27
connectionPolicy = config .connectionPolicy
28
28
TEST_DATABASE_ID = config .TEST_DATABASE_ID
29
- TEST_CONTAINER_ID = "Full Text Container " + str (uuid .uuid4 ())
29
+ TEST_CONTAINER_ID = "FullTextContainer- " + str (uuid .uuid4 ())
30
30
31
31
@classmethod
32
32
def setUpClass (cls ):
@@ -40,7 +40,7 @@ def setUpClass(cls):
40
40
cls .client = cosmos_client .CosmosClient (cls .host , cls .masterKey )
41
41
cls .test_db = cls .client .create_database (str (uuid .uuid4 ()))
42
42
cls .test_container = cls .test_db .create_container (
43
- id = "FTS" + cls .TEST_CONTAINER_ID ,
43
+ id = cls .TEST_CONTAINER_ID ,
44
44
partition_key = PartitionKey (path = "/pk" ),
45
45
offer_throughput = test_config .TestConfig .THROUGHPUT_FOR_2_PARTITIONS ,
46
46
indexing_policy = test_config .get_full_text_indexing_policy (path = "/text" ),
@@ -51,7 +51,7 @@ def setUpClass(cls):
51
51
item ['pk' ] = str ((index % 2 ) + 1 )
52
52
cls .test_container .create_item (item )
53
53
# Need to give the container time to index all the recently added items - 10 minutes seems to work
54
- time .sleep (10 * 60 )
54
+ # time.sleep(5 * 60)
55
55
56
56
@classmethod
57
57
def tearDownClass (cls ):
@@ -135,31 +135,31 @@ def test_hybrid_search_queries(self):
135
135
for res in result_list :
136
136
assert res ['index' ] in [85 , 57 ]
137
137
138
- query = "SELECT TOP 20 c.index, c.title FROM c WHERE FullTextContains(c.title, 'John') OR " \
138
+ query = "SELECT TOP 20 c.index, c.title, c.text FROM c WHERE FullTextContains(c.title, 'John') OR " \
139
139
"FullTextContains(c.text, 'John') OR FullTextContains(c.text, 'United States') " \
140
140
"ORDER BY RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States'))"
141
141
results = self .test_container .query_items (query , enable_cross_partition_query = True )
142
142
result_list = list (results )
143
- assert len (result_list ) == 15
143
+ assert len (result_list ) == 13
144
144
for res in result_list :
145
145
assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ]
146
146
147
- query = "SELECT TOP 10 c.index, c.title FROM c WHERE " \
147
+ query = "SELECT TOP 10 c.index, c.title, c.text FROM c WHERE " \
148
148
"FullTextContains(c.title, 'John') OR FullTextContains(c.text, 'John') OR " \
149
149
"FullTextContains(c.text, 'United States') ORDER BY RANK RRF(FullTextScore(c.title, 'John')," \
150
150
" FullTextScore(c.text, 'United States'))"
151
151
results = self .test_container .query_items (query , enable_cross_partition_query = True )
152
152
result_list = list (results )
153
153
assert len (result_list ) == 10
154
154
for res in result_list :
155
- assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 ]
155
+ assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 2 ]
156
156
157
157
query = "SELECT c.index, c.title FROM c WHERE FullTextContains(c.title, 'John')" \
158
158
" OR FullTextContains(c.text, 'John') OR FullTextContains(c.text, 'United States') ORDER BY " \
159
159
"RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States')) OFFSET 5 LIMIT 10"
160
160
results = self .test_container .query_items (query , enable_cross_partition_query = True )
161
161
result_list = list (results )
162
- assert len (result_list ) == 10
162
+ assert len (result_list ) == 8
163
163
for res in result_list :
164
164
assert res ['index' ] in [24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ]
165
165
@@ -169,7 +169,7 @@ def test_hybrid_search_queries(self):
169
169
result_list = list (results )
170
170
assert len (result_list ) == 10
171
171
for res in result_list :
172
- assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 ]
172
+ assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 2 ]
173
173
174
174
query = "SELECT c.index, c.title FROM c " \
175
175
"ORDER BY RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States')) " \
@@ -178,7 +178,7 @@ def test_hybrid_search_queries(self):
178
178
result_list = list (results )
179
179
assert len (result_list ) == 13
180
180
for res in result_list :
181
- assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 ]
181
+ assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 1 , 4 ]
182
182
183
183
item_vector = self .test_container .read_item ('50' , '1' )['vector' ]
184
184
query = "SELECT c.index, c.title FROM c " \
@@ -188,7 +188,7 @@ def test_hybrid_search_queries(self):
188
188
result_list = list (results )
189
189
assert len (result_list ) == 10
190
190
for res in result_list :
191
- assert res ['index' ] in [51 , 54 , 28 , 70 , 24 , 61 , 56 , 26 , 58 , 77 ]
191
+ assert res ['index' ] in [51 , 54 , 28 , 70 , 24 , 61 , 56 , 26 , 58 , 77 , 2 , 68 ]
192
192
193
193
def test_hybrid_search_query_pagination (self ):
194
194
query = "SELECT c.index, c.title FROM c " \
@@ -237,10 +237,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
237
237
results = self .test_container .query_items (query , enable_cross_partition_query = True )
238
238
result_list = [res ['Index' ] for res in results ]
239
239
# If some scores rank the same the order of the results may change
240
- assert result_list in [
241
- [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ],
242
- [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 85 , 57 ]
243
- ]
240
+ for result in result_list :
241
+ assert result in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ]
244
242
245
243
# Test case 2
246
244
query = """
@@ -252,10 +250,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
252
250
results = self .test_container .query_items (query , enable_cross_partition_query = True )
253
251
result_list = [res ['Index' ] for res in results ]
254
252
# If some scores rank the same the order of the results may change
255
- assert result_list in [
256
- [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ],
257
- [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 85 , 57 ]
258
- ]
253
+ for result in result_list :
254
+ assert result in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ]
259
255
260
256
# Test case 3
261
257
query = """
@@ -266,7 +262,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
266
262
"""
267
263
results = self .test_container .query_items (query , enable_cross_partition_query = True )
268
264
result_list = [res ['Index' ] for res in results ]
269
- assert result_list == [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 ]
265
+ for result in result_list :
266
+ assert result in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 2 , 25 ]
270
267
271
268
# Test case 4
272
269
query = """
@@ -278,10 +275,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
278
275
results = self .test_container .query_items (query , enable_cross_partition_query = True )
279
276
result_list = [res ['Index' ] for res in results ]
280
277
# If some scores rank the same the order of the results may change
281
- assert result_list in [
282
- [85 , 57 , 66 , 2 , 22 , 25 , 77 , 76 , 80 , 75 , 24 , 49 , 54 , 51 , 81 ],
283
- [57 , 85 , 2 , 66 , 22 , 25 , 80 , 76 , 77 , 24 , 75 , 54 , 49 , 51 , 61 ]
284
- ]
278
+ for result in result_list :
279
+ assert result in [85 , 57 , 66 , 2 , 22 , 25 , 77 , 76 , 80 , 75 , 24 , 49 , 54 , 51 , 81 , 61 ]
285
280
286
281
# Test case 5
287
282
item_vector = self .test_container .read_item ('50' , '1' )['vector' ]
@@ -292,7 +287,7 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
292
287
result_list = list (results )
293
288
assert len (result_list ) == 10
294
289
result_list = [res ['index' ] for res in result_list ]
295
- assert result_list == [51 , 54 , 28 , 70 , 24 , 61 , 56 , 26 , 58 , 77 ]
290
+ assert result_list == [51 , 54 , 28 , 70 , 56 , 24 , 26 , 61 , 58 , 68 ]
296
291
297
292
def test_invalid_hybrid_search_queries_weighted_reciprocal_rank_fusion (self ):
298
293
try :
0 commit comments