Skip to content

Commit 0ac98cd

Browse files
committed
Update sqlite vec android
1 parent 93bba9e commit 0ac98cd

File tree

6 files changed

+43
-1
lines changed

6 files changed

+43
-1
lines changed
-1.9 KB
Binary file not shown.
-324 Bytes
Binary file not shown.

android/src/main/libsqlitevec/x86/libsqlite_vec.so

100644100755
528 Bytes
Binary file not shown.
336 Bytes
Binary file not shown.

example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
"fts5": true,
5252
"rtree": true,
5353
"crsqlite": false,
54-
"sqliteVec": false,
54+
"sqliteVec": true,
5555
"performanceMode": true,
5656
"tokenizers": [
5757
"wordtokenizer",

example/src/tests/queries.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -775,4 +775,46 @@ describe('Queries tests', () => {
775775
const res = db.executeSync('PRAGMA user_version');
776776
expect(res.rows).toDeepEqual([{user_version: 0}]);
777777
});
778+
779+
it('sqlite-vec extension: vector similarity search', async () => {
780+
// Create a virtual table for storing vectors
781+
await db.execute(`
782+
CREATE VIRTUAL TABLE vec_items USING vec0(
783+
embedding FLOAT[8]
784+
)
785+
`);
786+
787+
// Insert some sample vectors
788+
await db.execute(`
789+
INSERT INTO vec_items(rowid, embedding)
790+
VALUES
791+
(1, '[-0.200, 0.250, 0.341, -0.211, 0.645, 0.935, -0.316, -0.924]'),
792+
(2, '[0.443, -0.501, 0.355, -0.771, 0.707, -0.708, -0.185, 0.362]'),
793+
(3, '[0.716, -0.927, 0.134, 0.052, -0.669, 0.793, -0.634, -0.162]'),
794+
(4, '[-0.710, 0.330, 0.656, 0.041, -0.990, 0.726, 0.385, -0.958]')
795+
`);
796+
797+
// Perform KNN query to find the 2 nearest neighbors
798+
const queryVector = '[0.890, 0.544, 0.825, 0.961, 0.358, 0.0196, 0.521, 0.175]';
799+
const result = await db.execute(`
800+
SELECT rowid, distance
801+
FROM vec_items
802+
WHERE embedding MATCH ?
803+
ORDER BY distance
804+
LIMIT 2
805+
`, [queryVector]);
806+
807+
// Verify results
808+
expect(result.rows.length).toEqual(2);
809+
expect(result.rows[0]!.rowid).toEqual(2);
810+
expect(result.rows[1]!.rowid).toEqual(1);
811+
812+
// Verify distances are positive numbers
813+
const distance0 = result.rows[0]!.distance as number;
814+
const distance1 = result.rows[1]!.distance as number;
815+
expect(typeof distance0).toEqual('number');
816+
expect(distance0 > 0).toBeTruthy();
817+
expect(distance1 > 0).toBeTruthy();
818+
});
819+
778820
});

0 commit comments

Comments
 (0)