Skip to content

Commit

Permalink
add backward compatibility test for on-disk format of vector index
Browse files Browse the repository at this point in the history
  • Loading branch information
sivukhin committed Nov 24, 2024
1 parent b11c0c5 commit 963256b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
5 changes: 4 additions & 1 deletion libsql-sqlite3/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ libsql.pc
/sqlite3session.h
tclsqlite.lo
tclsqlite.o
testdir/

testdir/*
!testdir/libsql_vector_index_v2.db

tsrc/
dbhash
fuzzcheck
Expand Down
29 changes: 29 additions & 0 deletions libsql-sqlite3/test/libsql_vector_index.test
Original file line number Diff line number Diff line change
Expand Up @@ -531,3 +531,32 @@ do_execsql_test vector-index-attach-query {
ATTACH DATABASE 'test2.db' AS t;
SELECT * FROM vector_top_k('t.t_attach_idx', vector('[3,4,5]'), 4);
} {3 4 2 1}

# v2.db created with simple command (with LibSQL built from commit 4a5f373a298cc751d9ca56662eaaf879eefff279):
# ./sqlite3 v2.db --cmd "CREATE TABLE t (id TEXT, e FLOAT32(4)); CREATE INDEX t_idx ON t (libsql_vector_idx(e)); INSERT INTO t VALUES ('a', vector32('[1,2,3,4]')), ('b', vector32('[-100,-100,-100,-100]')), ('c', vector32('[10,10,-10,-10]')), ('d', vector32('[-1,2,3,4]'))"
sqlite3 dbv2 libsql_vector_index_v2.db

# select version and check that it equals to 2
do_test vector-index-v2-read {
execsql { SELECT substr(hex(metadata), 0, 18) FROM libsql_vector_meta_shadow WHERE name = 't_idx'; } dbv2
} {01020000000000000}

do_test vector-index-v2-read {
execsql { SELECT vector_extract(e) FROM t; } dbv2
} {{[1,2,3,4]} {[-100,-100,-100,-100]} {[10,10,-10,-10]} {[-1,2,3,4]}}

do_test vector-index-v2-query-1 {
execsql { SELECT t.id FROM vector_top_k('t_idx', vector('[1,1,1,1]'), 3) i INNER JOIN t ON t.rowid = i.id; } dbv2
} {a d c}

do_test vector-index-v2-query-2 {
execsql { SELECT t.id FROM vector_top_k('t_idx', vector('[-1,-1,-1,-1]'), 3) i INNER JOIN t ON t.rowid = i.id; } dbv2
} {b c d}

do_test vector-index-v2-query-3 {
execsql { SELECT t.id FROM vector_top_k('t_idx', vector('[1,1,-1,-1]'), 3) i INNER JOIN t ON t.rowid = i.id; } dbv2
} {c b a}

do_test vector-index-v2-query-4 {
execsql { SELECT t.id FROM vector_top_k('t_idx', vector('[-1,1,1,1]'), 3) i INNER JOIN t ON t.rowid = i.id; } dbv2
} {d a c}
Binary file not shown.

0 comments on commit 963256b

Please sign in to comment.