Skip to content

Commit 8077948

Browse files
authored
Merge pull request #1653 from tursodatabase/vector-search-allow-partial-index
Vector search allow partial index
2 parents e78fb34 + ec996fa commit 8077948

File tree

4 files changed

+30
-18
lines changed

4 files changed

+30
-18
lines changed

libsql-ffi/bundled/SQLite3MultipleCiphers/src/sqlite3.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214523,11 +214523,6 @@ int vectorIndexCreate(Parse *pParse, const Index *pIdx, const char *zDbSName, co
214523214523
sqlite3ErrorMsg(pParse, "vector index: must contain exactly one column wrapped into the " VECTOR_INDEX_MARKER_FUNCTION " function");
214524214524
return CREATE_FAIL;
214525214525
}
214526-
// we are able to support this but I doubt this works for now - more polishing required to make this work
214527-
if( pIdx->pPartIdxWhere != NULL ) {
214528-
sqlite3ErrorMsg(pParse, "vector index: where condition is forbidden");
214529-
return CREATE_FAIL;
214530-
}
214531214526

214532214527
pArgsList = pIdx->aColExpr->a[0].pExpr->x.pList;
214533214528
pListItem = pArgsList->a;

libsql-ffi/bundled/src/sqlite3.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214523,11 +214523,6 @@ int vectorIndexCreate(Parse *pParse, const Index *pIdx, const char *zDbSName, co
214523214523
sqlite3ErrorMsg(pParse, "vector index: must contain exactly one column wrapped into the " VECTOR_INDEX_MARKER_FUNCTION " function");
214524214524
return CREATE_FAIL;
214525214525
}
214526-
// we are able to support this but I doubt this works for now - more polishing required to make this work
214527-
if( pIdx->pPartIdxWhere != NULL ) {
214528-
sqlite3ErrorMsg(pParse, "vector index: where condition is forbidden");
214529-
return CREATE_FAIL;
214530-
}
214531214526

214532214527
pArgsList = pIdx->aColExpr->a[0].pExpr->x.pList;
214533214528
pListItem = pArgsList->a;

libsql-sqlite3/src/vectorIndex.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,6 @@ int vectorIndexCreate(Parse *pParse, const Index *pIdx, const char *zDbSName, co
862862
sqlite3ErrorMsg(pParse, "vector index: must contain exactly one column wrapped into the " VECTOR_INDEX_MARKER_FUNCTION " function");
863863
return CREATE_FAIL;
864864
}
865-
// we are able to support this but I doubt this works for now - more polishing required to make this work
866-
if( pIdx->pPartIdxWhere != NULL ) {
867-
sqlite3ErrorMsg(pParse, "vector index: where condition is forbidden");
868-
return CREATE_FAIL;
869-
}
870865

871866
pArgsList = pIdx->aColExpr->a[0].pExpr->x.pList;
872867
pListItem = pArgsList->a;

libsql-sqlite3/test/libsql_vector_index.test

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,36 @@ do_execsql_test vector-all-params {
275275
SELECT * FROM vector_top_k('t_all_params_idx', vector('[1,2]'), 2);
276276
} {1 2}
277277

278+
do_execsql_test vector-partial {
279+
CREATE TABLE t_partial( name TEXT, type INT, v FLOAT32(3));
280+
INSERT INTO t_partial VALUES ( 'a', 0, vector('[1,2,3]') );
281+
INSERT INTO t_partial VALUES ( 'b', 1, vector('[3,4,5]') );
282+
INSERT INTO t_partial VALUES ( 'c', 2, vector('[4,5,6]') );
283+
INSERT INTO t_partial VALUES ( 'd', 0, vector('[5,6,7]') );
284+
INSERT INTO t_partial VALUES ( 'e', 1, vector('[6,7,8]') );
285+
INSERT INTO t_partial VALUES ( 'f', 2, vector('[7,8,9]') );
286+
CREATE INDEX t_partial_idx_0 ON t_partial( libsql_vector_idx(v) ) WHERE type = 0;
287+
CREATE INDEX t_partial_idx_1 ON t_partial( libsql_vector_idx(v) ) WHERE type = 1;
288+
CREATE INDEX t_partial_idx_not_0 ON t_partial( libsql_vector_idx(v) ) WHERE type != 0;
289+
SELECT id FROM vector_top_k('t_partial_idx_0', vector('[1,2,3]'), 10);
290+
SELECT id FROM vector_top_k('t_partial_idx_1', vector('[1,2,3]'), 10);
291+
SELECT id FROM vector_top_k('t_partial_idx_not_0', vector('[1,2,3]'), 10);
292+
INSERT INTO t_partial VALUES ( 'g', 0, vector('[8,9,10]') );
293+
INSERT INTO t_partial VALUES ( 'h', 1, vector('[9,10,11]') );
294+
INSERT INTO t_partial VALUES ( 'i', 2, vector('[10,11,12]') );
295+
SELECT id FROM vector_top_k('t_partial_idx_0', vector('[1,2,3]'), 10);
296+
SELECT id FROM vector_top_k('t_partial_idx_1', vector('[1,2,3]'), 10);
297+
SELECT id FROM vector_top_k('t_partial_idx_not_0', vector('[1,2,3]'), 10);
298+
} {
299+
1 4
300+
2 5
301+
2 3 5 6
302+
303+
1 4 7
304+
2 5 8
305+
2 3 5 6 8 9
306+
}
307+
278308
proc error_messages {sql} {
279309
set ret ""
280310
catch {
@@ -309,8 +339,6 @@ do_test vector-errors {
309339
sqlite3_exec db { CREATE TABLE t_mixed_t( v FLOAT32(3)); }
310340
sqlite3_exec db { INSERT INTO t_mixed_t VALUES('[1]'); }
311341
lappend ret [error_messages {CREATE INDEX t_mixed_t_idx ON t_mixed_t( libsql_vector_idx(v) )}]
312-
sqlite3_exec db { CREATE TABLE t_partial( name TEXT, type INT, v FLOAT32(3)); }
313-
lappend ret [error_messages {CREATE INDEX t_partial_idx ON t_partial( libsql_vector_idx(v) ) WHERE type = 0}]
314342
} [list {*}{
315343
{no such table: main.t_no}
316344
{no such column: v}
@@ -328,5 +356,4 @@ do_test vector-errors {
328356
{vector index(insert): only f32 vectors are supported}
329357
{vector index(search): dimensions are different: 2 != 4}
330358
{vector index(insert): dimensions are different: 1 != 3}
331-
{vector index: where condition is forbidden}
332359
}]

0 commit comments

Comments
 (0)