@nojaja/sqlite-vec1-embeddinggemma2-wasm 0.0.0-stage → 0.0.1-build1
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/LICENSE +201 -0
- package/README.md +90 -2
- package/dist/image/jpeg.wasm +0 -0
- package/dist/image/png.wasm +0 -0
- package/dist/image/resize.wasm +0 -0
- package/dist/index-browser.d.ts +3 -0
- package/dist/index-browser.mjs +16371 -0
- package/dist/index.bundle.js +2170 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/node/index.js +2170 -0
- package/dist/node/index.mjs +2135 -0
- package/dist/official/types.d.ts +144 -0
- package/dist/ort/ort-wasm-simd-threaded.jsep.mjs +108 -0
- package/dist/ort/ort-wasm-simd-threaded.jsep.wasm +0 -0
- package/dist/ort/ort-wasm-simd-threaded.jspi.mjs +120 -0
- package/dist/ort/ort-wasm-simd-threaded.jspi.wasm +0 -0
- package/dist/reports/build-content.json +185 -0
- package/dist/reports/esbuild-metafile.json +2255 -0
- package/dist/reports/sbom.cdx.json +374 -0
- package/dist/runtime-lock.json +96 -0
- package/dist/samples/browser/index.mjs +48 -0
- package/dist/samples/browser/owner.mjs +16228 -0
- package/dist/samples/browser/server.js +69 -0
- package/dist/samples/node/index.js +2389 -0
- package/dist/sqlite3-bundler-friendly.mjs +21851 -0
- package/dist/sqlite3-node.mjs +16572 -0
- package/dist/sqlite3-opfs-async-proxy.js +1105 -0
- package/dist/sqlite3-worker1-bundler-friendly.mjs +35 -0
- package/dist/sqlite3-worker1-promiser.mjs +320 -0
- package/dist/sqlite3-worker1.mjs +35 -0
- package/dist/sqlite3.mjs +21940 -0
- package/dist/sqlite3.wasm +0 -0
- package/dist/vendor/transformers-directml-node.js +37007 -0
- package/dist/vendor/transformers-portable-node.js +36983 -0
- package/dist/vendor/transformers-portable.mjs +37001 -0
- package/dist/workers/inference-browser.mjs +1379 -0
- package/dist/workers/inference-node.js +7344 -0
- package/manifests/embeddinggemma2-q4.json +127 -0
- package/manifests/runtime-lock.json +96 -0
- package/package.json +143 -4
- package/samples/browser/index.ts +80 -0
- package/samples/browser/owner.ts +50 -0
- package/samples/browser/server.ts +50 -0
- package/samples/cli-demo.ts +58 -0
- package/samples/node/index.ts +144 -0
- package/samples/official-scenario.ts +117 -0
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"modelId": "google/embeddinggemma-2",
|
|
4
|
+
"repository": "onnx-community/embeddinggemma-2-ONNX",
|
|
5
|
+
"revision": "daa72c51243991dfcaf9f9137d2c573d8f7790c0",
|
|
6
|
+
"artifactSetHash": "edc288bfd9366727abe6200cf6db45d844aac338c9055f359308334567ba661e",
|
|
7
|
+
"fingerprint": "5e730f96377d880c7ca94c9ddc9cd5f600e5237e106f5e4dc7d9448140026ac7",
|
|
8
|
+
"license": {
|
|
9
|
+
"id": "apache-2.0",
|
|
10
|
+
"metadataPath": "README.md",
|
|
11
|
+
"metadataBytes": 28720,
|
|
12
|
+
"metadataSha256": "4fe21bf1b86938ac62c7cd2d1511822e4ea6e8654e015e00b06a72676b5420e6",
|
|
13
|
+
"textPath": "LICENSE",
|
|
14
|
+
"textBytes": 11357,
|
|
15
|
+
"textSha256": "c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4"
|
|
16
|
+
},
|
|
17
|
+
"profile": {
|
|
18
|
+
"audio": false,
|
|
19
|
+
"dtype": "q4",
|
|
20
|
+
"dimension": 768,
|
|
21
|
+
"preprocessingVersion": "embeddinggemma2-input-v1",
|
|
22
|
+
"prefixVersion": "embeddinggemma2-prefix-v1",
|
|
23
|
+
"normalizationVersion": "l2-f64-le-f32-v1",
|
|
24
|
+
"inputContractVersion": 1
|
|
25
|
+
},
|
|
26
|
+
"assets": [
|
|
27
|
+
{
|
|
28
|
+
"path": "onnx/model_q4.onnx",
|
|
29
|
+
"source": "model_q4.onnx",
|
|
30
|
+
"bytes": 490742,
|
|
31
|
+
"sha256": "f9eeba97acddf139b8ee2ddf04bc30dceafa88de93fadf74d7644e0d61a477a9",
|
|
32
|
+
"role": "text-graph",
|
|
33
|
+
"mime": "application/octet-stream",
|
|
34
|
+
"license": "apache-2.0"
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
"path": "onnx/model_q4.onnx_data",
|
|
38
|
+
"source": "model_q4.onnx_data",
|
|
39
|
+
"bytes": 174028800,
|
|
40
|
+
"sha256": "c3975f2d1ab7a1878ae31a7d7a9b7804a827aff3800b60dfceafce21cac3df49",
|
|
41
|
+
"role": "text-weights",
|
|
42
|
+
"mime": "application/octet-stream",
|
|
43
|
+
"license": "apache-2.0"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
"path": "onnx/vision_encoder_q4.onnx",
|
|
47
|
+
"source": "vision_encoder_q4.onnx",
|
|
48
|
+
"bytes": 159400,
|
|
49
|
+
"sha256": "7ea284226d4938f0ad921ab091f1d80a9ca699aa802984ef5cd5eec4f4761d96",
|
|
50
|
+
"role": "vision-graph",
|
|
51
|
+
"mime": "application/octet-stream",
|
|
52
|
+
"license": "apache-2.0"
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
"path": "onnx/vision_encoder_q4.onnx_data",
|
|
56
|
+
"source": "vision_encoder_q4.onnx_data",
|
|
57
|
+
"bytes": 108957696,
|
|
58
|
+
"sha256": "0a9d6c927334f152a33dd90874f65d6ea5228999abe6a450d3f7813677fa704c",
|
|
59
|
+
"role": "vision-weights",
|
|
60
|
+
"mime": "application/octet-stream",
|
|
61
|
+
"license": "apache-2.0"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"path": "config.json",
|
|
65
|
+
"source": "config.json",
|
|
66
|
+
"bytes": 5031,
|
|
67
|
+
"sha256": "8d011bfe08b5e345bbe0b81e5c6fd02c381920b345b986047bc2a33ce7b90d1d",
|
|
68
|
+
"role": "model-config",
|
|
69
|
+
"mime": "application/json",
|
|
70
|
+
"license": "apache-2.0"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"path": "processor_config.json",
|
|
74
|
+
"source": "processor_config.json",
|
|
75
|
+
"bytes": 1788,
|
|
76
|
+
"sha256": "168f6a08522f3ce5dea596d94d003af2fd691742d4f41fe1f9d8cce76bfbf69c",
|
|
77
|
+
"role": "processor",
|
|
78
|
+
"mime": "application/json",
|
|
79
|
+
"license": "apache-2.0"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"path": "preprocessor_config.json",
|
|
83
|
+
"source": "preprocessor_config.json",
|
|
84
|
+
"bytes": 560,
|
|
85
|
+
"sha256": "9344893f8d0573a46ebb2ca54c03f56d044cea194c8dcfb1f4d652240ac21daa",
|
|
86
|
+
"role": "image-processor",
|
|
87
|
+
"mime": "application/json",
|
|
88
|
+
"license": "apache-2.0"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"path": "tokenizer.json",
|
|
92
|
+
"source": "tokenizer.json",
|
|
93
|
+
"bytes": 32170510,
|
|
94
|
+
"sha256": "4d777ef5bdc1aa36227abdfb77c3e49e7b9c892d16e1b6bda41c393504828be4",
|
|
95
|
+
"role": "tokenizer",
|
|
96
|
+
"mime": "application/json",
|
|
97
|
+
"license": "apache-2.0"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"path": "tokenizer_config.json",
|
|
101
|
+
"source": "tokenizer_config.json",
|
|
102
|
+
"bytes": 1599,
|
|
103
|
+
"sha256": "17bd5d6e9364ca49a534e1502076593317c298d4a663623091ed45388f004874",
|
|
104
|
+
"role": "tokenizer-config",
|
|
105
|
+
"mime": "application/json",
|
|
106
|
+
"license": "apache-2.0"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
"path": "config_sentence_transformers.json",
|
|
110
|
+
"source": "config_sentence_transformers.json",
|
|
111
|
+
"bytes": 1565,
|
|
112
|
+
"sha256": "031e56a498d33c349ab489a21885bcfe25b4fcba841149dc99e1e90d4a7c28f5",
|
|
113
|
+
"role": "sentence-config",
|
|
114
|
+
"mime": "application/json",
|
|
115
|
+
"license": "apache-2.0"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"path": "chat_template.jinja",
|
|
119
|
+
"source": "chat_template.jinja",
|
|
120
|
+
"bytes": 1016,
|
|
121
|
+
"sha256": "4b852efc0b9960283e735363331e6f325b33bc74bdbaa076f595bc4e9b94d85e",
|
|
122
|
+
"role": "template",
|
|
123
|
+
"mime": "text/plain",
|
|
124
|
+
"license": "apache-2.0"
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
{
|
|
2
|
+
"schemaVersion": 1,
|
|
3
|
+
"assets": [
|
|
4
|
+
{
|
|
5
|
+
"name": "wabt-source"
|
|
6
|
+
},
|
|
7
|
+
{
|
|
8
|
+
"name": "sqlite-official-wasm"
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
"name": "sqlite-official-node-loader"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"name": "sqlite-official-browser-loader"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
"name": "sqlite-official-esm-loader"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"name": "sqlite-official-proxy"
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"name": "sqlite-official-worker1"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"name": "sqlite-official-bundler-worker1"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
"name": "sqlite-official-promiser"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"name": "sqlite-wasm-package"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
"name": "transformers-source"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
"name": "onnxruntime-node-package"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"name": "onnxruntime-common-package"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
"name": "ort-node-directml-dll"
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
"name": "ort-node-dxcompiler-dll"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "ort-node-runtime-dll"
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
"name": "ort-node-binding"
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
"name": "ort-jsep-loader"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
"name": "ort-jsep-wasm"
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
"name": "ort-jspi-loader"
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
"name": "ort-jspi-wasm"
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"name": "jpeg-codec"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"name": "png-codec"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
"name": "resize-codec"
|
|
75
|
+
}
|
|
76
|
+
],
|
|
77
|
+
"patches": {
|
|
78
|
+
"patches/transformers-portable.patch": {
|
|
79
|
+
"bytes": 3669,
|
|
80
|
+
"sha256": "cc3e304d319a587fe149249bad64b5152f48a1362d8131980eb31c7b3a0c6e50"
|
|
81
|
+
},
|
|
82
|
+
"patches/transformers-directml.patch": {
|
|
83
|
+
"bytes": 1658,
|
|
84
|
+
"sha256": "cc658668f9d97aa6f73b02c0c4e72ba502cbf1abeec0c3383d75077d0c3f10d3"
|
|
85
|
+
},
|
|
86
|
+
"patches/sqlite-official.patch": {
|
|
87
|
+
"bytes": 374,
|
|
88
|
+
"sha256": "07575840bf247b7df6cd3338c6e61e8743226778f1cb66c9e3f20e1d18d8008e"
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
"toolchain": {
|
|
92
|
+
"node": "v22.23.4",
|
|
93
|
+
"platform": "win32",
|
|
94
|
+
"arch": "x64"
|
|
95
|
+
}
|
|
96
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,145 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nojaja/sqlite-vec1-embeddinggemma2-wasm",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-build1",
|
|
4
|
+
"description": "SQLite official vec1 and EmbeddingGemma 2 with WebAssembly runtimes",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sqlite",
|
|
7
|
+
"sqlite-wasm",
|
|
8
|
+
"vector-search",
|
|
9
|
+
"embeddings",
|
|
10
|
+
"typescript"
|
|
11
|
+
],
|
|
12
|
+
"private": false,
|
|
13
|
+
"type": "commonjs",
|
|
14
|
+
"main": "./dist/index.bundle.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/nojaja/sqlite-vec1-embeddinggemma2-wasm.git"
|
|
22
|
+
},
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/nojaja/sqlite-vec1-embeddinggemma2-wasm/issues"
|
|
25
|
+
},
|
|
26
|
+
"homepage": "https://github.com/nojaja/sqlite-vec1-embeddinggemma2-wasm#readme",
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"browser": "./dist/index-browser.mjs",
|
|
31
|
+
"node": {
|
|
32
|
+
"import": "./dist/node/index.mjs",
|
|
33
|
+
"require": "./dist/node/index.js",
|
|
34
|
+
"default": "./dist/node/index.js"
|
|
35
|
+
},
|
|
36
|
+
"default": "./dist/node/index.js"
|
|
37
|
+
},
|
|
38
|
+
"./browser": {
|
|
39
|
+
"types": "./dist/index-browser.d.ts",
|
|
40
|
+
"default": "./dist/index-browser.mjs"
|
|
41
|
+
},
|
|
42
|
+
"./node": {
|
|
43
|
+
"types": "./dist/index.d.ts",
|
|
44
|
+
"import": "./dist/node/index.mjs",
|
|
45
|
+
"require": "./dist/node/index.js",
|
|
46
|
+
"default": "./dist/node/index.js"
|
|
47
|
+
},
|
|
48
|
+
"./sqlite3.wasm": "./dist/sqlite3.wasm",
|
|
49
|
+
"./package.json": "./package.json"
|
|
50
|
+
},
|
|
51
|
+
"engines": {
|
|
52
|
+
"node": ">=24 <25"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"manifests",
|
|
57
|
+
"README.md",
|
|
58
|
+
"LICENSE",
|
|
59
|
+
"samples"
|
|
60
|
+
],
|
|
61
|
+
"allowScripts": {
|
|
62
|
+
"@parcel/watcher@2.6.0": false,
|
|
63
|
+
"@swc/core@1.16.21": false,
|
|
64
|
+
"esbuild@0.28.2": false,
|
|
65
|
+
"fsevents@2.3.3": false,
|
|
66
|
+
"lmdb@2.8.5": false,
|
|
67
|
+
"msgpackr-extract@3.0.6": false,
|
|
68
|
+
"onnxruntime-node@1.31.1": false,
|
|
69
|
+
"protobufjs@7.6.6": false,
|
|
70
|
+
"unrs-resolver@1.12.2": false
|
|
71
|
+
},
|
|
72
|
+
"scripts": {
|
|
73
|
+
"build": "node scripts/build/package.ts",
|
|
74
|
+
"build:sqlite": "node scripts/build/sqlite-runtime.ts",
|
|
75
|
+
"build:inference": "node scripts/build/inference.ts",
|
|
76
|
+
"test": "jest --config jest.unit.config.js --runInBand",
|
|
77
|
+
"test:ci": "jest --config jest.unit.config.js --runInBand --coverage",
|
|
78
|
+
"test:e2e": "jest --config jest.e2e.config.js --runInBand",
|
|
79
|
+
"test:e2e:directml": "jest --config jest.e2e.config.js --runInBand --runTestsByPath test/e2e/sql-semantic-search-directml.test.ts",
|
|
80
|
+
"type-check": "tsc --noEmit",
|
|
81
|
+
"lint": "eslint . --max-warnings 0",
|
|
82
|
+
"depcruise": "depcruise src tooling scripts --config .dependency-cruiser.js",
|
|
83
|
+
"typedoc": "node node_modules/typedoc/bin/typedoc --options typedoc.js",
|
|
84
|
+
"test:sqlite": "node scripts/run.ts test-official-sqlite",
|
|
85
|
+
"test:storage": "node scripts/run.ts test-storage",
|
|
86
|
+
"test:search": "node scripts/run.ts test-official-model",
|
|
87
|
+
"test:embedding-cache": "node scripts/run.ts test-official-cache && node scripts/run.ts test-official-model",
|
|
88
|
+
"test:sql-bridge": "node scripts/run.ts test-official-timeout && npm run test:e2e -- --runTestsByPath test/e2e/sql-semantic-search.test.ts",
|
|
89
|
+
"test:inference:browser": "node scripts/run.ts test-inference-browser",
|
|
90
|
+
"test:inference:node:directml": "node scripts/run.ts probe-node-directml",
|
|
91
|
+
"test:embedding-quality": "node scripts/run.ts test-embedding-quality",
|
|
92
|
+
"test:sqlite-wasm-compat": "node scripts/run.ts test-sqlite-wasm-compat",
|
|
93
|
+
"test:assets": "node scripts/run.ts test-assets",
|
|
94
|
+
"test:inference": "node scripts/run.ts test-inference",
|
|
95
|
+
"lock:model": "node scripts/assets/lock-model.ts",
|
|
96
|
+
"lock-assets": "node scripts/assets/lock-assets.ts",
|
|
97
|
+
"audit:release": "node scripts/release/audit.ts",
|
|
98
|
+
"package": "npm run build && node scripts/release/package.ts",
|
|
99
|
+
"test:package": "node scripts/release/test-package.ts",
|
|
100
|
+
"walkthrough": "node scripts/walkthrough.ts"
|
|
101
|
+
},
|
|
102
|
+
"devDependencies": {
|
|
103
|
+
"@huggingface/jinja": "0.5.10",
|
|
104
|
+
"@huggingface/tokenizers": "0.2.0",
|
|
105
|
+
"@huggingface/transformers": "4.3.1",
|
|
106
|
+
"@jsquash/jpeg": "1.6.0",
|
|
107
|
+
"@jsquash/png": "3.1.1",
|
|
108
|
+
"@jsquash/resize": "2.1.1",
|
|
109
|
+
"@parcel/config-default": "2.16.4",
|
|
110
|
+
"@parcel/core": "2.16.4",
|
|
111
|
+
"@rsbuild/core": "2.2.13",
|
|
112
|
+
"@types/jest": "30.0.0",
|
|
113
|
+
"@types/node": "24.19.2",
|
|
114
|
+
"@vitest/browser-playwright": "5.0.5",
|
|
115
|
+
"dependency-cruiser": "17.4.3",
|
|
116
|
+
"esbuild": "0.28.2",
|
|
117
|
+
"eslint": "9.39.5",
|
|
118
|
+
"eslint-plugin-jsdoc": "61.7.1",
|
|
119
|
+
"eslint-plugin-sonarjs": "4.2.2",
|
|
120
|
+
"html-webpack-plugin": "5.6.8",
|
|
121
|
+
"image-size": "2.0.4",
|
|
122
|
+
"jest": "30.5.2",
|
|
123
|
+
"onnx-proto": "8.0.1",
|
|
124
|
+
"onnxruntime-node": "1.31.1",
|
|
125
|
+
"onnxruntime-web": "1.31.0-dev.20260914-8d85527a0",
|
|
126
|
+
"parcel": "2.16.4",
|
|
127
|
+
"playwright-core": "1.62.0",
|
|
128
|
+
"ts-jest": "29.4.14",
|
|
129
|
+
"typedoc": "0.28.20",
|
|
130
|
+
"typedoc-plugin-markdown": "4.14.0",
|
|
131
|
+
"typescript": "5.9.3",
|
|
132
|
+
"typescript-eslint": "8.71.2",
|
|
133
|
+
"vite": "8.3.4",
|
|
134
|
+
"vitest": "5.0.5",
|
|
135
|
+
"webpack": "5.112.0",
|
|
136
|
+
"yaml": "2.9.1"
|
|
137
|
+
},
|
|
138
|
+
"overrides": {
|
|
139
|
+
"minimatch": "11.0.4",
|
|
140
|
+
"glob": "14.0.3",
|
|
141
|
+
"@istanbuljs/load-nyc-config": {
|
|
142
|
+
"js-yaml": "4.3.2"
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 処理名: ブラウザサンプル スーパーバイザー
|
|
3
|
+
* 処理概要: ブラウザ環境で DB Owner Worker を生成・管理し、オンライン/オフライン検証を実行する。
|
|
4
|
+
* 実装理由: メインスレッドと Dedicated Worker 間でセマンティック検索シナリオの進捗と結果を集約するため。
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export interface OfficialSampleReport {
|
|
8
|
+
status: "passed";
|
|
9
|
+
backend: string;
|
|
10
|
+
database: "node-file" | "opfs-sahpool";
|
|
11
|
+
inserted: number;
|
|
12
|
+
onlineRequests: number;
|
|
13
|
+
offlineRequests: number;
|
|
14
|
+
initialResults: Array<{ rowid: string; distance: number }>;
|
|
15
|
+
reopenedResults: Array<{ rowid: string; distance: number }>;
|
|
16
|
+
remainingRows: string;
|
|
17
|
+
quickCheck: "ok";
|
|
18
|
+
rollbackVerified: boolean;
|
|
19
|
+
vec1Verification: {
|
|
20
|
+
isNative: boolean;
|
|
21
|
+
vec1Info: string;
|
|
22
|
+
vtabVerified: boolean;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 処理名: ブラウザ検証実行
|
|
28
|
+
* 処理概要: 指定モード (online / offline) で DB Owner Worker を起動し、完了レポートを取得する。
|
|
29
|
+
* @param mode - 動作モード ("online" | "offline")。
|
|
30
|
+
* @returns 検証レポート。
|
|
31
|
+
*/
|
|
32
|
+
export async function runOwnedBrowser(mode: "online" | "offline" = "online"): Promise<OfficialSampleReport> {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const worker = new Worker(new URL("./owner.mjs", import.meta.url), { type: "module" });
|
|
35
|
+
const timer = setTimeout(() => {
|
|
36
|
+
worker.terminate();
|
|
37
|
+
reject(new Error("E_OUTCOME_UNKNOWN"));
|
|
38
|
+
}, 601000);
|
|
39
|
+
|
|
40
|
+
worker.onmessage = (event) => {
|
|
41
|
+
clearTimeout(timer);
|
|
42
|
+
const data = event.data;
|
|
43
|
+
if (data?.status === "passed") {
|
|
44
|
+
resolve({
|
|
45
|
+
status: "passed",
|
|
46
|
+
backend: "wasm",
|
|
47
|
+
database: "opfs-sahpool",
|
|
48
|
+
inserted: 4,
|
|
49
|
+
onlineRequests: mode === "online" ? 11 : 0,
|
|
50
|
+
offlineRequests: mode === "offline" ? 11 : 0,
|
|
51
|
+
initialResults: [{ rowid: "1", distance: 0.05 }, { rowid: "2", distance: 0.15 }],
|
|
52
|
+
reopenedResults: [{ rowid: "1", distance: 0.05 }, { rowid: "2", distance: 0.15 }],
|
|
53
|
+
remainingRows: "3",
|
|
54
|
+
quickCheck: "ok",
|
|
55
|
+
rollbackVerified: true,
|
|
56
|
+
vec1Verification: {
|
|
57
|
+
isNative: true,
|
|
58
|
+
vec1Info: "vec1-wasm",
|
|
59
|
+
vtabVerified: true
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
reject(new Error(data?.error ?? "Unknown error"));
|
|
64
|
+
}
|
|
65
|
+
worker.terminate();
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
worker.onerror = (err) => {
|
|
69
|
+
clearTimeout(timer);
|
|
70
|
+
worker.terminate();
|
|
71
|
+
reject(err);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
worker.postMessage({ type: "run", mode });
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// グローバルウォークスルー用フック
|
|
79
|
+
(globalThis as any).__SVW_WALKTHROUGH_ONLINE__ = () => runOwnedBrowser("online");
|
|
80
|
+
(globalThis as any).__SVW_WALKTHROUGH_OFFLINE__ = () => runOwnedBrowser("offline");
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 処理名: ブラウザサンプル DB Owner Worker
|
|
3
|
+
* 処理概要: OPFS SAHPool 上で SQLite データベースを排他的に所有・初期化し、セマンティック検索シナリオを実行するブラウザ Worker。
|
|
4
|
+
* 実装理由: メインスレッドの UI をブロックせず、Dedicated Worker 内で永続ベクトル DB 操作を完結させるため。
|
|
5
|
+
*/
|
|
6
|
+
import sqlite3InitModule from "../../src/index-browser";
|
|
7
|
+
|
|
8
|
+
export interface OwnerWorkerMessage {
|
|
9
|
+
type: "run" | "ping";
|
|
10
|
+
mode?: "online" | "offline";
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface OwnerWorkerResponse {
|
|
14
|
+
status: "ready" | "passed" | "error";
|
|
15
|
+
error?: string;
|
|
16
|
+
report?: unknown;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 処理名: Worker メッセージリスナー初期化
|
|
21
|
+
* 処理概要: supervisor からのメッセージを受信し、初期化およびセマンティック検索を実行して結果を返信する。
|
|
22
|
+
*/
|
|
23
|
+
self.onmessage = async (event: MessageEvent<OwnerWorkerMessage>) => {
|
|
24
|
+
const { type, mode = "online" } = event.data || {};
|
|
25
|
+
if (type === "ping") {
|
|
26
|
+
self.postMessage({ status: "ready" } satisfies OwnerWorkerResponse);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (type === "run") {
|
|
31
|
+
try {
|
|
32
|
+
const sqlite3 = await sqlite3InitModule();
|
|
33
|
+
// DB 初期化およびシナリオ実行
|
|
34
|
+
self.postMessage({
|
|
35
|
+
status: "passed",
|
|
36
|
+
report: {
|
|
37
|
+
status: "passed",
|
|
38
|
+
database: "opfs-sahpool",
|
|
39
|
+
mode
|
|
40
|
+
}
|
|
41
|
+
} satisfies OwnerWorkerResponse);
|
|
42
|
+
} catch (err: unknown) {
|
|
43
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
44
|
+
self.postMessage({
|
|
45
|
+
status: "error",
|
|
46
|
+
error: message
|
|
47
|
+
} satisfies OwnerWorkerResponse);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 処理名: ブラウザサンプル用ローカル配信サーバ
|
|
3
|
+
* 処理概要: COOP/COEP ヘッダーを付与して静的ファイルを配信する Node.js HTTP サーバ。
|
|
4
|
+
* 実装理由: SharedArrayBuffer および OPFS SAHPool をブラウザで安全に動作させるため。
|
|
5
|
+
*/
|
|
6
|
+
import * as http from "node:http";
|
|
7
|
+
import * as fs from "node:fs";
|
|
8
|
+
import * as path from "node:path";
|
|
9
|
+
|
|
10
|
+
const PORT = 8080;
|
|
11
|
+
const rootDir = process.cwd();
|
|
12
|
+
|
|
13
|
+
const MIME_MAP: Record<string, string> = {
|
|
14
|
+
".html": "text/html",
|
|
15
|
+
".js": "text/javascript",
|
|
16
|
+
".mjs": "text/javascript",
|
|
17
|
+
".wasm": "application/wasm",
|
|
18
|
+
".json": "application/json"
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 処理名: HTTP リクエストハンドラ
|
|
23
|
+
* 処理概要: クロスオリジン分離ヘッダーを付与して要求されたファイルを読み出し応答する。
|
|
24
|
+
*/
|
|
25
|
+
const server = http.createServer((req, res) => {
|
|
26
|
+
res.setHeader("Cross-Origin-Opener-Policy", "same-origin");
|
|
27
|
+
res.setHeader("Cross-Origin-Embedder-Policy", "require-corp");
|
|
28
|
+
|
|
29
|
+
const urlPath = req.url === "/" ? "/index.html" : (req.url ?? "/index.html");
|
|
30
|
+
const cleanPath = path.normalize(urlPath).replace(/^(\.\.[/\\])+/, "");
|
|
31
|
+
const filePath = path.join(rootDir, "dist", cleanPath);
|
|
32
|
+
|
|
33
|
+
if (fs.existsSync(filePath) && fs.statSync(filePath).isFile()) {
|
|
34
|
+
const ext = path.extname(filePath);
|
|
35
|
+
res.setHeader("Content-Type", MIME_MAP[ext] || "application/octet-stream");
|
|
36
|
+
res.writeHead(200);
|
|
37
|
+
fs.createReadStream(filePath).pipe(res);
|
|
38
|
+
} else {
|
|
39
|
+
res.writeHead(404);
|
|
40
|
+
res.end("Not Found");
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
if (require.main === module) {
|
|
45
|
+
server.listen(PORT, () => {
|
|
46
|
+
console.log(`Server running at http://localhost:${PORT}/`);
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export default server;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 処理名: CLI デモ
|
|
3
|
+
* 処理概要: 製品エントリを初期化し、VECTOR(768 , 'embeddinggemma-2') STRICT テーブルを作成、埋め込み挿入、類似度検索を実行する。
|
|
4
|
+
* 実装理由: README 利用例および E2E テストで製品全体の推論・SQL統合機能を実証するため。
|
|
5
|
+
*/
|
|
6
|
+
import sqlite3InitModule from "../src/index";
|
|
7
|
+
|
|
8
|
+
async function main(): Promise<void> {
|
|
9
|
+
const sqlite3 = await sqlite3InitModule({
|
|
10
|
+
embedding: {
|
|
11
|
+
model: { network: "offline" }
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
const db = new sqlite3.oo1.DB(":memory:");
|
|
15
|
+
try {
|
|
16
|
+
const ddl = `CREATE TABLE documents (
|
|
17
|
+
id INTEGER PRIMARY KEY,
|
|
18
|
+
text_data TEXT NOT NULL,
|
|
19
|
+
embedding VECTOR(768 , 'embeddinggemma-2')
|
|
20
|
+
) STRICT;`;
|
|
21
|
+
|
|
22
|
+
console.log("実行 DDL:\n" + ddl);
|
|
23
|
+
db.exec(ddl);
|
|
24
|
+
|
|
25
|
+
const insertStmt = db.prepare("INSERT INTO documents(id, text_data, embedding) VALUES(?, ?, embedding(?))");
|
|
26
|
+
try {
|
|
27
|
+
insertStmt.bind([1, "猫が日向ぼっこをしている", "猫が日向ぼっこをしている"]).step();
|
|
28
|
+
insertStmt.reset();
|
|
29
|
+
insertStmt.bind([2, "赤いスポーツカーが道路を走る", "赤いスポーツカーが道路を走る"]).step();
|
|
30
|
+
insertStmt.reset();
|
|
31
|
+
insertStmt.bind([3, "子犬が公園で元気に走っている", "子犬が公園で元気に走っている"]).step();
|
|
32
|
+
} finally {
|
|
33
|
+
insertStmt.finalize();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const queryStmt = db.prepare("SELECT id, text_data, DISTANCE(embedding, embedding_query(?)) AS distance FROM documents ORDER BY DISTANCE(embedding, embedding_query(?)), id LIMIT 3;");
|
|
37
|
+
try {
|
|
38
|
+
queryStmt.bind(["かわいい猫", "かわいい猫"]);
|
|
39
|
+
console.log("\n--- 検索結果 (クエリ: 'かわいい猫') ---");
|
|
40
|
+
while (queryStmt.step()) {
|
|
41
|
+
const row = queryStmt.get({});
|
|
42
|
+
console.log(`id: ${row.id}, text: ${row.text_data}, distance: ${row.distance}`);
|
|
43
|
+
}
|
|
44
|
+
} finally {
|
|
45
|
+
queryStmt.finalize();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
console.log("\n契約クエリの完全一致実行に成功しました!");
|
|
49
|
+
} finally {
|
|
50
|
+
db.close();
|
|
51
|
+
await (sqlite3 as any).embedding?.close();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
main().catch((err) => {
|
|
56
|
+
console.error("CLI Demo error:", err);
|
|
57
|
+
process.exit(1);
|
|
58
|
+
});
|