Skip to content

Commit 02d7775

Browse files
feat(sqlite-vec): vector search (#285)
* feat(sqlite-vec): vector search via statically-linked sqlite-vec Add react-native-nitro-sqlite-vec: a companion package vendoring the sqlite-vec v0.1.9 amalgamation. Its native sources compile INTO the core react-native-nitro-sqlite library's single sqlite3 build and register via sqlite3_auto_extension — no second sqlite3, no runtime extension loading. Vector search runs through the core's existing execute() API (vec0 + vec_* functions); thin typed helpers (vecVersion/createVectorTable/ knnSearch) are included. Core integration: - Android: CMakeLists/build.gradle flag-gated compilation of the companion's sqlite-vec.c (-DSQLITE_CORE -DSQLITE_VEC_STATIC), enabled in the example via gradle.properties `nitroSqliteVec=true`. - iOS: companion RNNitroSqliteVec.podspec, static-linked into the core's single sqlite3 through the core podspec. - operations.cpp registers the extension once in sqliteOpenDb (#ifdef NITRO_SQLITE_VEC); bindStatement binds whole-number JS values as INTEGER (vec0 rowid/pk/partition require INTEGER); sqliteExecuteBatch fixes a double-rollback that masked the real batch error. Testing: on-device React Native Harness spec (example/tests/harness/sqlite-vec.harness.ts) covering vec_* scalar functions, distance metrics, vec0 KNN (float32/int8/bit), metadata filtering, partition keys, auxiliary columns, and UPDATE/DELETE. * fix: comments * fix: prettier * chore: update `Podfile.lock` * fix: enable sqlite-vec in example project --------- Co-authored-by: Christoph Pader <chris@margelo.com>
1 parent 179a15a commit 02d7775

24 files changed

Lines changed: 11118 additions & 25 deletions

.claude/settings.local.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
{
22
"permissions": {
3-
"allow": [
4-
"Bash(find:*)",
5-
"Bash(grep:*)"
6-
]
3+
"allow": ["Bash(find:*)", "Bash(grep:*)"]
74
}
85
}

bun.lock

Lines changed: 17 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/android/gradle.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,6 @@ hermesEnabled=true
4242
# This allows your app to draw behind system bars for an immersive UI.
4343
# Note: Only works with ReactActivity and should not be used with custom Activity.
4444
edgeToEdgeEnabled=false
45+
46+
# Compile react-native-nitro-sqlite-vec into the core library (opt-in).
47+
nitroSqliteVec=true

example/ios/Podfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
ENV['RCT_NEW_ARCH_ENABLED'] = '1'
22
ENV['USE_FRAMEWORKS'] = "static"
3+
ENV['NITRO_SQLITE_VEC'] = '1'
34

45
# Resolve react_native_pods.rb with node to allow for hoisting
56
require Pod::Executable.execute_command('node', ['-p',

example/ios/Podfile.lock

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1931,6 +1931,8 @@ PODS:
19311931
- ReactCommon/turbomodule/core
19321932
- ReactNativeDependencies
19331933
- Yoga
1934+
- RNNitroSqliteVec (9.6.0):
1935+
- RNNitroSQLite
19341936
- RNScreens (4.18.0):
19351937
- hermes-engine
19361938
- RCTRequired
@@ -2060,6 +2062,7 @@ DEPENDENCIES:
20602062
- ReactNativeDependencies (from `../../node_modules/react-native/third-party-podspecs/ReactNativeDependencies.podspec`)
20612063
- "RNCClipboard (from `../../node_modules/@react-native-clipboard/clipboard`)"
20622064
- RNNitroSQLite (from `../../packages/react-native-nitro-sqlite`)
2065+
- RNNitroSqliteVec (from `../../node_modules/react-native-nitro-sqlite-vec`)
20632066
- RNScreens (from `../../node_modules/react-native-screens`)
20642067
- Yoga (from `../../node_modules/react-native/ReactCommon/yoga`)
20652068

@@ -2225,6 +2228,8 @@ EXTERNAL SOURCES:
22252228
:path: "../../node_modules/@react-native-clipboard/clipboard"
22262229
RNNitroSQLite:
22272230
:path: "../../packages/react-native-nitro-sqlite"
2231+
RNNitroSqliteVec:
2232+
:path: "../../node_modules/react-native-nitro-sqlite-vec"
22282233
RNScreens:
22292234
:path: "../../node_modules/react-native-screens"
22302235
Yoga:
@@ -2309,10 +2314,11 @@ SPEC CHECKSUMS:
23092314
ReactCommon: 7525e252c88d254545e3fdaea0000d1959dfbf20
23102315
ReactNativeDependencies: 0cdc5c6985700a9d8f654762fa702169ef9cef9b
23112316
RNCClipboard: 7a7d4557bfd3370b35c99dfecd92ae7b9fc4948a
2312-
RNNitroSQLite: d4dcda5cae90531900839746ca2009e1db222793
2317+
RNNitroSQLite: bad203a8435c5d843534398dc4822b3e80fbbd81
2318+
RNNitroSqliteVec: cca5db2aec2a31f4e26a911bda7cac8fc2cdc2e2
23132319
RNScreens: dd5c879d56b543c7ff8e593739eeb66093d60263
23142320
Yoga: d68c8a4bde0af9c17b15540fffa330d26398d150
23152321

2316-
PODFILE CHECKSUM: efa901d259f2a40103bc359243a7632881296bf1
2322+
PODFILE CHECKSUM: 6933dbd8b4eea93df54a57c95e03351734e37a5b
23172323

23182324
COCOAPODS: 1.15.2

example/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
"react-native": "0.85.0-rc.0",
2929
"react-native-nitro-modules": "*",
3030
"react-native-nitro-sqlite": "9.6.0",
31+
"react-native-nitro-sqlite-vec": "*",
3132
"react-native-quick-base64": "^3.0.0",
3233
"react-native-quick-crypto": "^1.1.5",
3334
"react-native-safe-area-context": "^5.5.2",

example/src/screens/UnitTestScreen.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@ import React, { useEffect, useState } from 'react'
22
import { FlatList, StyleSheet, Text } from 'react-native'
33
import type { MochaTestResult } from '@tests/MochaSetup'
44
import { runTests } from '@tests/MochaSetup'
5-
import { registerUnitTests, registerTypeORMUnitTests } from '@tests/unit'
5+
import {
6+
registerUnitTests,
7+
registerTypeORMUnitTests,
8+
registerSqliteVecUnitTests,
9+
} from '@tests/unit'
610

711
export function UnitTestScreen() {
812
const [results, setResults] = useState<MochaTestResult[]>([])
913

1014
useEffect(() => {
1115
setResults([])
12-
runTests(registerUnitTests, registerTypeORMUnitTests).then(setResults)
16+
runTests(
17+
registerUnitTests,
18+
registerTypeORMUnitTests,
19+
registerSqliteVecUnitTests,
20+
).then(setResults)
1321
}, [])
1422

1523
return (
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import '@/initGlobals'
2+
import { registerSqliteVecUnitTests } from '@tests/unit'
3+
import init from './init'
4+
5+
init()
6+
registerSqliteVecUnitTests()

example/tests/unit/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import registerTransactionUnitTests from './specs/operations/transaction.spec'
55
import registerExecuteBatchUnitTests from './specs/operations/executeBatch.spec'
66
import registerTypeORMUnitTestsSpecs from './specs/typeorm.spec'
77
import registerDatabaseQueueUnitTests from './specs/DatabaseQueue.spec'
8+
import registerSqliteVecUnitTestsSpecs from './specs/sqlite-vec.spec'
89

910
export function registerUnitTests() {
1011
beforeEach(setupTestDb)
@@ -21,3 +22,7 @@ export function registerUnitTests() {
2122
export function registerTypeORMUnitTests() {
2223
registerTypeORMUnitTestsSpecs()
2324
}
25+
26+
export function registerSqliteVecUnitTests() {
27+
registerSqliteVecUnitTestsSpecs()
28+
}

0 commit comments

Comments
 (0)