react-native-nitro-sqlite-vec 9.8.1 → 10.0.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.
- package/README.md +2 -1
- package/RNNitroSqliteVec.podspec +6 -2
- package/cpp/{registerVectorExtensions.cpp → NitroSQLiteVecRegisterVectorExtensions.cpp} +1 -1
- package/cpp/NitroSQLiteVecRegisterVectorExtensions.hpp +10 -0
- package/package.json +4 -2
- package/react-native.config.js +2 -1
- package/src/index.ts +38 -11
- package/cpp/registerVectorExtensions.hpp +0 -8
package/README.md
CHANGED
|
@@ -10,10 +10,11 @@ Install both this package and `react-native-nitro-sqlite`, then enable the nativ
|
|
|
10
10
|
npm install react-native-nitro-sqlite react-native-nitro-sqlite-vec
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
- **iOS:**
|
|
13
|
+
- **Apple platforms (iOS, macOS, visionOS):**
|
|
14
14
|
```bash
|
|
15
15
|
NITRO_SQLITE_VEC=1 npx pod-install
|
|
16
16
|
```
|
|
17
|
+
For React Native macOS, run `NITRO_SQLITE_VEC=1 pod install` from `macos/`.
|
|
17
18
|
- **Android:** add this to `android/gradle.properties` and rebuild:
|
|
18
19
|
```properties
|
|
19
20
|
nitroSqliteVec=true
|
package/RNNitroSqliteVec.podspec
CHANGED
|
@@ -2,7 +2,7 @@ require "json"
|
|
|
2
2
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# Apple-platform opt-in (NITRO_SQLITE_VEC=1); compile sqlite-vec and static-link into the core's sqlite3.
|
|
6
6
|
nitro_sqlite_vec = ENV['NITRO_SQLITE_VEC'] == '1'
|
|
7
7
|
|
|
8
8
|
# The core's bundled sqlite3.h (compiled with SQLITE_CORE to link it directly).
|
|
@@ -15,7 +15,11 @@ Pod::Spec.new do |s|
|
|
|
15
15
|
s.homepage = "https://github.com/margelo/react-native-nitro-sqlite"
|
|
16
16
|
s.license = "MIT"
|
|
17
17
|
s.authors = "Margelo"
|
|
18
|
-
s.platforms = {
|
|
18
|
+
s.platforms = {
|
|
19
|
+
:ios => min_ios_version_supported,
|
|
20
|
+
:visionos => "1.0",
|
|
21
|
+
:osx => "10.13",
|
|
22
|
+
}
|
|
19
23
|
s.source = { :git => "https://github.com/margelo/react-native-nitro-sqlite.git", :tag => "#{s.version}" }
|
|
20
24
|
|
|
21
25
|
if nitro_sqlite_vec
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
namespace margelo::rnnitrosqlitevec {
|
|
4
|
+
|
|
5
|
+
/** Register the statically linked sqlite-vec initializer as a SQLite auto-extension.
|
|
6
|
+
* A process-wide once flag makes repeated calls safe before each database open.
|
|
7
|
+
*/
|
|
8
|
+
void registerVectorExtensions();
|
|
9
|
+
|
|
10
|
+
} // namespace margelo::rnnitrosqlitevec
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-sqlite-vec",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "10.0.0",
|
|
4
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
5
|
"source": "./src/index",
|
|
6
6
|
"react-native": "./src/index",
|
|
@@ -29,12 +29,14 @@
|
|
|
29
29
|
"vector-search",
|
|
30
30
|
"nitro-modules",
|
|
31
31
|
"ios",
|
|
32
|
+
"macos",
|
|
32
33
|
"android"
|
|
33
34
|
],
|
|
34
35
|
"repository": {
|
|
35
36
|
"type": "git",
|
|
36
37
|
"url": "git+https://github.com/margelo/react-native-nitro-sqlite.git"
|
|
37
38
|
},
|
|
39
|
+
"author": "Christoph Pader",
|
|
38
40
|
"license": "MIT",
|
|
39
41
|
"publishConfig": {
|
|
40
42
|
"registry": "https://registry.npmjs.org/",
|
|
@@ -44,7 +46,7 @@
|
|
|
44
46
|
"react-native-nitro-sqlite": ">=9.0.0"
|
|
45
47
|
},
|
|
46
48
|
"devDependencies": {
|
|
47
|
-
"react-native-nitro-sqlite": "
|
|
49
|
+
"react-native-nitro-sqlite": "10.0.0",
|
|
48
50
|
"typescript": "^5.8.3"
|
|
49
51
|
},
|
|
50
52
|
"jest": {
|
package/react-native.config.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
// Android compiles
|
|
1
|
+
// CocoaPods autolinks this package on Apple platforms; Android compiles it via the core's CMake.
|
|
2
2
|
module.exports = {
|
|
3
3
|
dependency: {
|
|
4
4
|
platforms: {
|
|
5
5
|
ios: {},
|
|
6
|
+
macos: {},
|
|
6
7
|
android: null,
|
|
7
8
|
},
|
|
8
9
|
},
|
package/src/index.ts
CHANGED
|
@@ -1,30 +1,36 @@
|
|
|
1
1
|
import type { NitroSQLiteConnection } from 'react-native-nitro-sqlite'
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/** Vector storage types accepted by a `vec0` column. */
|
|
5
4
|
export type VectorColumnType = 'float' | 'int8' | 'bit'
|
|
5
|
+
|
|
6
|
+
/** Distance metrics accepted by a `vec0` column. */
|
|
6
7
|
export type VectorDistanceMetric = 'L2' | 'cosine' | 'L1'
|
|
7
8
|
|
|
8
|
-
/**
|
|
9
|
+
/** One nearest-neighbor match returned by {@link knnSearch}. */
|
|
9
10
|
export interface KnnMatch {
|
|
11
|
+
/** SQLite row ID of the matching vector. */
|
|
10
12
|
rowid: number
|
|
13
|
+
/** Distance from the query vector, ordered from smallest to largest. */
|
|
11
14
|
distance: number
|
|
15
|
+
/** Allows additional columns when using this row shape with custom queries. */
|
|
12
16
|
[column: string]: unknown
|
|
13
17
|
}
|
|
14
18
|
|
|
19
|
+
/** Settings for a `vec0` virtual table created by {@link createVectorTable}. */
|
|
15
20
|
export interface CreateVectorTableOptions {
|
|
16
|
-
/** Number of dimensions
|
|
21
|
+
/** Number of dimensions passed to `vec0` for the vector column. */
|
|
17
22
|
dimensions: number
|
|
18
23
|
/** Vector storage type. Defaults to `'float'` (float32). */
|
|
19
24
|
type?: VectorColumnType
|
|
20
|
-
/** Distance metric.
|
|
25
|
+
/** Distance metric. Omit to use sqlite-vec's default (L2). */
|
|
21
26
|
distanceMetric?: VectorDistanceMetric
|
|
22
|
-
/**
|
|
27
|
+
/** Trusted SQL column identifier. Defaults to `'embedding'`. */
|
|
23
28
|
column?: string
|
|
24
29
|
}
|
|
25
30
|
|
|
31
|
+
/** Settings for {@link knnSearch}. */
|
|
26
32
|
export interface KnnSearchOptions {
|
|
27
|
-
/**
|
|
33
|
+
/** Trusted SQL column identifier. Defaults to `'embedding'`. */
|
|
28
34
|
column?: string
|
|
29
35
|
}
|
|
30
36
|
|
|
@@ -33,12 +39,19 @@ function firstValue<T>(db: NitroSQLiteConnection, sql: string): T {
|
|
|
33
39
|
return row?.value as T
|
|
34
40
|
}
|
|
35
41
|
|
|
36
|
-
/**
|
|
42
|
+
/** Query the sqlite-vec version on an open connection.
|
|
43
|
+
* @param db Open NitroSQLite connection. The query runs synchronously.
|
|
44
|
+
* @returns The linked version string, for example `"v0.1.9"`.
|
|
45
|
+
* @throws If `vec_version()` is unavailable or the query fails.
|
|
46
|
+
*/
|
|
37
47
|
export function vecVersion(db: NitroSQLiteConnection): string {
|
|
38
48
|
return firstValue<string>(db, 'SELECT vec_version() AS value')
|
|
39
49
|
}
|
|
40
50
|
|
|
41
|
-
/**
|
|
51
|
+
/** Check whether the version query succeeds on this connection.
|
|
52
|
+
* @param db Open NitroSQLite connection. The check runs synchronously.
|
|
53
|
+
* @returns `false` if the version query throws for any reason, including a closed connection.
|
|
54
|
+
*/
|
|
42
55
|
export function isVecAvailable(db: NitroSQLiteConnection): boolean {
|
|
43
56
|
try {
|
|
44
57
|
vecVersion(db)
|
|
@@ -48,7 +61,13 @@ export function isVecAvailable(db: NitroSQLiteConnection): boolean {
|
|
|
48
61
|
}
|
|
49
62
|
}
|
|
50
63
|
|
|
51
|
-
/**
|
|
64
|
+
/** Create a `vec0` virtual table if it does not already exist.
|
|
65
|
+
* Executes synchronously. An existing table is left as it is, even if its
|
|
66
|
+
* definition differs from `options`.
|
|
67
|
+
* @param db Open NitroSQLite connection with sqlite-vec enabled.
|
|
68
|
+
* @param table Trusted SQL table identifier, interpolated into the statement.
|
|
69
|
+
* @param options Vector dimensions, storage type, metric, and trusted column identifier.
|
|
70
|
+
*/
|
|
52
71
|
export function createVectorTable(
|
|
53
72
|
db: NitroSQLiteConnection,
|
|
54
73
|
table: string,
|
|
@@ -63,7 +82,15 @@ export function createVectorTable(
|
|
|
63
82
|
)
|
|
64
83
|
}
|
|
65
84
|
|
|
66
|
-
/**
|
|
85
|
+
/** Search a `vec0` table for the nearest vectors.
|
|
86
|
+
* Executes synchronously and returns matches ordered by increasing distance.
|
|
87
|
+
* @param db Open NitroSQLite connection with sqlite-vec enabled.
|
|
88
|
+
* @param table Trusted SQL table identifier, interpolated into the statement.
|
|
89
|
+
* @param query JSON vector string passed through unchanged, or a numeric array serialized as JSON.
|
|
90
|
+
* @param k Maximum number of matches requested.
|
|
91
|
+
* @param options Optional trusted vector column identifier.
|
|
92
|
+
* @returns Matching row IDs and distances, or an empty array when no rows are returned.
|
|
93
|
+
*/
|
|
67
94
|
export function knnSearch(
|
|
68
95
|
db: NitroSQLiteConnection,
|
|
69
96
|
table: string,
|