Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions docs/reference/online-stores/milvus.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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",
),
(
Expand All @@ -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",
),
],
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Loading