Skip to content

Commit

Permalink
sparse float vector: do not infer empty list or list with empty rows(…
Browse files Browse the repository at this point in the history
…row with 0 non-zero value) as sparse vector input (#1973)

Signed-off-by: Buqian Zheng <[email protected]>
  • Loading branch information
zhengbuqian authored Mar 18, 2024
1 parent 0fd83fb commit 3e77421
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pymilvus/client/entity_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,13 @@ def is_float_type(v: Any):
return isinstance(v, (float, np.floating)) or is_type_in_str(v, float)

# must be of multiple rows
if len(entity) == 0:
return False
for item in entity:
pairs = item.items() if isinstance(item, dict) else item
# each row must be a list of Tuple[int, float]
# each row must be a non-empty list of Tuple[int, float]
if len(pairs) == 0:
return False
for pair in pairs:
if len(pair) != 2 or not is_int_type(pair[0]) or not is_float_type(pair[1]):
return False
Expand Down Expand Up @@ -158,6 +162,9 @@ def unify_sparse_input(data: SparseMatrixInputType) -> sparse.csr_array:
values.extend([float(value) if isinstance(value, str) else value for _, value in row])
return sparse.csr_array((values, (row_indices, col_indices)))

if not entity_is_sparse_matrix(data):
msg = "input must be a sparse matrix in supported format"
raise TypeError(msg)
csr = unify_sparse_input(data)
result = schema_types.SparseFloatArray()
result.dim = csr.shape[1]
Expand Down

0 comments on commit 3e77421

Please sign in to comment.