Skip to content

Fix sparse vector Map serialization with out-of-order indices - #38

Closed
mhatipog wants to merge 1 commit into
pgvector:masterfrom
mhatipog:fix/sparse-map-order-upstream
Closed

mhatipog wants to merge 1 commit into
pgvector:masterfrom
mhatipog:fix/sparse-map-order-upstream

Conversation

@mhatipog

Copy link
Copy Markdown

Problem

SparseVector preserves JavaScript Map insertion order, but PostgreSQL sparsevec requires ascending coordinate indices. For an unordered Map, the generated literal is rejected with sparsevec indices must be in ascending order.

Fix

Sort numeric coordinate/value pairs together before populating indices and values. Do not mutate the input Map. This matches Python and Go pgvector clients.

Tests

  • Update Map unit assertions for ordering, SQL output and dense values
  • Add unordered Map regression with negative/zero values and input immutability
  • Add PostgreSQL INSERT/RETURNING integration regression

Targeted Node tests passed on Repo Guardian runner; the PostgreSQL integration test is included for upstream CI.

@ankane

ankane commented Oct 27, 2026

Copy link
Copy Markdown
Member

Hi @mhatipog, the text format doesn't require this.

@ankane ankane closed this Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants