mirror of
https://github.com/asg017/sqlite-vec.git
synced 2026-04-25 00:36:56 +02:00
Replace the old INSERT INTO t(rowid) VALUES('command') hack with a
proper hidden command column named after the table (FTS5 pattern):
INSERT INTO t(t) VALUES ('oversample=16')
The command column is the first hidden column (before distance and k)
to reserve ability for future table-valued function argument use.
Schema: CREATE TABLE x(rowid, <cols>, "<table>" hidden, distance hidden, k hidden)
For backwards compat, pre-v0.1.10 tables (detected via _info shadow
table version) skip the command column to avoid name conflicts with
user columns that may share the table's name. Verified with legacy
fixture DB generated by sqlite-vec v0.1.6.
Changes:
- Add hidden command column to sqlite3_declare_vtab for new tables
- Version-gate via _info shadow table for existing tables
- Validate at CREATE time that no column name matches table name
- Add rescore_handle_command() with oversample=N support
- rescore_knn() prefers runtime oversample_search over CREATE default
- Remove old rowid-based command dispatch
- Migrate all DiskANN/IVF/fuzz tests and benchmarks to new syntax
- Add legacy DB fixture (v0.1.6) and 9 backwards-compat tests
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
41 lines
1.4 KiB
Python
41 lines
1.4 KiB
Python
import sqlite3
|
|
import pytest
|
|
from helpers import exec
|
|
|
|
|
|
@pytest.mark.skipif(
|
|
sqlite3.sqlite_version_info[1] < 37,
|
|
reason="pragma_table_list was added in SQLite 3.37",
|
|
)
|
|
def test_shadow(db, snapshot):
|
|
db.execute(
|
|
"create virtual table v using vec0(a float[1], partition text partition key, metadata text, +name text, chunk_size=8)"
|
|
)
|
|
assert exec(db, "select * from sqlite_master order by name") == snapshot()
|
|
assert (
|
|
exec(db, "select * from pragma_table_list where type = 'shadow' order by name") == snapshot()
|
|
)
|
|
|
|
db.execute("drop table v;")
|
|
assert (
|
|
exec(db, "select * from pragma_table_list where type = 'shadow' order by name") == snapshot()
|
|
)
|
|
|
|
|
|
def test_info(db, snapshot):
|
|
db.execute("create virtual table v using vec0(a float[1])")
|
|
assert exec(db, "select key, typeof(value) from v_info order by 1") == snapshot()
|
|
|
|
|
|
def test_command_column_name_conflict(db):
|
|
"""Table name matching a column name should error (command column conflict)."""
|
|
# This would conflict: hidden command column 'embeddings' vs vector column 'embeddings'
|
|
with pytest.raises(sqlite3.OperationalError, match="conflicts with table name"):
|
|
db.execute(
|
|
"create virtual table embeddings using vec0(embeddings float[4])"
|
|
)
|
|
|
|
# Different names should work fine
|
|
db.execute("create virtual table t using vec0(embeddings float[4])")
|
|
|
|
|