Skip to content

Commit

Permalink
fix: Remove np.view for floatvector (#2048)
Browse files Browse the repository at this point in the history
Signed-off-by: yangxuan <[email protected]>
  • Loading branch information
XuanYang-cn authored Apr 23, 2024
1 parent 59bf5e8 commit 1a741d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion examples/hello_milvus.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,18 @@
# provide the pk field because `auto_id` is set to False
[str(i) for i in range(num_entities)],
rng.random(num_entities).tolist(), # field random, only supports list
rng.random((num_entities, dim)), # field embeddings, supports numpy.ndarray and list
rng.random((num_entities, dim), np.float32), # field embeddings, supports numpy.ndarray and list
]

insert_result = hello_milvus.insert(entities)

row = {
"pk": "19530",
"random": 0.5,
"embeddings": rng.random((1, dim), np.float32)[0]
}
hello_milvus.insert(row)

hello_milvus.flush()
print(f"Number of entities in Milvus: {hello_milvus.num_entities}") # check the num_entities

Expand Down
2 changes: 1 addition & 1 deletion pymilvus/client/entity_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ def pack_field_value_to_field_data(
raise ParamError(
message="invalid input for float32 vector, expect np.ndarray with dtype=float32"
)
f_value = field_value.view(np.float32).tolist()
f_value = field_value.tolist()

field_data.vectors.dim = len(f_value)
field_data.vectors.float_vector.data.extend(f_value)
Expand Down
2 changes: 1 addition & 1 deletion pymilvus/orm/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def prepare_insert_data(
field.name, "np.float32/np.float64", f_data.dtype
)
)
d = f_data.view(np.float32).tolist()
d = f_data.tolist()

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

0 comments on commit 1a741d1

Please sign in to comment.