Skip to content

Commit 3306473

Browse files
pymilvus-botjac0626silas.jiang
authored
[Backport 2.6] fix: extend protobuf after flush vector cache (#3200) (#3201)
Backport of #3200 to `2.6`. Signed-off-by: silas.jiang <silas.jiang@zilliz.com> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: jac <jacllovey@qq.com> Co-authored-by: silas.jiang <silas.jiang@zilliz.com>
1 parent 4e30085 commit 3306473

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pymilvus/client/prepare.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,8 +1016,6 @@ def _parse_upsert_row_request(
10161016
)
10171017

10181018
fields_data = {k: v for k, v in fields_data.items() if field_len[k] > 0}
1019-
request.fields_data.extend(fields_data.values())
1020-
10211019
# Flush all bytes vector field temporary byte lists to optimize memory usage
10221020
for field_data in fields_data.values():
10231021
if field_data.type in (
@@ -1028,6 +1026,8 @@ def _parse_upsert_row_request(
10281026
):
10291027
entity_helper.flush_vector_bytes(field_data, vector_bytes_cache)
10301028

1029+
request.fields_data.extend(fields_data.values())
1030+
10311031
if struct_fields_data:
10321032
# reconstruct the struct array fields data (same as in insert)
10331033
for struct in input_struct_field_info:

tests/test_prepare.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,35 @@ def test_batch_upsert_param_partial_update_field_count_validation_skip(self):
538538
request.fields_data) == 2, "Should only contain data for provided fields"
539539

540540

541+
542+
def test_row_upsert_param_partial_update_with_float16_vector_cached(self):
543+
"""Test that cached vector types (float16) are flushed correctly with partial_update=True"""
544+
dim = 8
545+
schema = CollectionSchema([
546+
FieldSchema("float16_vector", DataType.FLOAT16_VECTOR, dim=dim),
547+
FieldSchema("pk", DataType.INT64, is_primary=True)
548+
])
549+
550+
# simulated float16 data (numpy float16 array)
551+
vector_data = np.zeros((1, dim), dtype=np.float16)
552+
553+
rows = [
554+
{"pk": 1, "float16_vector": vector_data[0]}
555+
]
556+
557+
req = Prepare.row_upsert_param("test_collection", rows, "",
558+
fields_info=schema.to_dict()["fields"],
559+
partial_update=True)
560+
561+
vector_field_data = next((fd for fd in req.fields_data if fd.field_name == "float16_vector"), None)
562+
assert vector_field_data is not None, "Vector field 'float16_vector' not found in request"
563+
564+
# Should have data
565+
# 1 vector * 8 dim * 2 bytes = 16 bytes
566+
expected_bytes = 1 * dim * 2
567+
assert len(vector_field_data.vectors.float16_vector) == expected_bytes, f"Vector data has incorrect size! Expected {expected_bytes} bytes."
568+
569+
541570
class TestCreateIndexRequest:
542571
def test_create_index_request_with_false_boolean_param(self):
543572
"""Test that boolean False values are preserved in index parameters"""

0 commit comments

Comments
 (0)