Skip to content

Commit 111eae3

Browse files
[Backport 2.6] support warmup type params for fieldschema (#3255) (#3256)
Backport of #3255 to `2.6`. Signed-off-by: chasingegg <chao.gao@zilliz.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Gao <chao.gao@zilliz.com>
1 parent 7e634e6 commit 111eae3

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

pymilvus/orm/schema.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ def add_field(self, field_name: str, datatype: DataType, **kwargs):
424424
if "mmap_enabled" in kwargs:
425425
struct_schema._type_params["mmap_enabled"] = kwargs["mmap_enabled"]
426426

427+
if "warmup" in kwargs:
428+
struct_schema._type_params["warmup"] = kwargs["warmup"]
429+
427430
self._struct_fields.append(struct_schema)
428431
return self
429432

@@ -489,6 +492,9 @@ def __init__(self, name: str, dtype: DataType, description: str = "", **kwargs)
489492
if "mmap_enabled" in kwargs:
490493
self._type_params["mmap_enabled"] = kwargs["mmap_enabled"]
491494

495+
if "warmup" in kwargs:
496+
self._type_params["warmup"] = kwargs["warmup"]
497+
492498
for key in ["analyzer_params", "multi_analyzer_params"]:
493499
if key in self._kwargs and isinstance(self._kwargs[key], dict):
494500
self._kwargs[key] = orjson.dumps(self._kwargs[key]).decode(Config.EncodeProtocol)

tests/orm/test_schema.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,16 @@ def test_mmap_enabled_param(self):
375375
field = FieldSchema("vec", DataType.FLOAT_VECTOR, dim=128, mmap_enabled=True)
376376
assert field._type_params.get("mmap_enabled") is True
377377

378+
def test_warmup_param(self):
379+
"""Test warmup type param."""
380+
field = FieldSchema("vec", DataType.FLOAT_VECTOR, dim=128, warmup=True)
381+
assert field._type_params.get("warmup") is True
382+
383+
def test_warmup_param_false(self):
384+
"""Test warmup type param with False value."""
385+
field = FieldSchema("vec", DataType.FLOAT_VECTOR, dim=128, warmup=False)
386+
assert field._type_params.get("warmup") is False
387+
378388
def test_analyzer_params_dict(self):
379389
"""Test analyzer_params as dict gets serialized."""
380390
field = FieldSchema(
@@ -658,6 +668,27 @@ def test_add_struct_field_with_mmap(self):
658668
assert len(schema.struct_fields) == 1
659669
assert schema.struct_fields[0]._type_params.get("mmap_enabled") is True
660670

671+
def test_add_struct_field_with_warmup(self):
672+
"""Test adding struct field with warmup."""
673+
struct = StructFieldSchema()
674+
struct.add_field("score", DataType.FLOAT)
675+
schema = CollectionSchema(
676+
[
677+
FieldSchema("id", DataType.INT64, is_primary=True),
678+
FieldSchema("vec", DataType.FLOAT_VECTOR, dim=128),
679+
]
680+
)
681+
schema.add_field(
682+
"struct",
683+
DataType.ARRAY,
684+
element_type=DataType.STRUCT,
685+
struct_schema=struct,
686+
max_capacity=10,
687+
warmup=True,
688+
)
689+
assert len(schema.struct_fields) == 1
690+
assert schema.struct_fields[0]._type_params.get("warmup") is True
691+
661692

662693
class TestCollectionSchemaToDict:
663694
"""Tests for CollectionSchema to_dict and construct_from_dict methods."""

tests/test_client_abstract.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,28 @@ def test_field_schema_with_mmap_disabled(self):
156156

157157
assert field.params["mmap_enabled"] is False
158158

159+
def test_field_schema_with_warmup_enabled(self):
160+
"""Test FieldSchema with warmup type parameter."""
161+
warmup_param = MagicMock()
162+
warmup_param.key = "warmup"
163+
warmup_param.value = "true"
164+
165+
raw = self._create_mock_raw_field(type_params=[warmup_param])
166+
field = FieldSchema(raw)
167+
168+
assert field.params["warmup"] == "true"
169+
170+
def test_field_schema_with_warmup_disabled(self):
171+
"""Test FieldSchema with warmup set to false."""
172+
warmup_param = MagicMock()
173+
warmup_param.key = "warmup"
174+
warmup_param.value = "false"
175+
176+
raw = self._create_mock_raw_field(type_params=[warmup_param])
177+
field = FieldSchema(raw)
178+
179+
assert field.params["warmup"] == "false"
180+
159181
def test_field_schema_with_json_params(self):
160182
"""Test FieldSchema with JSON type params."""
161183
params_param = MagicMock()

0 commit comments

Comments
 (0)