@@ -11,6 +11,7 @@ import {
11
11
genCollectionParams ,
12
12
VECTOR_FIELD_NAME ,
13
13
GENERATE_NAME ,
14
+ dynamicFields ,
14
15
} from '../tools' ;
15
16
16
17
const milvusClient = new MilvusClient ( { address : IP } ) ;
@@ -29,6 +30,14 @@ const COLLECTION_NAME_AUTO_ID_PARAMS = genCollectionParams({
29
30
dim : [ 4 ] ,
30
31
vectorType : [ DataType . FloatVector ] ,
31
32
autoID : true ,
33
+ enableDynamic : true ,
34
+ fields : [
35
+ {
36
+ name : 'other_ids' ,
37
+ data_type : DataType . Int32 ,
38
+ description : '' ,
39
+ } ,
40
+ ] ,
32
41
} ) ;
33
42
34
43
const PARTITION_NAME = 'test' ;
@@ -56,6 +65,30 @@ describe(`Upsert API`, () => {
56
65
57
66
// create collection autoid = true and float_vector
58
67
await milvusClient . createCollection ( COLLECTION_NAME_AUTO_ID_PARAMS ) ;
68
+ // create index before load
69
+ await milvusClient . createIndex ( {
70
+ collection_name : COLLECTION_NAME_AUTO_ID ,
71
+ field_name : VECTOR_FIELD_NAME ,
72
+ extra_params : {
73
+ index_type : 'IVF_FLAT' ,
74
+ metric_type : 'L2' ,
75
+ params : JSON . stringify ( { nlist : 1024 } ) ,
76
+ } ,
77
+ } ) ;
78
+ // load collection
79
+ await milvusClient . loadCollectionSync ( {
80
+ collection_name : COLLECTION_NAME_AUTO_ID ,
81
+ } ) ;
82
+ // pare data
83
+ const vectorsData = generateInsertData (
84
+ [ ...COLLECTION_NAME_AUTO_ID_PARAMS . fields , ...dynamicFields ] ,
85
+ 10
86
+ ) ;
87
+ // insert data
88
+ await milvusClient . insert ( {
89
+ collection_name : COLLECTION_NAME_AUTO_ID ,
90
+ fields_data : vectorsData ,
91
+ } ) ;
59
92
60
93
// create collection autoid = false and binary_vector
61
94
@@ -162,20 +195,46 @@ describe(`Upsert API`, () => {
162
195
}
163
196
} ) ;
164
197
165
- it ( `Upsert Data on float field and autoId is true expect error` , async ( ) => {
166
- const vectorsData = generateInsertData (
167
- COLLECTION_NAME_AUTO_ID_PARAMS . fields ,
168
- 10
169
- ) ;
198
+ it ( `Upsert Data on float field and autoId is true expect successful` , async ( ) => {
199
+ const query = await milvusClient . query ( {
200
+ collection_name : COLLECTION_NAME_AUTO_ID ,
201
+ expr : 'id > 0' ,
202
+ limit : 4 ,
203
+ } ) ;
204
+
205
+ const other_ids = query . data . map ( ( item : any ) => item . other_ids ) ;
206
+
207
+ // modify the bool field to true
208
+ const vectorsData = query . data . map ( ( item : any ) => {
209
+ item . bool = true ;
210
+ item . dynamic_upserted_int32 = 100 ;
211
+ return item ;
212
+ } ) ;
170
213
214
+ // upsert the data
171
215
const params : InsertReq = {
172
216
collection_name : COLLECTION_NAME_AUTO_ID ,
173
217
fields_data : vectorsData ,
174
218
} ;
175
219
220
+ // expect successful
176
221
const res = await milvusClient . upsert ( params ) ;
222
+ expect ( res . status . error_code ) . toEqual ( ErrorCode . SUCCESS ) ;
177
223
178
- expect ( res . status . error_code ) . toEqual ( ErrorCode . IllegalArgument ) ;
224
+ // query these id
225
+ const query2 = await milvusClient . query ( {
226
+ collection_name : COLLECTION_NAME_AUTO_ID ,
227
+ expr : `other_ids in [${ other_ids . join ( ',' ) } ]` ,
228
+ limit : 4 ,
229
+ } ) ;
230
+ // check the bool field
231
+ expect ( query2 . data . every ( ( item : any ) => item . bool ) ) . toBeTruthy ( ) ;
232
+ // check the dynamic field
233
+ expect (
234
+ query2 . data . every (
235
+ ( item : any ) => item . $meta . dynamic_upserted_int32 === 100
236
+ )
237
+ ) . toBeTruthy ( ) ;
179
238
} ) ;
180
239
181
240
it ( `Upsert Data on different scalar fields` , async ( ) => {
0 commit comments