react-native-nitro-sqlite-vec 9.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,41 @@
1
+ #ifndef SQLITE_VEC_H
2
+ #define SQLITE_VEC_H
3
+
4
+ #ifndef SQLITE_CORE
5
+ #include "sqlite3ext.h"
6
+ #else
7
+ #include "sqlite3.h"
8
+ #endif
9
+
10
+ #ifdef SQLITE_VEC_STATIC
11
+ #define SQLITE_VEC_API
12
+ #else
13
+ #ifdef _WIN32
14
+ #define SQLITE_VEC_API __declspec(dllexport)
15
+ #else
16
+ #define SQLITE_VEC_API
17
+ #endif
18
+ #endif
19
+
20
+ #define SQLITE_VEC_VERSION "v0.1.9"
21
+ // TODO rm
22
+ #define SQLITE_VEC_DATE "2026-03-31T08:01:41Z+0000"
23
+ #define SQLITE_VEC_SOURCE "e9f598abfa0c06b328d8fe5da9c3760cce74be10"
24
+
25
+
26
+ #define SQLITE_VEC_VERSION_MAJOR 0
27
+ #define SQLITE_VEC_VERSION_MINOR 1
28
+ #define SQLITE_VEC_VERSION_PATCH 9
29
+
30
+ #ifdef __cplusplus
31
+ extern "C" {
32
+ #endif
33
+
34
+ SQLITE_VEC_API int sqlite3_vec_init(sqlite3 *db, char **pzErrMsg,
35
+ const sqlite3_api_routines *pApi);
36
+
37
+ #ifdef __cplusplus
38
+ } /* end of the 'extern "C"' block */
39
+ #endif
40
+
41
+ #endif /* ifndef SQLITE_VEC_H */
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "react-native-nitro-sqlite-vec",
3
+ "version": "9.7.0",
4
+ "description": "Vector search (sqlite-vec) for react-native-nitro-sqlite. Native sqlite-vec is statically linked into the core's single sqlite3 — no second SQLite, no runtime extension loading.",
5
+ "source": "./src/index",
6
+ "react-native": "./src/index",
7
+ "main": "./src/index",
8
+ "types": "./src/index",
9
+ "files": [
10
+ "src",
11
+ "cpp",
12
+ "RNNitroSqliteVec.podspec",
13
+ "react-native.config.js",
14
+ "README.md"
15
+ ],
16
+ "scripts": {
17
+ "typecheck": "tsc --noEmit",
18
+ "lint": "eslint \"**/*.{js,ts,tsx}\" --fix",
19
+ "release": "release-it",
20
+ "prepublishOnly": "bun typecheck"
21
+ },
22
+ "keywords": [
23
+ "react-native",
24
+ "sqlite",
25
+ "sqlite-vec",
26
+ "vector",
27
+ "vector-search",
28
+ "nitro-modules",
29
+ "ios",
30
+ "android"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "git+https://github.com/margelo/react-native-nitro-sqlite.git"
35
+ },
36
+ "license": "MIT",
37
+ "publishConfig": {
38
+ "registry": "https://registry.npmjs.org/",
39
+ "access": "public"
40
+ },
41
+ "peerDependencies": {
42
+ "react-native-nitro-sqlite": ">=9.0.0"
43
+ },
44
+ "devDependencies": {
45
+ "react-native-nitro-sqlite": "9.7.0",
46
+ "typescript": "^5.8.3"
47
+ },
48
+ "release-it": {
49
+ "npm": {
50
+ "publish": true,
51
+ "skipChecks": true,
52
+ "versionArgs": [
53
+ "--allow-same-version"
54
+ ]
55
+ },
56
+ "git": false,
57
+ "github": {
58
+ "release": false
59
+ },
60
+ "hooks": {
61
+ "before:init": "bun typecheck"
62
+ },
63
+ "plugins": {
64
+ "@release-it/bumper": {
65
+ "out": {
66
+ "file": "package.json",
67
+ "path": [
68
+ "version",
69
+ "devDependencies.react-native-nitro-sqlite"
70
+ ]
71
+ }
72
+ }
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,9 @@
1
+ // Android compiles these sources via the core's CMake, so autolink iOS only.
2
+ module.exports = {
3
+ dependency: {
4
+ platforms: {
5
+ ios: {},
6
+ android: null,
7
+ },
8
+ },
9
+ }
package/src/index.ts ADDED
@@ -0,0 +1,81 @@
1
+ import type { NitroSQLiteConnection } from 'react-native-nitro-sqlite'
2
+
3
+ /** Optional typed helpers over react-native-nitro-sqlite's execute() for sqlite-vec. */
4
+
5
+ export type VectorColumnType = 'float' | 'int8' | 'bit'
6
+ export type VectorDistanceMetric = 'L2' | 'cosine' | 'L1'
7
+
8
+ /** A KNN result row: always `rowid` + `distance`, plus any selected columns. */
9
+ export interface KnnMatch {
10
+ rowid: number
11
+ distance: number
12
+ [column: string]: unknown
13
+ }
14
+
15
+ export interface CreateVectorTableOptions {
16
+ /** Number of dimensions of the vector column. */
17
+ dimensions: number
18
+ /** Vector storage type. Defaults to `'float'` (float32). */
19
+ type?: VectorColumnType
20
+ /** Distance metric. Defaults to sqlite-vec's default (L2). */
21
+ distanceMetric?: VectorDistanceMetric
22
+ /** Vector column name. Defaults to `'embedding'`. */
23
+ column?: string
24
+ }
25
+
26
+ export interface KnnSearchOptions {
27
+ /** Vector column name. Defaults to `'embedding'`. */
28
+ column?: string
29
+ }
30
+
31
+ function firstValue<T>(db: NitroSQLiteConnection, sql: string): T {
32
+ const row = db.execute(sql).rows?._array?.[0]
33
+ return row?.value as T
34
+ }
35
+
36
+ /** Returns the linked sqlite-vec version string, e.g. `"v0.1.9"`. */
37
+ export function vecVersion(db: NitroSQLiteConnection): string {
38
+ return firstValue<string>(db, 'SELECT vec_version() AS value')
39
+ }
40
+
41
+ /** True if sqlite-vec is linked into the active build (vector flag enabled). */
42
+ export function isVecAvailable(db: NitroSQLiteConnection): boolean {
43
+ try {
44
+ vecVersion(db)
45
+ return true
46
+ } catch {
47
+ return false
48
+ }
49
+ }
50
+
51
+ /** Creates a `vec0` virtual table for the given vector column. */
52
+ export function createVectorTable(
53
+ db: NitroSQLiteConnection,
54
+ table: string,
55
+ options: CreateVectorTableOptions,
56
+ ): void {
57
+ const column = options.column ?? 'embedding'
58
+ const type = options.type ?? 'float'
59
+ const metric = options.distanceMetric
60
+ const metricClause = metric ? ` distance_metric=${metric}` : ''
61
+ db.execute(
62
+ `CREATE VIRTUAL TABLE IF NOT EXISTS ${table} USING vec0(${column} ${type}[${options.dimensions}]${metricClause});`,
63
+ )
64
+ }
65
+
66
+ /** Runs a KNN search; `query` is a JSON string `'[0.1,0.2]'` or a numeric array. */
67
+ export function knnSearch(
68
+ db: NitroSQLiteConnection,
69
+ table: string,
70
+ query: string | number[],
71
+ k: number,
72
+ options?: KnnSearchOptions,
73
+ ): KnnMatch[] {
74
+ const column = options?.column ?? 'embedding'
75
+ const vector = typeof query === 'string' ? query : JSON.stringify(query)
76
+ const result = db.execute(
77
+ `SELECT rowid, distance FROM ${table} WHERE ${column} MATCH ? AND k = ? ORDER BY distance`,
78
+ [vector, k],
79
+ )
80
+ return (result.rows?._array ?? []) as unknown as KnnMatch[]
81
+ }