API Reference / react-native-nitro-sqlite-vec
react-native-nitro-sqlite-vec
This optional package adds sqlite-vec vector search to Nitro SQLite. Its native code is compiled into the core package's SQLite build. The functions and types below cover availability checks, vector tables, and nearest-neighbor searches.
Install
Install Nitro SQLite, Nitro Modules, and the vector companion. The core requires React Native 0.75 or newer, React 17 or newer, and Nitro Modules 0.37.1 or newer. Enable sqlite-vec for every platform you ship.
npm install react-native-nitro-sqlite react-native-nitro-modules react-native-nitro-sqlite-vecOn iOS, install Pods with the build flag:
NITRO_SQLITE_VEC=1 npx pod-installOn Android, add this to android/gradle.properties:
nitroSqliteVec=trueRebuild the native app after enabling the flag. See the vector search guide for other Apple platforms and more setup details.
Create and search a vector table
import { open } from 'react-native-nitro-sqlite'
import {
createVectorTable,
isVecAvailable,
knnSearch,
} from 'react-native-nitro-sqlite-vec'
const db = open({ name: 'vectors.sqlite' })
if (!isVecAvailable(db)) {
db.close()
throw new Error('Enable sqlite-vec in the native build')
}
createVectorTable(db, 'embeddings', { dimensions: 3 })
db.execute('INSERT INTO embeddings (rowid, embedding) VALUES (?, ?)', [
1,
'[0.1, 0.2, 0.3]',
])
const matches = knnSearch(db, 'embeddings', [0.1, 0.2, 0.25], 10)
console.log(matches)
db.close()isVecAvailable() returns false when its version query fails. The helpers use table and column names as SQL identifiers, so only pass names you control. See the vector search guide for storage types, distance metrics, and custom queries.