@@ -39,6 +39,7 @@ def _milvus_from_texts(
39
39
# connection_args={"uri": "http://127.0.0.1:19530"},
40
40
connection_args = {"uri" : "./milvus_demo.db" },
41
41
drop_old = drop ,
42
+ consistency_level = "Strong" ,
42
43
** kwargs ,
43
44
)
44
45
@@ -303,6 +304,51 @@ def test_milvus_enable_dynamic_field_with_partition_key() -> None:
303
304
}
304
305
305
306
307
+ def test_milvus_array_field () -> None :
308
+ """Manually specify metadata schema, including an array_field.
309
+ For more information about array data type and filtering, please refer to
310
+ https://milvus.io/docs/array_data_type.md
311
+ """
312
+ from pymilvus import DataType
313
+
314
+ texts = ["foo" , "bar" , "baz" ]
315
+ metadatas = [{"id" : i , "array_field" : [i , i + 1 , i + 2 ]} for i in range (len (texts ))]
316
+
317
+ # Manually specify metadata schema, including an array_field.
318
+ # If some fields are not specified, Milvus will automatically infer their schemas.
319
+ docsearch = _milvus_from_texts (
320
+ metadatas = metadatas ,
321
+ metadata_schema = {
322
+ "array_field" : {
323
+ "dtype" : DataType .ARRAY ,
324
+ "kwargs" : {"element_type" : DataType .INT64 , "max_capacity" : 50 },
325
+ },
326
+ # "id": {
327
+ # "dtype": DataType.INT64,
328
+ # }
329
+ },
330
+ )
331
+ output = docsearch .similarity_search ("foo" , k = 10 , expr = "array_field[0] < 2" )
332
+ assert len (output ) == 2
333
+ output = docsearch .similarity_search (
334
+ "foo" , k = 10 , expr = "ARRAY_CONTAINS(array_field, 3)"
335
+ )
336
+ assert len (output ) == 2
337
+
338
+ # If we use enable_dynamic_field,
339
+ # there is no need to manually specify metadata schema.
340
+ docsearch = _milvus_from_texts (
341
+ enable_dynamic_field = True ,
342
+ metadatas = metadatas ,
343
+ )
344
+ output = docsearch .similarity_search ("foo" , k = 10 , expr = "array_field[0] < 2" )
345
+ assert len (output ) == 2
346
+ output = docsearch .similarity_search (
347
+ "foo" , k = 10 , expr = "ARRAY_CONTAINS(array_field, 3)"
348
+ )
349
+ assert len (output ) == 2
350
+
351
+
306
352
# if __name__ == "__main__":
307
353
# test_milvus()
308
354
# test_milvus_vector_search()
@@ -319,3 +365,4 @@ def test_milvus_enable_dynamic_field_with_partition_key() -> None:
319
365
# test_milvus_enable_dynamic_field()
320
366
# test_milvus_disable_dynamic_field()
321
367
# test_milvus_metadata_field()
368
+ # test_milvus_array_field()
0 commit comments