Skip to content

Commit

Permalink
sparse to accept list of single row scipy.sparse object as input for …
Browse files Browse the repository at this point in the history
…insert/search

Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian committed Jun 4, 2024
1 parent 02fa0f8 commit fdf595c
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions pymilvus/client/entity_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def is_float_type(v: Any):
if len(entity) == 0:
return False
for item in entity:
if SciPyHelper.is_scipy_sparse(item):
return item.shape[0] == 1
pairs = item.items() if isinstance(item, dict) else item
# each row must be a non-empty list of Tuple[int, float]
if len(pairs) == 0:
Expand Down Expand Up @@ -103,14 +105,22 @@ def sparse_float_row_to_bytes(indices: Iterable[int], values: Iterable[float]):
else:
dim = 0
for _, row_data in enumerate(data):
indices = []
values = []
row = row_data.items() if isinstance(row_data, dict) else row_data
for index, value in row:
indices.append(int(index))
values.append(float(value))
result.contents.append(sparse_float_row_to_bytes(indices, values))
dim = max(dim, indices[-1] + 1)
if SciPyHelper.is_scipy_sparse(row_data):
if row_data.shape[0] != 1:
raise ParamError(message="invalid input for sparse float vector: expect 1 row")
dim = max(dim, row_data.shape[1])
result.contents.append(
sparse_float_row_to_bytes(row_data.indices, row_data.data)
)
else:
indices = []
values = []
row = row_data.items() if isinstance(row_data, dict) else row_data
for index, value in row:
indices.append(int(index))
values.append(float(value))
result.contents.append(sparse_float_row_to_bytes(indices, values))
dim = max(dim, indices[-1] + 1)
result.dim = dim
return result

Expand Down

0 comments on commit fdf595c

Please sign in to comment.