Skip to content

Reject malformed vector column types with exact-match parsing - #310

Open
stumpylog wants to merge 1 commit into
asg017:mainfrom
stumpylog:fix/strict-vector-column-type-parsing
Open

stumpylog wants to merge 1 commit into
asg017:mainfrom
stumpylog:fix/strict-vector-column-type-parsing

Conversation

@stumpylog

Copy link
Copy Markdown

The vec0 column-type parser matched element type names with a prefix-only sqlite3_strnicmp (comparing only the first N bytes against "float", "int8", "bit", etc.). Any identifier sharing a prefix with a real type was silently coerced to that type:

  • float16[768] → a 32-bit float column (silently, double the intended storage)
  • bitcoin[2] → a bit column
  • typos like floaty[2] → accepted instead of rejected

This compares the full identifier length so only exact element-type spellings parse. float32 is added as an explicit alias, since it was previously accepted via the float prefix and is a natural spelling to keep working.

This also unblocks adding real float16/bfloat16 types (#27), which would otherwise collide with the float prefix.

Testing

  • New tests/test-column-type-parse.py asserts valid spellings (float, f32, float32, int8, i8, bit) are accepted and lookalikes (float16, bitcoin, floaty, ...) are rejected.
  • Two tests in test-loadable.py that incidentally used the bogus float8[1] were corrected to float[1].
  • Full loadable suite passes.

The vec0 column-type parser matched element type names with a
prefix-only `sqlite3_strnicmp` (e.g. comparing the first 5 bytes
against "float"). Any identifier sharing a prefix with a real type
was silently coerced to that type: `float16[768]` became a 32-bit
`float` column, `bitcoin[2]` became `bit`, and typos like `floaty`
were accepted instead of erroring.

Compare the full identifier length so only exact element-type
spellings parse. `float32` is added as an explicit alias since it
was previously accepted via the `float` prefix and is a natural
spelling to keep working.

This also unblocks adding real `float16`/`bfloat16` types (asg017#27),
which would otherwise collide with the `float` prefix.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
vlasky added a commit to vlasky/sqlite-vec that referenced this pull request Nov 8, 2026
…olumn types

Ports, as they stand, three open pull requests against asg017/sqlite-vec
whose bugs reproduce on this fork:

- asg017#323 by ariannamethod: vec_each() read bit vectors most
  significant bit first, while vec_to_json(), vec_quantize_binary() and the
  stored bitmaps are least significant bit first. The API reference example
  showed the wrong order too.
- asg017#365 by flysheep-ai (upstream issue asg017#362):
  vec_distance_l1() on int8 vectors summed in 32 bits and wrapped negative
  from 8,421,505 elements at opposite extremes. The sum is now 64-bit and
  the NEON kernel is only used within its 32-bit range. vec0 columns are
  capped at 8192 dimensions and were never affected.
- asg017#310 by stumpylog: vector column types were matched by
  prefix, so float16[4], floaty[4] and bitcoin[8] were accepted as float and
  bit columns. The name must now match exactly; float32 stays accepted. Two
  tests declared a column as float8[1] and now say float[1].

Tests for the first two follow with the fork's own fixes.
@vlasky

vlasky commented Nov 9, 2026

Copy link
Copy Markdown

For anyone waiting on this: the community fork vlasky/sqlite-vec has merged this change in v0.2.9-alpha (changelog), with one addition found in review: an unknown type name followed by [ is now an error rather than falling through to the metadata parser. Without that, v float64[2] (accepted as float32 by the old prefix match) would reopen as a FLOAT metadata column and the next vector column would read the wrong shadow tables. Thanks for the fix.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants