@@ -314,99 +314,99 @@ def test_delete_record(self, collection_id):
314
314
pytest .assume (new_nums == 0 )
315
315
316
316
317
- # @pytest.mark.test_sync
318
- # class TestChunk:
319
- #
320
- # @pytest.mark.run(order=41)
321
- # def test_query_chunks(self, collection_id):
322
- # # Query chunks.
323
- #
324
- # query_text = "Machine learning"
325
- # top_k = 1
326
- # res = query_chunks(
327
- # collection_id=collection_id, query_text=query_text, top_k=top_k, max_tokens=20000, score_threshold=0.04
328
- # )
329
- # pytest.assume(len(res) == top_k)
330
- # for chunk in res:
331
- # chunk_dict = vars(chunk)
332
- # assume_query_chunk_result(query_text, chunk_dict)
333
- # pytest.assume(chunk_dict["score"] >= 0.04)
334
- #
335
- # @pytest.mark.run(order=42)
336
- # def test_create_chunk(self, collection_id):
337
- # # Create a chunk.
338
- # create_chunk_data = {
339
- # "collection_id": collection_id,
340
- # "content": "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data.",
341
- # }
342
- # res = create_chunk(**create_chunk_data)
343
- # res_dict = vars(res)
344
- # assume_chunk_result(create_chunk_data, res_dict)
345
- #
346
- # @pytest.mark.run(order=43)
347
- # def test_list_chunks(self, collection_id):
348
- # # List chunks.
349
- #
350
- # nums_limit = 1
351
- # res = list_chunks(limit=nums_limit, collection_id=collection_id)
352
- # pytest.assume(len(res) == nums_limit)
353
- #
354
- # after_id = res[-1].chunk_id
355
- # after_res = list_chunks(limit=nums_limit, after=after_id, collection_id=collection_id)
356
- # pytest.assume(len(after_res) == nums_limit)
357
- #
358
- # twice_nums_list = list_chunks(limit=nums_limit * 2, collection_id=collection_id)
359
- # pytest.assume(len(twice_nums_list) == nums_limit * 2)
360
- # pytest.assume(after_res[-1] == twice_nums_list[-1])
361
- # pytest.assume(after_res[0] == twice_nums_list[nums_limit])
362
- #
363
- # before_id = after_res[0].chunk_id
364
- # before_res = list_chunks(limit=nums_limit, before=before_id, collection_id=collection_id)
365
- # pytest.assume(len(before_res) == nums_limit)
366
- # pytest.assume(before_res[-1] == twice_nums_list[nums_limit - 1])
367
- # pytest.assume(before_res[0] == twice_nums_list[0])
368
- #
369
- # @pytest.mark.run(order=44)
370
- # def test_get_chunk(self, collection_id):
371
- # # list chunks
372
- #
373
- # chunks = list_chunks(collection_id=collection_id)
374
- # for chunk in chunks:
375
- # chunk_id = chunk.chunk_id
376
- # res = get_chunk(collection_id=collection_id, chunk_id=chunk_id)
377
- # logger.info(f"get chunk response: {res}")
378
- # res_dict = vars(res)
379
- # pytest.assume(res_dict["collection_id"] == collection_id)
380
- # pytest.assume(res_dict["chunk_id"] == chunk_id)
381
- #
382
- # @pytest.mark.run(order=45)
383
- # def test_update_chunk(self, collection_id, chunk_id):
384
- # # Update a chunk.
385
- #
386
- # update_chunk_data = {
387
- # "collection_id": collection_id,
388
- # "chunk_id": chunk_id,
389
- # "content": "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data.",
390
- # "metadata": {"test": "test"},
391
- # }
392
- # res = update_chunk(**update_chunk_data)
393
- # res_dict = vars(res)
394
- # assume_chunk_result(update_chunk_data, res_dict)
395
- #
396
- # @pytest.mark.run(order=46)
397
- # def test_delete_chunk(self, collection_id):
398
- # # List chunks.
399
- #
400
- # chunks = list_chunks(collection_id=collection_id, limit=5)
401
- # for index, chunk in enumerate(chunks):
402
- # chunk_id = chunk.chunk_id
403
- #
404
- # # Delete a chunk.
405
- #
406
- # delete_chunk(collection_id=collection_id, chunk_id=chunk_id)
407
- #
408
- # # List chunks.
409
- #
410
- # new_chunks = list_chunks(collection_id=collection_id)
411
- # chunk_ids = [chunk.chunk_id for chunk in new_chunks]
412
- # pytest.assume(chunk_id not in chunk_ids)
317
+ @pytest .mark .test_sync
318
+ class TestChunk :
319
+
320
+ @pytest .mark .run (order = 41 )
321
+ def test_query_chunks (self , collection_id ):
322
+ # Query chunks.
323
+
324
+ query_text = "Machine learning"
325
+ top_k = 1
326
+ res = query_chunks (
327
+ collection_id = collection_id , query_text = query_text , top_k = top_k , max_tokens = 20000 , score_threshold = 0.04
328
+ )
329
+ pytest .assume (len (res ) == top_k )
330
+ for chunk in res :
331
+ chunk_dict = vars (chunk )
332
+ assume_query_chunk_result (query_text , chunk_dict )
333
+ pytest .assume (chunk_dict ["score" ] >= 0.04 )
334
+
335
+ @pytest .mark .run (order = 42 )
336
+ def test_create_chunk (self , collection_id ):
337
+ # Create a chunk.
338
+ create_chunk_data = {
339
+ "collection_id" : collection_id ,
340
+ "content" : "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data." ,
341
+ }
342
+ res = create_chunk (** create_chunk_data )
343
+ res_dict = vars (res )
344
+ assume_chunk_result (create_chunk_data , res_dict )
345
+
346
+ @pytest .mark .run (order = 43 )
347
+ def test_list_chunks (self , collection_id ):
348
+ # List chunks.
349
+
350
+ nums_limit = 1
351
+ res = list_chunks (limit = nums_limit , collection_id = collection_id )
352
+ pytest .assume (len (res ) == nums_limit )
353
+
354
+ after_id = res [- 1 ].chunk_id
355
+ after_res = list_chunks (limit = nums_limit , after = after_id , collection_id = collection_id )
356
+ pytest .assume (len (after_res ) == nums_limit )
357
+
358
+ twice_nums_list = list_chunks (limit = nums_limit * 2 , collection_id = collection_id )
359
+ pytest .assume (len (twice_nums_list ) == nums_limit * 2 )
360
+ pytest .assume (after_res [- 1 ] == twice_nums_list [- 1 ])
361
+ pytest .assume (after_res [0 ] == twice_nums_list [nums_limit ])
362
+
363
+ before_id = after_res [0 ].chunk_id
364
+ before_res = list_chunks (limit = nums_limit , before = before_id , collection_id = collection_id )
365
+ pytest .assume (len (before_res ) == nums_limit )
366
+ pytest .assume (before_res [- 1 ] == twice_nums_list [nums_limit - 1 ])
367
+ pytest .assume (before_res [0 ] == twice_nums_list [0 ])
368
+
369
+ @pytest .mark .run (order = 44 )
370
+ def test_get_chunk (self , collection_id ):
371
+ # list chunks
372
+
373
+ chunks = list_chunks (collection_id = collection_id )
374
+ for chunk in chunks :
375
+ chunk_id = chunk .chunk_id
376
+ res = get_chunk (collection_id = collection_id , chunk_id = chunk_id )
377
+ logger .info (f"get chunk response: { res } " )
378
+ res_dict = vars (res )
379
+ pytest .assume (res_dict ["collection_id" ] == collection_id )
380
+ pytest .assume (res_dict ["chunk_id" ] == chunk_id )
381
+
382
+ @pytest .mark .run (order = 45 )
383
+ def test_update_chunk (self , collection_id , chunk_id ):
384
+ # Update a chunk.
385
+
386
+ update_chunk_data = {
387
+ "collection_id" : collection_id ,
388
+ "chunk_id" : chunk_id ,
389
+ "content" : "Machine learning is a subfield of artificial intelligence (AI) that involves the development of algorithms that allow computers to learn from and make decisions or predictions based on data." ,
390
+ "metadata" : {"test" : "test" },
391
+ }
392
+ res = update_chunk (** update_chunk_data )
393
+ res_dict = vars (res )
394
+ assume_chunk_result (update_chunk_data , res_dict )
395
+
396
+ @pytest .mark .run (order = 46 )
397
+ def test_delete_chunk (self , collection_id ):
398
+ # List chunks.
399
+
400
+ chunks = list_chunks (collection_id = collection_id , limit = 5 )
401
+ for index , chunk in enumerate (chunks ):
402
+ chunk_id = chunk .chunk_id
403
+
404
+ # Delete a chunk.
405
+
406
+ delete_chunk (collection_id = collection_id , chunk_id = chunk_id )
407
+
408
+ # List chunks.
409
+
410
+ new_chunks = list_chunks (collection_id = collection_id )
411
+ chunk_ids = [chunk .chunk_id for chunk in new_chunks ]
412
+ pytest .assume (chunk_id not in chunk_ids )
0 commit comments