interplane.Get Omega
Read in your language

sqlite

[Ported from github.com/sqlite/sqlite] Fix bugs in and improve the interface to the ".check" command of the CLI.

Brought by drakestapleton

branch master Branches Tags History

sqlite / ext / vec1 / test / vec1fixed.test

113 lines · 3034 bytes Raw Blame History
1# 2026-04-02
2#
3# The author disclaims copyright to this source code. In place of
4# a legal notice, here is a blessing:
5#
6# May you do good and not evil.
7# May you find forgiveness for yourself and forgive others.
8# May you share freely, never taking more than you give.
9#
10#***********************************************************************
11#
12# A vec1 table "fixes" the vector size when either:
13#
14# * the first vector is written to the table, or
15# * the table is trained by a model that specifies a vector size.
16#
17# This file contains tests of these two cases.
18#
19
20source [file join [file dirname [info script]] vec1_common.tcl]
21set testprefix vec1fixed
22vec1_load db
23
24do_execsql_test 1.0 {
25 CREATE VIRTUAL TABLE v1 USING vec1;
26}
27
28do_execsql_test 1.1 {
29 INSERT INTO v1(cmd, vector) VALUES('rebuild', (
30 WITH s(i) AS (
31 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<512
32 ) SELECT vec1_train( random_vector(128), '{nbucket:4}' ) FROM s
33 ));
34}
35
36do_catchsql_test 1.2 {
37 INSERT INTO v1 VALUES(random_vector(127));
38} {1 {vec1: unexpected vector blob size 508 bytes, expected 512}}
39
40do_catchsql_test 1.3 {
41 INSERT INTO v1(cmd, vector) VALUES('rebuild', (
42 WITH s(i) AS (
43 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<512
44 ) SELECT vec1_train( random_vector(64), '{codesize:16}' ) FROM s
45 ));
46} {1 {vec1: model/data vector size mismatch: 64/128}}
47
48do_catchsql_test 1.4 {
49 SELECT rowid FROM v1(random_vector(129))
50} {1 {vec1: unexpected vector blob size 516 bytes, expected 512}}
51
52#-------------------------------------------------------------------------
53# Similar to tests 1.*, except fix the vector size by inserting a row.
54#
55reset_db
56vec1_load db
57
58do_execsql_test 2.0 {
59 CREATE VIRTUAL TABLE v1 USING vec1;
60}
61
62do_execsql_test 2.1 {
63 INSERT INTO v1 VALUES( random_vector(128) );
64}
65
66do_catchsql_test 2.2 {
67 INSERT INTO v1 VALUES(random_vector(127));
68} {1 {vec1: unexpected vector blob size 508 bytes, expected 512}}
69
70do_catchsql_test 2.3 {
71 INSERT INTO v1(cmd, vector) VALUES('rebuild', (
72 WITH s(i) AS (
73 SELECT 1 UNION ALL SELECT i+1 FROM s WHERE i<512
74 ) SELECT vec1_train( random_vector(64), '{codesize:16}' ) FROM s
75 ));
76} {1 {vec1: model/data vector size mismatch: 64/128}}
77
78do_catchsql_test 2.4 {
79 SELECT rowid FROM v1(random_vector(129))
80} {1 {vec1: unexpected vector blob size 516 bytes, expected 512}}
81
82do_execsql_test 2.5 {
83 INSERT INTO v1 VALUES( random_vector(128) );
84}
85
86#-------------------------------------------------------------------------
87#
88reset_db
89vec1_load db
90
91do_execsql_test 3.0 {
92 CREATE VIRTUAL TABLE v1 USING vec1;
93}
94
95do_catchsql_test 3.1 {
96 INSERT INTO v1 VALUES( random_vector(1) );
97} {1 {vec1: invalid vector size: 4 bytes}}
98do_catchsql_test 3.2 {
99 INSERT INTO v1 VALUES( random_vector(4097) );
100} {1 {vec1: invalid vector size: 16388 bytes}}
101do_catchsql_test 3.3 {
102 INSERT INTO v1 VALUES( randomblob(207) );
103} {1 {vec1: invalid vector size: 207 bytes}}
104
105
106
107do_execsql_test 3.4 {
108 INSERT INTO v1 VALUES( random_vector(4096) );
109}
110
111
112finish_test
113