fix(sparse): declare SparseFloatArray dim from the max index, not the last one - #3774
Open
sainikhiljuluri wants to merge 1 commit into
Open
fix(sparse): declare SparseFloatArray dim from the max index, not the last one#3774sainikhiljuluri wants to merge 1 commit into
sainikhiljuluri wants to merge 1 commit into
Conversation
sparse_rows_to_proto() collects a dict/list sparse row's indices in input
order, then computed the array dimension as indices[-1] + 1. The byte payload
is sorted before packing, but the dim was taken from whatever index happened to
be last, so an unsorted row under-declared dim: e.g. {5: .., 2: ..} yielded
dim 3 instead of 6, and [(7,..),(1,..),(4,..)] yielded 5 instead of 8. Milvus
then sees a dim that does not cover every index in the row.
Use max(indices) + 1 (guarded by the existing len(indices) > 0 check) so the
declared dim always covers the largest index regardless of input order. The
scipy paths already derive dim from shape and are unaffected. Adds a regression
test with unsorted dict and list rows (fails on the previous code: 3 != 6).
Signed-off-by: Sainikhil Juluri <sainikhiljuluri19008@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: sainikhiljuluri The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Tick the box to add this pull request to the merge queue (same as
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
sparse_rows_to_proto()builds theSparseFloatArray.dimincorrectly for adict/list sparse row whose indices are not in ascending order.
The row's
indicesare collected in input order (entity_helper.py:154-157),and the byte payload is sorted before packing (
sparse_float_row_to_bytes), so thestored data is fine. But the dimension was taken from the last collected index:
For an unsorted row the last index is not the maximum, so
dimis under-declared:{5: 0.1, 2: 0.3}[(7, .1), (1, .2), (4, .3)]Milvus then receives a
dimthat does not cover every index present in the row.Fix
Use
max(indices) + 1(still guarded by the existinglen(indices) > 0check) sothe declared dim always covers the largest index regardless of input order. The
scipy code paths already derive
dimfromshapeand are untouched.Testing
Added
test_sparse_rows_to_proto_dim_uses_max_indexintests/unit/test_client_entity_helper.pywith an unsorted dict row and an unsortedlist row. It fails on the previous code (
assert 3 == 6) and passes with the fix.Full
tests/unit/test_client_entity_helper.py: 139 passed.ruff checkclean.