Skip to content

Commit 2575e2a

Browse files
jiwidintkathole
authored andcommitted
feat: Store arrays and Json natively for every new collection
ARRAY and JSON columns are independent of enable_openai_compatible_store. Every new collection gets them. A collection that an older Feast version created keeps its VARCHAR columns, and the column types of each collection decide how a row is written and read. Signed-off-by: jiwidi <fhjaime96@gmail.com>
1 parent fb5e5d5 commit 2575e2a

4 files changed

Lines changed: 42 additions & 49 deletions

File tree

‎docs/reference/online-stores/milvus.md‎

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ online_store:
101101
| `partition_key_isolation` | unset | Enables partition key isolation on a new collection that has a partition key. When unset, Milvus uses its default. |
102102
| `vector_enabled` | `true` | Enables vector search. |
103103
| `varchar_max_length` | `65535` | Default `max_length` of VARCHAR fields. Override per field with the `max_length` tag. |
104-
| `enable_openai_compatible_store` | `false` | Store numeric, array, `Json`, `Map` and `Struct` features as native Milvus types. See [Field types](#field-types). |
104+
| `enable_openai_compatible_store` | `false` | Store numeric features as native Milvus numeric types. |
105105

106106
The full set of configuration options is available in [MilvusOnlineStoreConfig](https://rtd.feast.dev/en/latest/#feast.infra.online_stores.milvus.MilvusOnlineStoreConfig).
107107

@@ -237,8 +237,8 @@ type.
237237
| `UnixTimestamp` | `VARCHAR` holding the seconds as text | `INT64` |
238238
| `Bytes` | `VARCHAR` holding base64 | `VARCHAR` holding base64 |
239239
| `Array` with `vector_index=True` | `FLOAT_VECTOR` with the field's `vector_length`, or `embedding_dim` when it is unset | the same |
240-
| `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 |
241-
| `Json` and `Array(Json)` | `VARCHAR` holding the serialized value | `JSON` |
240+
| `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 |
241+
| `Json` and `Array(Json)` | `JSON` | the same |
242242
| Every other type, including `Map` and `Struct` | `VARCHAR` holding the serialized value | the same |
243243

244244
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
256256
typed lists. `JSON` and `ARRAY` columns are nullable unless the field has `milvus.nullable: "false"`.
257257
258258
{% hint style="warning" %}
259-
`enable_openai_compatible_store` only applies when Feast creates a collection. Feast detects the
260-
column types of an existing collection, so reads and writes keep working whichever way it was
261-
created. `feast teardown` drops the collections of every feature view in the project, online reads
259+
Column types only apply when Feast creates a collection. A collection that an older Feast version
260+
created keeps its `VARCHAR` columns, and Feast detects the column types of each collection, so
261+
reads and writes keep working whichever way it was created. To get the new columns for an existing
262+
feature view, recreate its collection: `feast teardown` drops the collections of every feature view in the project, online reads
262263
fail until materialization finishes, and rows that exist only in the online store are lost. To
263264
migrate without a teardown, add a copy of the feature view under a new name, materialize it, move
264265
readers to it, then remove the old view.
@@ -299,7 +300,7 @@ Field(
299300
`STL_SORT`, `Trie` or `AUTOINDEX`, and `milvus.index_params` passes a JSON object of parameters.
300301
`milvus.json_indexes` is a JSON list of index definitions for paths of a `JSON` column, each with a
301302
`json_path`, a `json_cast_type` and an optional `index_type` that defaults to `INVERTED`. It needs
302-
native types and a Milvus server with JSON path indexes. Vector indexes come from `index_type` and
303+
a Milvus server with JSON path indexes. Vector indexes come from `index_type` and
303304
`index_params` in the store config.
304305

305306
Indexes only apply when Feast creates a collection. For an existing collection without them, Feast

‎sdk/python/feast/infra/online_stores/milvus_online_store/milvus.py‎

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,11 @@
117117
DataType.BOOL,
118118
}
119119
MILVUS_VECTOR_TYPES = {DataType.FLOAT_VECTOR, DataType.BINARY_VECTOR}
120-
# Feast types stored as a JSON column when native types are enabled. Map and
120+
# Feast types stored as a JSON column. Map and
121121
# Struct stay serialized: JSON cannot hold their nested bytes, timestamps or
122122
# empty typed lists.
123123
_JSON_VALUE_TYPES = {ValueType.JSON, ValueType.JSON_LIST}
124-
# Element types of an ARRAY column when native types are enabled.
124+
# Element types of an ARRAY column.
125125
_ARRAY_ELEMENT_TYPES: Dict[Any, DataType] = {
126126
PrimitiveFeastType.STRING: DataType.VARCHAR,
127127
PrimitiveFeastType.BOOL: DataType.BOOL,
@@ -1318,36 +1318,37 @@ def _milvus_field_type(field: Field) -> DataType:
13181318

13191319

13201320
def _column_spec(
1321-
field: Field, native: bool, varchar_max_length: int, embedding_dim: Optional[int]
1321+
field: Field,
1322+
native_numerics: bool,
1323+
varchar_max_length: int,
1324+
embedding_dim: Optional[int],
13221325
) -> Dict[str, Any]:
13231326
"""The FieldSchema arguments of a feature's column.
13241327
1325-
A ``vector_index`` field is a vector. With native types, scalars get their
1326-
own type, arrays of scalars become ARRAY and Json, Map and Struct values
1327-
become JSON. Everything else is VARCHAR: text, base64 bytes or a
1328-
serialized value.
1328+
A ``vector_index`` field is a vector, an array of scalars is an ARRAY and a
1329+
Json value is JSON. A numeric is native when ``native_numerics`` is set.
1330+
Everything else is VARCHAR: text, base64 bytes or a serialized value.
13291331
"""
13301332
dtype = _milvus_field_type(field)
13311333
if dtype in MILVUS_VECTOR_TYPES:
13321334
return {"dtype": dtype, "dim": field.vector_length or embedding_dim}
13331335
max_length = _max_length_tag(field, varchar_max_length)
1334-
if native:
1335-
if from_feast_type(field.dtype) in _JSON_VALUE_TYPES:
1336-
return {"dtype": DataType.JSON, "nullable": True}
1337-
if isinstance(field.dtype, Array):
1338-
element = _ARRAY_ELEMENT_TYPES.get(field.dtype.base_type)
1339-
if element is not None:
1340-
spec: Dict[str, Any] = {
1341-
"dtype": DataType.ARRAY,
1342-
"element_type": element,
1343-
"max_capacity": _max_capacity_tag(field),
1344-
"nullable": True,
1345-
}
1346-
if element == DataType.VARCHAR:
1347-
spec["max_length"] = max_length
1348-
return spec
1349-
elif dtype in MILVUS_NATIVE_NUMERIC_TYPES:
1350-
return {"dtype": dtype}
1336+
if from_feast_type(field.dtype) in _JSON_VALUE_TYPES:
1337+
return {"dtype": DataType.JSON, "nullable": True}
1338+
if isinstance(field.dtype, Array):
1339+
element = _ARRAY_ELEMENT_TYPES.get(field.dtype.base_type)
1340+
if element is not None:
1341+
spec: Dict[str, Any] = {
1342+
"dtype": DataType.ARRAY,
1343+
"element_type": element,
1344+
"max_capacity": _max_capacity_tag(field),
1345+
"nullable": True,
1346+
}
1347+
if element == DataType.VARCHAR:
1348+
spec["max_length"] = max_length
1349+
return spec
1350+
elif native_numerics and dtype in MILVUS_NATIVE_NUMERIC_TYPES:
1351+
return {"dtype": dtype}
13511352
return {"dtype": DataType.VARCHAR, "max_length": max_length}
13521353

13531354

‎sdk/python/tests/integration/online_store/test_milvus_remote.py‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,6 @@ def test_native_complex_types_filters_and_tag_indexes(
587587
config = _repo_config(
588588
tmp_path,
589589
project,
590-
enable_openai_compatible_store=True,
591590
consistency_level="Strong",
592591
)
593592
fv = FeatureView(

‎sdk/python/tests/unit/infra/online_store/test_milvus_online_store.py‎

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ def test_column_types_follow_vector_index_and_vector_length(
10401040
)
10411041

10421042
for native, seen_at_type, history_type in [
1043-
(False, DataType.VARCHAR, DataType.VARCHAR),
1043+
(False, DataType.VARCHAR, DataType.ARRAY),
10441044
(True, DataType.INT64, DataType.ARRAY),
10451045
]:
10461046
MilvusOnlineStore()._get_or_create_collection(
@@ -1243,10 +1243,6 @@ def test_bool_array_cannot_be_a_vector_field(mock_client_cls: MagicMock) -> None
12431243
mock_client.create_collection.assert_not_called()
12441244

12451245

1246-
def _native_config(tmp_path: Path, **online_store: Any) -> RepoConfig:
1247-
return _lite_config(tmp_path, enable_openai_compatible_store=True, **online_store)
1248-
1249-
12501246
@patch(f"{MILVUS_MODULE}.MilvusClient")
12511247
def test_native_types_get_json_and_array_columns(mock_client_cls: MagicMock) -> None:
12521248
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) ->
12641260
],
12651261
)
12661262

1267-
MilvusOnlineStore()._get_or_create_collection(
1268-
_mock_config(enable_openai_compatible_store=True), fv
1269-
)
1263+
MilvusOnlineStore()._get_or_create_collection(_mock_config(), fv)
12701264

12711265
fields = {
12721266
field.name: field.to_dict()
@@ -1312,7 +1306,7 @@ def test_native_types_get_json_and_array_columns(mock_client_cls: MagicMock) ->
13121306

13131307

13141308
def test_native_complex_values_round_trip(tmp_path: Path) -> None:
1315-
config = _native_config(tmp_path)
1309+
config = _lite_config(tmp_path)
13161310
store = MilvusOnlineStore()
13171311

13181312
for index, (dtype, value) in enumerate(_NATIVE_COMPLEX_VALUES):
@@ -1364,7 +1358,7 @@ def _product_rows() -> Dict[int, Dict[str, ValueProto]]:
13641358

13651359

13661360
def test_filters_address_json_paths_and_array_elements(tmp_path: Path) -> None:
1367-
config = _native_config(tmp_path)
1361+
config = _lite_config(tmp_path)
13681362
fv = _attributes_feature_view()
13691363
store = MilvusOnlineStore()
13701364
store.update(config, [], [fv], [], [], partial=False)
@@ -1425,9 +1419,7 @@ def test_index_tags_create_scalar_and_json_path_indexes(
14251419
}
14261420
)
14271421

1428-
MilvusOnlineStore()._get_or_create_collection(
1429-
_mock_config(enable_openai_compatible_store=True), fv
1430-
)
1422+
MilvusOnlineStore()._get_or_create_collection(_mock_config(), fv)
14311423

14321424
created = _created_indexes(mock_client)
14331425
assert created["brand"]["index_type"] == "INVERTED"
@@ -1462,7 +1454,7 @@ def test_index_tags_create_scalar_and_json_path_indexes(
14621454
dtype=String,
14631455
tags={"milvus.json_indexes": '[{"json_path": "brand"}]'},
14641456
),
1465-
{"enable_openai_compatible_store": True},
1457+
{},
14661458
"not stored as JSON",
14671459
),
14681460
(
@@ -1477,7 +1469,7 @@ def test_index_tags_create_scalar_and_json_path_indexes(
14771469
),
14781470
(
14791471
Field(name="tags", dtype=Array(String), tags={"milvus.max_capacity": "0"}),
1480-
{"enable_openai_compatible_store": True},
1472+
{},
14811473
"milvus.max_capacity tag must be",
14821474
),
14831475
],
@@ -1535,7 +1527,7 @@ def test_missing_tag_indexes_on_an_existing_collection_are_logged(
15351527
def test_json_null_reads_as_missing_and_json_scalars_are_rejected(
15361528
tmp_path: Path,
15371529
) -> None:
1538-
config = _native_config(tmp_path)
1530+
config = _lite_config(tmp_path)
15391531
fv = _typed_feature_view("documents", Json)
15401532
store = MilvusOnlineStore()
15411533
store.update(config, [], [fv], [], [], partial=False)
@@ -1556,7 +1548,7 @@ def test_json_null_reads_as_missing_and_json_scalars_are_rejected(
15561548
def test_a_json_column_that_cannot_be_null_rejects_a_missing_value(
15571549
tmp_path: Path,
15581550
) -> None:
1559-
config = _native_config(tmp_path)
1551+
config = _lite_config(tmp_path)
15601552
fv = _typed_feature_view("documents", Json, tags={"milvus.nullable": "false"})
15611553
store = MilvusOnlineStore()
15621554
store.update(config, [], [fv], [], [], partial=False)

0 commit comments

Comments
 (0)