11import numpy
22import pytest
33
4- from pymilvus import CollectionSchema , FieldSchema , DataType , MilvusException
4+ from pymilvus import CollectionSchema , FieldSchema , DataType
55from utils import *
66from pymilvus .orm import schema as s
77
88
9+ from pymilvus .orm .schema import Function , FunctionType
10+
911class TestCollectionSchema :
1012 @pytest .fixture (scope = "function" )
1113 def raw_dict (self ):
12- _dict = {}
13- _dict ["description" ] = "TestCollectionSchema_description"
14- fields = [
15- {
16- "name" : "vec1" ,
17- "description" : "desc1" ,
18- "type" : DataType .FLOAT_VECTOR ,
19- "params" : {"dim" : 128 },
20- },
21-
22- {
23- "name" : "vec2" ,
24- "description" : "desc2" ,
25- "type" : DataType .BINARY_VECTOR ,
26- "params" : {"dim" : 128 },
27- },
28- {
29- "name" : "ID" ,
30- "description" : "ID" ,
31- "type" : DataType .INT64 ,
32- "is_primary" : True ,
33- "auto_id" : False
34- },
35- ]
36- _dict ["fields" ] = fields
37- _dict ["enable_dynamic_field" ] = True
38-
39- return _dict
14+ return {
15+ "description" : "TestCollectionSchema_description" ,
16+ "enable_dynamic_field" : True ,
17+ "fields" : [
18+ {
19+ "name" : "vec1" ,
20+ "description" : "desc1" ,
21+ "type" : DataType .FLOAT_VECTOR ,
22+ "params" : {"dim" : 128 },
23+ },
24+ {
25+ "name" : "vec2" ,
26+ "description" : "desc2" ,
27+ "type" : DataType .BINARY_VECTOR ,
28+ "params" : {"dim" : 128 },
29+ },
30+ {
31+ "name" : "ID" ,
32+ "description" : "ID" ,
33+ "type" : DataType .INT64 ,
34+ "is_primary" : True ,
35+ "auto_id" : False
36+ },
37+ ]
38+ }
4039
4140 def test_constructor_from_dict (self , raw_dict ):
4241 schema = CollectionSchema .construct_from_dict (raw_dict )
@@ -54,6 +53,14 @@ def test_to_dict(self, raw_dict):
5453 assert target == raw_dict
5554 assert target is not raw_dict
5655
56+ def test_init_with_functions (self , raw_dict ):
57+ functions = [
58+ Function ("func1" , FunctionType .BM25 , ["field1" ], ["field2" ])
59+ ]
60+ schema = CollectionSchema .construct_from_dict (raw_dict )
61+ schema_with_func = CollectionSchema (schema .fields , schema .description , functions = functions )
62+ assert schema_with_func .functions == functions
63+
5764
5865class TestFieldSchema :
5966 @pytest .fixture (scope = "function" )
0 commit comments