11"""Unit tests for the Milvus online store, run against Milvus Lite or a mocked client."""
22
3+ import json
34from datetime import datetime , timedelta , timezone
45from pathlib import Path
56from typing import Any , Dict , List , Optional , Tuple
@@ -1472,17 +1473,35 @@ def test_index_tags_create_scalar_and_json_path_indexes(
14721473 {},
14731474 "milvus.max_capacity tag must be" ,
14741475 ),
1476+ (
1477+ Field (name = "price" , dtype = Float64 , tags = {"milvus.enable_match" : "true" }),
1478+ {},
1479+ "not a String feature" ,
1480+ ),
1481+ (
1482+ Field (name = "title" , dtype = String , tags = {"milvus.enable_match" : "yes" }),
1483+ {},
1484+ "must be 'true' or 'false'" ,
1485+ ),
1486+ (
1487+ Field (name = "title" , dtype = String , tags = {"milvus.analyzer_params" : "[]" }),
1488+ {},
1489+ "milvus.analyzer_params must be a JSON dict" ,
1490+ ),
14751491 ],
14761492 ids = [
14771493 "params_without_index" ,
14781494 "bad_json" ,
14791495 "json_index_on_text" ,
14801496 "vector" ,
14811497 "capacity" ,
1498+ "analysis_on_non_string" ,
1499+ "match_not_boolean" ,
1500+ "analyzer_not_object" ,
14821501 ],
14831502)
14841503@patch (f"{ MILVUS_MODULE } .MilvusClient" )
1485- def test_index_and_capacity_tags_are_validated (
1504+ def test_field_tags_are_validated (
14861505 mock_client_cls : MagicMock , field : Field , online_store : Dict [str , Any ], match : str
14871506) -> None :
14881507 mock_client = _mock_client (mock_client_cls , has_collection = False )
@@ -1499,6 +1518,61 @@ def test_index_and_capacity_tags_are_validated(
14991518 mock_client .create_collection .assert_not_called ()
15001519
15011520
1521+ @pytest .mark .parametrize (
1522+ "tags, expected" ,
1523+ [
1524+ (
1525+ {"milvus.analyzer_params" : '{"tokenizer": "whitespace"}' },
1526+ {"enable_analyzer" : True , "analyzer_params" : {"tokenizer" : "whitespace" }},
1527+ ),
1528+ (
1529+ {"milvus.enable_match" : "true" },
1530+ {"enable_analyzer" : True , "enable_match" : True },
1531+ ),
1532+ (
1533+ {
1534+ "milvus.analyzer_params" : '{"tokenizer": "whitespace"}' ,
1535+ "milvus.enable_match" : "true" ,
1536+ },
1537+ {
1538+ "enable_analyzer" : True ,
1539+ "analyzer_params" : {"tokenizer" : "whitespace" },
1540+ "enable_match" : True ,
1541+ },
1542+ ),
1543+ ({"milvus.enable_match" : "false" }, {}),
1544+ ],
1545+ ids = ["analyzer" , "match" , "both" , "match_false" ],
1546+ )
1547+ @patch (f"{ MILVUS_MODULE } .MilvusClient" )
1548+ def test_text_analysis_tags_set_field_params (
1549+ mock_client_cls : MagicMock , tags : Dict [str , str ], expected : Dict [str , Any ]
1550+ ) -> None :
1551+ mock_client = _mock_client (mock_client_cls , has_collection = False )
1552+ fv = FeatureView (
1553+ name = "products" ,
1554+ entities = [_driver_entity ()],
1555+ ttl = timedelta (days = 1 ),
1556+ schema = [
1557+ Field (name = "driver_id" , dtype = Int64 ),
1558+ Field (name = "title" , dtype = String , tags = tags ),
1559+ ],
1560+ )
1561+
1562+ MilvusOnlineStore ()._get_or_create_collection (_mock_config (), fv )
1563+
1564+ schema = mock_client .create_collection .call_args .kwargs ["schema" ]
1565+ params = next (field for field in schema .fields if field .name == "title" ).params
1566+ text_params = {
1567+ name : params [name ]
1568+ for name in ("enable_analyzer" , "analyzer_params" , "enable_match" )
1569+ if name in params
1570+ }
1571+ if "analyzer_params" in text_params :
1572+ text_params ["analyzer_params" ] = json .loads (text_params ["analyzer_params" ])
1573+ assert text_params == expected
1574+
1575+
15021576@patch (f"{ MILVUS_MODULE } .MilvusClient" )
15031577def test_missing_tag_indexes_on_an_existing_collection_are_logged (
15041578 mock_client_cls : MagicMock , caplog : pytest .LogCaptureFixture
0 commit comments