diff --git a/docs/reference/online-stores/milvus.md b/docs/reference/online-stores/milvus.md index c893f700c44..723194c4420 100644 --- a/docs/reference/online-stores/milvus.md +++ b/docs/reference/online-stores/milvus.md @@ -101,7 +101,7 @@ online_store: | `partition_key_isolation` | unset | Enables partition key isolation on a new collection that has a partition key. When unset, Milvus uses its default. | | `vector_enabled` | `true` | Enables vector search. | | `varchar_max_length` | `65535` | Default `max_length` of VARCHAR fields. Override per field with the `max_length` tag. | -| `enable_openai_compatible_store` | `false` | Store numeric, array, `Json`, `Map` and `Struct` features as native Milvus types. See [Field types](#field-types). | +| `enable_openai_compatible_store` | `false` | Store numeric features as native Milvus numeric types. | The full set of configuration options is available in [MilvusOnlineStoreConfig](https://rtd.feast.dev/en/latest/#feast.infra.online_stores.milvus.MilvusOnlineStoreConfig). @@ -237,8 +237,8 @@ type. | `UnixTimestamp` | `VARCHAR` holding the seconds as text | `INT64` | | `Bytes` | `VARCHAR` holding base64 | `VARCHAR` holding base64 | | `Array` with `vector_index=True` | `FLOAT_VECTOR` with the field's `vector_length`, or `embedding_dim` when it is unset | the same | -| `Array` of `String`, `Bool`, `Int32`, `Int64`, `Float32`, `Float64` or `UnixTimestamp` without `vector_index` | `VARCHAR` holding the serialized value | `ARRAY` of the element type, with at most `milvus.max_capacity` elements. The default and the maximum are 4096 | -| `Json` and `Array(Json)` | `VARCHAR` holding the serialized value | `JSON` | +| `Array` of `String`, `Bool`, `Int32`, `Int64`, `Float32`, `Float64` or `UnixTimestamp` without `vector_index` | `ARRAY` of the element type, with at most `milvus.max_capacity` elements. The default and the maximum are 4096 | the same | +| `Json` and `Array(Json)` | `JSON` | the same | | Every other type, including `Map` and `Struct` | `VARCHAR` holding the serialized value | the same | Filters apply to `VARCHAR` and native columns. A column that holds a serialized value can be read @@ -256,9 +256,10 @@ value comes back as the JSON text of the stored document, so its formatting is n typed lists. `JSON` and `ARRAY` columns are nullable unless the field has `milvus.nullable: "false"`. {% hint style="warning" %} -`enable_openai_compatible_store` only applies when Feast creates a collection. Feast detects the -column types of an existing collection, so reads and writes keep working whichever way it was -created. `feast teardown` drops the collections of every feature view in the project, online reads +Column types only apply when Feast creates a collection. A collection that an older Feast version +created keeps its `VARCHAR` columns, and Feast detects the column types of each collection, so +reads and writes keep working whichever way it was created. To get the new columns for an existing +feature view, recreate its collection: `feast teardown` drops the collections of every feature view in the project, online reads fail until materialization finishes, and rows that exist only in the online store are lost. To migrate without a teardown, add a copy of the feature view under a new name, materialize it, move readers to it, then remove the old view. @@ -299,7 +300,7 @@ Field( `STL_SORT`, `Trie` or `AUTOINDEX`, and `milvus.index_params` passes a JSON object of parameters. `milvus.json_indexes` is a JSON list of index definitions for paths of a `JSON` column, each with a `json_path`, a `json_cast_type` and an optional `index_type` that defaults to `INVERTED`. It needs -native types and a Milvus server with JSON path indexes. Vector indexes come from `index_type` and +a Milvus server with JSON path indexes. Vector indexes come from `index_type` and `index_params` in the store config. Indexes only apply when Feast creates a collection. For an existing collection without them, Feast diff --git a/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py b/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py index 2235feeed08..e2fcd5cabf3 100644 --- a/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py +++ b/sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py @@ -117,11 +117,11 @@ DataType.BOOL, } MILVUS_VECTOR_TYPES = {DataType.FLOAT_VECTOR, DataType.BINARY_VECTOR} -# Feast types stored as a JSON column when native types are enabled. Map and +# Feast types stored as a JSON column. Map and # Struct stay serialized: JSON cannot hold their nested bytes, timestamps or # empty typed lists. _JSON_VALUE_TYPES = {ValueType.JSON, ValueType.JSON_LIST} -# Element types of an ARRAY column when native types are enabled. +# Element types of an ARRAY column. _ARRAY_ELEMENT_TYPES: Dict[Any, DataType] = { PrimitiveFeastType.STRING: DataType.VARCHAR, PrimitiveFeastType.BOOL: DataType.BOOL, @@ -1318,36 +1318,37 @@ def _milvus_field_type(field: Field) -> DataType: def _column_spec( - field: Field, native: bool, varchar_max_length: int, embedding_dim: Optional[int] + field: Field, + native_numerics: bool, + varchar_max_length: int, + embedding_dim: Optional[int], ) -> Dict[str, Any]: """The FieldSchema arguments of a feature's column. - A ``vector_index`` field is a vector. With native types, scalars get their - own type, arrays of scalars become ARRAY and Json, Map and Struct values - become JSON. Everything else is VARCHAR: text, base64 bytes or a - serialized value. + A ``vector_index`` field is a vector, an array of scalars is an ARRAY and a + Json value is JSON. A numeric is native when ``native_numerics`` is set. + Everything else is VARCHAR: text, base64 bytes or a serialized value. """ dtype = _milvus_field_type(field) if dtype in MILVUS_VECTOR_TYPES: return {"dtype": dtype, "dim": field.vector_length or embedding_dim} max_length = _max_length_tag(field, varchar_max_length) - if native: - if from_feast_type(field.dtype) in _JSON_VALUE_TYPES: - return {"dtype": DataType.JSON, "nullable": True} - if isinstance(field.dtype, Array): - element = _ARRAY_ELEMENT_TYPES.get(field.dtype.base_type) - if element is not None: - spec: Dict[str, Any] = { - "dtype": DataType.ARRAY, - "element_type": element, - "max_capacity": _max_capacity_tag(field), - "nullable": True, - } - if element == DataType.VARCHAR: - spec["max_length"] = max_length - return spec - elif dtype in MILVUS_NATIVE_NUMERIC_TYPES: - return {"dtype": dtype} + if from_feast_type(field.dtype) in _JSON_VALUE_TYPES: + return {"dtype": DataType.JSON, "nullable": True} + if isinstance(field.dtype, Array): + element = _ARRAY_ELEMENT_TYPES.get(field.dtype.base_type) + if element is not None: + spec: Dict[str, Any] = { + "dtype": DataType.ARRAY, + "element_type": element, + "max_capacity": _max_capacity_tag(field), + "nullable": True, + } + if element == DataType.VARCHAR: + spec["max_length"] = max_length + return spec + elif native_numerics and dtype in MILVUS_NATIVE_NUMERIC_TYPES: + return {"dtype": dtype} return {"dtype": DataType.VARCHAR, "max_length": max_length} diff --git a/sdk/python/tests/integration/online_store/test_milvus_remote.py b/sdk/python/tests/integration/online_store/test_milvus_remote.py index 82cbbc30eb8..6274e1e674c 100644 --- a/sdk/python/tests/integration/online_store/test_milvus_remote.py +++ b/sdk/python/tests/integration/online_store/test_milvus_remote.py @@ -587,7 +587,6 @@ def test_native_complex_types_filters_and_tag_indexes( config = _repo_config( tmp_path, project, - enable_openai_compatible_store=True, consistency_level="Strong", ) fv = FeatureView( diff --git a/sdk/python/tests/unit/infra/online_store/test_milvus_online_store.py b/sdk/python/tests/unit/infra/online_store/test_milvus_online_store.py index 5e06c530da0..4375f985497 100644 --- a/sdk/python/tests/unit/infra/online_store/test_milvus_online_store.py +++ b/sdk/python/tests/unit/infra/online_store/test_milvus_online_store.py @@ -1040,7 +1040,7 @@ def test_column_types_follow_vector_index_and_vector_length( ) for native, seen_at_type, history_type in [ - (False, DataType.VARCHAR, DataType.VARCHAR), + (False, DataType.VARCHAR, DataType.ARRAY), (True, DataType.INT64, DataType.ARRAY), ]: MilvusOnlineStore()._get_or_create_collection( @@ -1243,10 +1243,6 @@ def test_bool_array_cannot_be_a_vector_field(mock_client_cls: MagicMock) -> None mock_client.create_collection.assert_not_called() -def _native_config(tmp_path: Path, **online_store: Any) -> RepoConfig: - return _lite_config(tmp_path, enable_openai_compatible_store=True, **online_store) - - @patch(f"{MILVUS_MODULE}.MilvusClient") def test_native_types_get_json_and_array_columns(mock_client_cls: MagicMock) -> None: mock_client = _mock_client(mock_client_cls, has_collection=False) @@ -1264,9 +1260,7 @@ def test_native_types_get_json_and_array_columns(mock_client_cls: MagicMock) -> ], ) - MilvusOnlineStore()._get_or_create_collection( - _mock_config(enable_openai_compatible_store=True), fv - ) + MilvusOnlineStore()._get_or_create_collection(_mock_config(), fv) fields = { field.name: field.to_dict() @@ -1312,7 +1306,7 @@ def test_native_types_get_json_and_array_columns(mock_client_cls: MagicMock) -> def test_native_complex_values_round_trip(tmp_path: Path) -> None: - config = _native_config(tmp_path) + config = _lite_config(tmp_path) store = MilvusOnlineStore() for index, (dtype, value) in enumerate(_NATIVE_COMPLEX_VALUES): @@ -1364,7 +1358,7 @@ def _product_rows() -> Dict[int, Dict[str, ValueProto]]: def test_filters_address_json_paths_and_array_elements(tmp_path: Path) -> None: - config = _native_config(tmp_path) + config = _lite_config(tmp_path) fv = _attributes_feature_view() store = MilvusOnlineStore() store.update(config, [], [fv], [], [], partial=False) @@ -1425,9 +1419,7 @@ def test_index_tags_create_scalar_and_json_path_indexes( } ) - MilvusOnlineStore()._get_or_create_collection( - _mock_config(enable_openai_compatible_store=True), fv - ) + MilvusOnlineStore()._get_or_create_collection(_mock_config(), fv) created = _created_indexes(mock_client) assert created["brand"]["index_type"] == "INVERTED" @@ -1462,7 +1454,7 @@ def test_index_tags_create_scalar_and_json_path_indexes( dtype=String, tags={"milvus.json_indexes": '[{"json_path": "brand"}]'}, ), - {"enable_openai_compatible_store": True}, + {}, "not stored as JSON", ), ( @@ -1477,7 +1469,7 @@ def test_index_tags_create_scalar_and_json_path_indexes( ), ( Field(name="tags", dtype=Array(String), tags={"milvus.max_capacity": "0"}), - {"enable_openai_compatible_store": True}, + {}, "milvus.max_capacity tag must be", ), ], @@ -1535,7 +1527,7 @@ def test_missing_tag_indexes_on_an_existing_collection_are_logged( def test_json_null_reads_as_missing_and_json_scalars_are_rejected( tmp_path: Path, ) -> None: - config = _native_config(tmp_path) + config = _lite_config(tmp_path) fv = _typed_feature_view("documents", Json) store = MilvusOnlineStore() store.update(config, [], [fv], [], [], partial=False) @@ -1556,7 +1548,7 @@ def test_json_null_reads_as_missing_and_json_scalars_are_rejected( def test_a_json_column_that_cannot_be_null_rejects_a_missing_value( tmp_path: Path, ) -> None: - config = _native_config(tmp_path) + config = _lite_config(tmp_path) fv = _typed_feature_view("documents", Json, tags={"milvus.nullable": "false"}) store = MilvusOnlineStore() store.update(config, [], [fv], [], [], partial=False)