diff --git a/libsql-sqlite3/.gitignore b/libsql-sqlite3/.gitignore index cdc89aec26..9ca28ced7a 100644 --- a/libsql-sqlite3/.gitignore +++ b/libsql-sqlite3/.gitignore @@ -41,7 +41,10 @@ libsql.pc /sqlite3session.h tclsqlite.lo tclsqlite.o -testdir/ + +testdir/* +!testdir/libsql_vector_index_v2.db + tsrc/ dbhash fuzzcheck diff --git a/libsql-sqlite3/test/libsql_vector_index.test b/libsql-sqlite3/test/libsql_vector_index.test index c7c7a9dfa8..58136f1435 100644 --- a/libsql-sqlite3/test/libsql_vector_index.test +++ b/libsql-sqlite3/test/libsql_vector_index.test @@ -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} diff --git a/libsql-sqlite3/testdir/libsql_vector_index_v2.db b/libsql-sqlite3/testdir/libsql_vector_index_v2.db new file mode 100644 index 0000000000..e64078ed87 Binary files /dev/null and b/libsql-sqlite3/testdir/libsql_vector_index_v2.db differ