1
1
import numpy
2
2
import pytest
3
3
4
- from pymilvus import CollectionSchema , FieldSchema , DataType , MilvusException
4
+ from pymilvus import CollectionSchema , FieldSchema , DataType
5
5
from utils import *
6
6
from pymilvus .orm import schema as s
7
7
8
8
9
+ from pymilvus .orm .schema import Function , FunctionType
10
+
9
11
class TestCollectionSchema :
10
12
@pytest .fixture (scope = "function" )
11
13
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
+ }
40
39
41
40
def test_constructor_from_dict (self , raw_dict ):
42
41
schema = CollectionSchema .construct_from_dict (raw_dict )
@@ -54,6 +53,14 @@ def test_to_dict(self, raw_dict):
54
53
assert target == raw_dict
55
54
assert target is not raw_dict
56
55
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
+
57
64
58
65
class TestFieldSchema :
59
66
@pytest .fixture (scope = "function" )
0 commit comments