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