Skip to content

Commit bd25344

Browse files
committed
add tests and refine error messages
1 parent 2e0647f commit bd25344

2 files changed

Lines changed: 17 additions & 4 deletions

File tree

libsql-sqlite3/src/vector.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,13 +954,19 @@ static void vectorDistanceFunc(
954954
goto out_free;
955955
}
956956
if( type1 != type2 ){
957-
pzErrMsg = sqlite3_mprintf("vector_distance_cos: vectors must have the same type: %d != %d", type1, type2);
957+
pzErrMsg = sqlite3_mprintf("vector_distance: vectors must have the same type: %d != %d", type1, type2);
958958
sqlite3_result_error(context, pzErrMsg, -1);
959959
sqlite3_free(pzErrMsg);
960960
goto out_free;
961961
}
962962
if( dims1 != dims2 ){
963-
pzErrMsg = sqlite3_mprintf("vector_distance_cos: vectors must have the same length: %d != %d", dims1, dims2);
963+
pzErrMsg = sqlite3_mprintf("vector_distance: vectors must have the same length: %d != %d", dims1, dims2);
964+
sqlite3_result_error(context, pzErrMsg, -1);
965+
sqlite3_free(pzErrMsg);
966+
goto out_free;
967+
}
968+
if( vectorDistance == vectorDistanceL2 && type1 == VECTOR_TYPE_FLOAT1BIT ){
969+
pzErrMsg = sqlite3_mprintf("vector_distance: l2 distance is not supported for float1bit vectors", dims1, dims2);
964970
sqlite3_result_error(context, pzErrMsg, -1);
965971
sqlite3_free(pzErrMsg);
966972
goto out_free;

libsql-sqlite3/test/libsql_vector.test

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ do_execsql_test vector-1-func-valid {
6262

6363
SELECT vector_distance_cos(vector8('[-20,-30,0,1,1.1,1.2,100]'), vector8('[-20,-30,0,1,1.1,1.2,10000]'));
6464
SELECT vector_distance_cos(vector32('[-20,-30,0,1,1.1,1.2,100]'), vector32('[-20,-30,0,1,1.1,1.2,10000]'));
65+
66+
SELECT vector_distance_l2(vector('[1,2,2,3,4,1,5]'), vector('[2,3,1,-1,2,4,5]'));
67+
SELECT vector_distance_l2(vector8('[1,2,2,3,4,1,5]'), vector8('[2,3,1,-1,2,4,5]'));
6568
} {
6669
{[]}
6770
{[]}
@@ -84,6 +87,8 @@ do_execsql_test vector-1-func-valid {
8487
{-6.10352568486405e-09} {0.0}
8588
{0.000111237335659098} {0.000117244853754528}
8689
{0.0576796568930149} {0.0582110174000263}
90+
91+
{5.65685415267944} {5.65413522720337}
8792
}
8893

8994
do_execsql_test vector-1-conversion {
@@ -158,6 +163,7 @@ do_test vector-1-func-errors {
158163
lappend ret [error_messages {SELECT vector(x'0000000000')}]
159164
lappend ret [error_messages {SELECT vector_distance_cos('[1,2,3]', '[1,2]')}]
160165
lappend ret [error_messages {SELECT vector_distance_cos(vector32('[1,2,3]'), vector64('[1,2,3]'))}]
166+
lappend ret [error_messages {SELECT vector_distance_l2(vector1bit('[1,2,2,3,4,1,5]'), vector1bit('[2,3,1,-1,2,4,5]'))}]
161167
} [list {*}{
162168
{vector: unexpected value type: got FLOAT, expected TEXT or BLOB}
163169
{vector: unexpected value type: got INTEGER, expected TEXT or BLOB}
@@ -169,6 +175,7 @@ do_test vector-1-func-errors {
169175
{vector: invalid float at position 2: '1.1.1'}
170176
{vector: must end with ']'}
171177
{vector: unexpected binary type: 0}
172-
{vector_distance_cos: vectors must have the same length: 3 != 2}
173-
{vector_distance_cos: vectors must have the same type: 1 != 2}
178+
{vector_distance: vectors must have the same length: 3 != 2}
179+
{vector_distance: vectors must have the same type: 1 != 2}
180+
{vector_distance: l2 distance is not supported for float1bit vectors}
174181
}]

0 commit comments

Comments
 (0)