Conversation
`tocoo()` returns coordinates in whatever order the source array holds them, so a coo_array built from unordered triplets produced a SparseVector whose indices descend. `sparsevec_recv` rejects that with "sparsevec indices must be in ascending order", which is the error an asyncpg or psycopg user sees on insert, and `_from_dict` already sorts for the same reason.
Member
|
Thanks @chrikrah, merged a version of this in the commit above. |
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.
_from_sparsenow sorts the index/value pairs before assigning them, the way_from_dictatpgvector/sparsevec.py:97already does. SciPy promises no coordinate order for acoo_array, and the constructor accepts any legal one, so unordered triplets reach the wire descending and the binary codec refuses them. The only signal a user gets is a PostgresDataExceptionat insert time, a long way from the constructor that caused it. asyncpg has no text path, and psycopg's%sresolves to the binary dumper.Before, against pgvector 0.8.7 on PostgreSQL 17:
After, same command against the same container:
No issue in the tracker covers it, so there is no closing keyword.
Verification
Baseline on
99a6776over the same six files is95 passed, so the delta istest_coo_array_unordered. Keeping that test and restoring the old_from_sparsegives1 failed, 95 passed, onassert [4, 0, 2] == [0, 2, 4].@ankane,
2cff2f8went the other way on allocation here, so I held this to the two lines_from_dictuses. Duplicate coordinates are the other half of a non-canonical COO and this patch leaves them alone: say the word and I will swap both forsum_duplicates()on a copy, guarded byhas_canonical_format, which costs an ordered array nothing.