Skip to content

Commit b1fcb5d

Browse files
authored
fix: Remove np.view for floatvector (#2049)
Signed-off-by: yangxuan <[email protected]>
1 parent 64acef6 commit b1fcb5d

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

‎examples/hello_milvus.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,18 @@
7373
# provide the pk field because `auto_id` is set to False
7474
[str(i) for i in range(num_entities)],
7575
rng.random(num_entities).tolist(), # field random, only supports list
76-
rng.random((num_entities, dim)), # field embeddings, supports numpy.ndarray and list
76+
rng.random((num_entities, dim), np.float32), # field embeddings, supports numpy.ndarray and list
7777
]
7878

7979
insert_result = hello_milvus.insert(entities)
8080

81+
row = {
82+
"pk": "19530",
83+
"random": 0.5,
84+
"embeddings": rng.random((1, dim), np.float32)[0]
85+
}
86+
hello_milvus.insert(row)
87+
8188
hello_milvus.flush()
8289
print(f"Number of entities in Milvus: {hello_milvus.num_entities}") # check the num_entities
8390

‎pymilvus/client/entity_helper.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def pack_field_value_to_field_data(
312312
raise ParamError(
313313
message="invalid input for float32 vector, expect np.ndarray with dtype=float32"
314314
)
315-
f_value = field_value.view(np.float32).tolist()
315+
f_value = field_value.tolist()
316316

317317
field_data.vectors.dim = len(f_value)
318318
field_data.vectors.float_vector.data.extend(f_value)

‎pymilvus/orm/prepare.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def prepare_insert_data(
9191
field.name, "np.float32/np.float64", f_data.dtype
9292
)
9393
)
94-
d = f_data.view(np.float32).tolist()
94+
d = f_data.tolist()
9595

9696
elif isinstance(f_data[0], np.ndarray):
9797
for ndarr in f_data:

0 commit comments

Comments
 (0)