@@ -26,7 +26,7 @@ class TestFullTextHybridSearchQuery(unittest.TestCase):
2626 masterKey = config .masterKey
2727 connectionPolicy = config .connectionPolicy
2828 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 ())
3030
3131 @classmethod
3232 def setUpClass (cls ):
@@ -40,7 +40,7 @@ def setUpClass(cls):
4040 cls .client = cosmos_client .CosmosClient (cls .host , cls .masterKey )
4141 cls .test_db = cls .client .create_database (str (uuid .uuid4 ()))
4242 cls .test_container = cls .test_db .create_container (
43- id = "FTS" + cls .TEST_CONTAINER_ID ,
43+ id = cls .TEST_CONTAINER_ID ,
4444 partition_key = PartitionKey (path = "/pk" ),
4545 offer_throughput = test_config .TestConfig .THROUGHPUT_FOR_2_PARTITIONS ,
4646 indexing_policy = test_config .get_full_text_indexing_policy (path = "/text" ),
@@ -51,7 +51,7 @@ def setUpClass(cls):
5151 item ['pk' ] = str ((index % 2 ) + 1 )
5252 cls .test_container .create_item (item )
5353 # 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)
5555
5656 @classmethod
5757 def tearDownClass (cls ):
@@ -135,31 +135,31 @@ def test_hybrid_search_queries(self):
135135 for res in result_list :
136136 assert res ['index' ] in [85 , 57 ]
137137
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 " \
139139 "FullTextContains(c.text, 'John') OR FullTextContains(c.text, 'United States') " \
140140 "ORDER BY RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States'))"
141141 results = self .test_container .query_items (query , enable_cross_partition_query = True )
142142 result_list = list (results )
143- assert len (result_list ) == 15
143+ assert len (result_list ) == 13
144144 for res in result_list :
145145 assert res ['index' ] in [61 , 51 , 49 , 54 , 75 , 24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ]
146146
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 " \
148148 "FullTextContains(c.title, 'John') OR FullTextContains(c.text, 'John') OR " \
149149 "FullTextContains(c.text, 'United States') ORDER BY RANK RRF(FullTextScore(c.title, 'John')," \
150150 " FullTextScore(c.text, 'United States'))"
151151 results = self .test_container .query_items (query , enable_cross_partition_query = True )
152152 result_list = list (results )
153153 assert len (result_list ) == 10
154154 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 ]
156156
157157 query = "SELECT c.index, c.title FROM c WHERE FullTextContains(c.title, 'John')" \
158158 " OR FullTextContains(c.text, 'John') OR FullTextContains(c.text, 'United States') ORDER BY " \
159159 "RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States')) OFFSET 5 LIMIT 10"
160160 results = self .test_container .query_items (query , enable_cross_partition_query = True )
161161 result_list = list (results )
162- assert len (result_list ) == 10
162+ assert len (result_list ) == 8
163163 for res in result_list :
164164 assert res ['index' ] in [24 , 77 , 76 , 80 , 25 , 22 , 2 , 66 , 57 , 85 ]
165165
@@ -169,7 +169,7 @@ def test_hybrid_search_queries(self):
169169 result_list = list (results )
170170 assert len (result_list ) == 10
171171 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 ]
173173
174174 query = "SELECT c.index, c.title FROM c " \
175175 "ORDER BY RANK RRF(FullTextScore(c.title, 'John'), FullTextScore(c.text, 'United States')) " \
@@ -178,7 +178,7 @@ def test_hybrid_search_queries(self):
178178 result_list = list (results )
179179 assert len (result_list ) == 13
180180 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 ]
182182
183183 item_vector = self .test_container .read_item ('50' , '1' )['vector' ]
184184 query = "SELECT c.index, c.title FROM c " \
@@ -188,7 +188,7 @@ def test_hybrid_search_queries(self):
188188 result_list = list (results )
189189 assert len (result_list ) == 10
190190 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 ]
192192
193193 def test_hybrid_search_query_pagination (self ):
194194 query = "SELECT c.index, c.title FROM c " \
@@ -237,10 +237,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
237237 results = self .test_container .query_items (query , enable_cross_partition_query = True )
238238 result_list = [res ['Index' ] for res in results ]
239239 # 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 ]
244242
245243 # Test case 2
246244 query = """
@@ -252,10 +250,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
252250 results = self .test_container .query_items (query , enable_cross_partition_query = True )
253251 result_list = [res ['Index' ] for res in results ]
254252 # 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 ]
259255
260256 # Test case 3
261257 query = """
@@ -266,7 +262,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
266262 """
267263 results = self .test_container .query_items (query , enable_cross_partition_query = True )
268264 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 ]
270267
271268 # Test case 4
272269 query = """
@@ -278,10 +275,8 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
278275 results = self .test_container .query_items (query , enable_cross_partition_query = True )
279276 result_list = [res ['Index' ] for res in results ]
280277 # 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 ]
285280
286281 # Test case 5
287282 item_vector = self .test_container .read_item ('50' , '1' )['vector' ]
@@ -292,7 +287,7 @@ def test_hybrid_search_weighted_reciprocal_rank_fusion(self):
292287 result_list = list (results )
293288 assert len (result_list ) == 10
294289 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 ]
296291
297292 def test_invalid_hybrid_search_queries_weighted_reciprocal_rank_fusion (self ):
298293 try :
0 commit comments