@usex/ternava 0.0.0-stage → 0.2.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/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ ## [0.2.0](https://github.com/ali-master/ternava/compare/v0.1.1...v0.2.0) (2026-10-13)
4
+
5
+ ### Features
6
+
7
+ * **docs-search:** add Persian Iran history corpus ([72156ec](https://github.com/ali-master/ternava/commit/72156ec827055970376917d91650fefac410e2bb))
8
+ * **docs-search:** localize history search interface ([aa7091d](https://github.com/ali-master/ternava/commit/aa7091ddc7065e9e1f659a9d4a46be5a971c8427))
9
+ * **emoji-search:** add Persian phrases and matching ([84624e2](https://github.com/ali-master/ternava/commit/84624e24e2555d1c23405d43e918073cdef182c3))
10
+ * **emoji-search:** localize interface and examples ([77e3929](https://github.com/ali-master/ternava/commit/77e3929b8326d1c35ab67d591e3f4142b25beb0a))
11
+ * **engine:** load bilingual model artifacts ([6ba3967](https://github.com/ali-master/ternava/commit/6ba3967020c6dc6fab60c30b9d961b65d259d1f8))
12
+ * **eval:** audit held-out data and correlations ([13c3f66](https://github.com/ali-master/ternava/commit/13c3f668bc3dd520b3a60cce6fc3c220d9889621))
13
+ * **eval:** evaluate bilingual model quality ([f313018](https://github.com/ali-master/ternava/commit/f3130182af244faa4ac4ba953f4a2ca09f9c0906))
14
+ * **eval:** preview Persian models without aliases ([1080d2c](https://github.com/ali-master/ternava/commit/1080d2c9efc4117aef4212cf2f054354c9604c8c))
15
+ * **odyssey:** search Persian narrative excerpts ([7ff0d80](https://github.com/ali-master/ternava/commit/7ff0d80eccf8bce237a7c9b2d649ed809b1f9f8e))
16
+ * **pack:** support bilingual models and positions ([4f3d322](https://github.com/ali-master/ternava/commit/4f3d3221464513f8f2f8bd185d53891bf99ae60f))
17
+ * **runtime:** support Node Bun and browsers ([29f537e](https://github.com/ali-master/ternava/commit/29f537ec3939375361cc98ba8aae80d4903fb33c))
18
+ * **training:** add bilingual tokenizer identity ([89572db](https://github.com/ali-master/ternava/commit/89572dbdaaa581c08e6f133f418215e89e474ccc))
19
+ * **training:** add compositional contrast training ([b406e03](https://github.com/ali-master/ternava/commit/b406e0398f959d8489df459fca43f95d1f8dddf2))
20
+ * **training:** add native Persian continuation ([49ab0e4](https://github.com/ali-master/ternava/commit/49ab0e43f36e7e86bd7ffe6ee46affcdce185fb8))
21
+ * **training:** add negation and numeric pilot ([d6d4bf2](https://github.com/ali-master/ternava/commit/d6d4bf2cb7b44d47f05f9b94b7270f141fed8248))
22
+ * **training:** add round 2 pilot ([6cd3d32](https://github.com/ali-master/ternava/commit/6cd3d32ca2d015b45c3142d49a0ba2a57b5cdab0))
23
+ * **training:** add round 3 pilot ([63124cd](https://github.com/ali-master/ternava/commit/63124cdcb5a5d3b28810f458cbea31b0062a9938))
24
+ * **training:** add round 4 pilot ([dd1fc27](https://github.com/ali-master/ternava/commit/dd1fc2766aac2bada412721d3c14a4420b9376f7))
25
+ * **training:** add technical Persian distillation ([7066bd5](https://github.com/ali-master/ternava/commit/7066bd51347e764f827b6dfbf2c0d242c2029168))
26
+ * **training:** configure bilingual mini distillation ([9c1dc83](https://github.com/ali-master/ternava/commit/9c1dc83d7a41c5b5f4cf75e6d412bd589a36276d))
27
+ * **training:** prepare bilingual teacher data ([2e762a0](https://github.com/ali-master/ternava/commit/2e762a04b3e7bc05339d65e851f8f18c44513a4b))
28
+ * **training:** preserve tokenizer provenance in runs ([cd77286](https://github.com/ali-master/ternava/commit/cd77286b6b90b0f2100ec59ff7fd9eee439dfcab))
29
+
30
+ ### Bug Fixes
31
+
32
+ * correct comments and improve readability in index.mjs and search.mjs ([151cd1b](https://github.com/ali-master/ternava/commit/151cd1bfcaadf130864d356d02ff130539250b69))
33
+ * **docs-search:** correct RTL search layout ([bcd6af2](https://github.com/ali-master/ternava/commit/bcd6af2df1db3d9367bdea3c101de9234ddcd61f))
34
+ * **engine:** match PyTorch activation rounding ([adacc66](https://github.com/ali-master/ternava/commit/adacc665210064791c8ecd23c7d71ab739e8cd53))
35
+ * **release:** prevent duplicate version tags ([ff45038](https://github.com/ali-master/ternava/commit/ff450382fe7732a7294a234202f5f00a5169e0ad))
36
+ * update demo links ([23da804](https://github.com/ali-master/ternava/commit/23da804d0ae19298c78446619905d92176a4ac83))
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Wenshu Tang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,75 @@
1
- # Temporary Holding Version
1
+ # @usex/ternava — Ternava / ترنوا
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Experimental Persian/English semantic embeddings for Node.js, Bun and browsers.
4
+ Built on [the upstream project](https://github.com/ali-master/ternava#acknowledgments) by Wenshu Tang — thank
5
+ you for the open-source model, Rust/WASM engine and training foundation.
6
+ Original MIT copyright is preserved in LICENSE.
7
+
8
+ The bilingual mini has 32,000 WordPiece tokens, 9,901,952 parameters, a 128-token
9
+ input limit, and 384-dimensional normalized embeddings. Weights use int4
10
+ embeddings and ternary linear layers. The default build uses the existing
11
+ `pilot-fa-en-reasoning` reference, not the failed compositional candidate.
12
+ **Persian negation and numeric reasoning remain unreliable.** Translated demos
13
+ and a successful import are not general language-quality evidence.
14
+
15
+ ## Installation
16
+
17
+ After publication: `bun add @usex/ternava`.
18
+ Try the [live history-search demo](https://ternava.usestrict.dev/).
19
+ Before publication, install the tarball produced by `bun run verify:release`
20
+ from the repository root. Nothing here implies that a release is already live.
21
+
22
+ ```js
23
+ import { embed, cosineSim, similar, engineInfo } from '@usex/ternava';
24
+ const vector = embed('خیلی دوستت دارم');
25
+ console.log(vector.length); // 384
26
+ console.log(cosineSim(vector, embed('عاشقتم')));
27
+ console.log(similar('forgot my password', [
28
+ 'Reset a forgotten password', 'Track a delivery',
29
+ ], { topK: 1 }));
30
+ console.log(engineInfo());
31
+ ```
32
+
33
+ Node.js and Bun can also use `const { embed } = require('@usex/ternava')`.
34
+ The main entry initializes synchronously from local WASM. It makes no API calls.
35
+
36
+ ## Portable loader
37
+
38
+ ```js
39
+ import init, { embed, similar } from '@usex/ternava/runtime';
40
+ await init();
41
+ console.log(embed('سلام دنیا'));
42
+ ```
43
+
44
+ Node/Bun read adjacent WASM from disk; browsers fetch it relative to the module
45
+ URL. In a plain browser, serve `pkg-web/` and import `./pkg-web/index.mjs`, or use
46
+ an import map for the package name. Keep its generated files together. `init`
47
+ accepts a URL, WASM bytes, or WebAssembly.Module; concurrent calls share a
48
+ promise and failed loads can be retried. Inference is synchronous after init.
49
+
50
+ `@usex/ternava/web` exposes the raw engine (`embed`, `tokenize`,
51
+ `config_summary`) and default init, without the JS helpers. The main browser
52
+ entry imports WASM as an ESM asset and requires a compatible bundler; webpack 5
53
+ uses `experiments: { asyncWebAssembly: true }`. For custom loaders, prefer
54
+ `/runtime` and explicit initialization.
55
+
56
+ ## API
57
+
58
+ | Export | Behavior |
59
+ |---|---|
60
+ | `embed(text)` | Float32Array(384), normalized; truncates at 128 tokens |
61
+ | `cosineSim(a, b)` | Dot product of normalized vectors |
62
+ | `similar(query, corpus, { topK })` | Sorted `{ text, sim }` results; default topK 5 |
63
+ | `engineInfo()` | Embedded model and tokenizer configuration |
64
+ | `TernError` | Stable `INVALID_INPUT`, `DIM_MISMATCH` codes; runtime adds `NOT_INITIALIZED` |
65
+
66
+ Cache corpus embeddings for repeated searches. Rebuild indexes whenever model
67
+ weights or tokenizer change; vectors from different models are not compatible.
68
+
69
+ [Source and measured pilot reports](https://github.com/ali-master/ternava).
70
+ `tern_engine` asset names and
71
+ `TernError` remain stable engine/API identifiers.
72
+
73
+ ## License
74
+
75
+ MIT. See LICENSE for the original attribution.
package/package.json CHANGED
@@ -1,6 +1,83 @@
1
1
  {
2
2
  "name": "@usex/ternava",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Ternava — experimental Persian/English semantic embeddings, 32k bilingual tokenizer and local WebAssembly inference for Node.js, Bun and browsers.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/ali-master/ternava.git",
9
+ "directory": "packages/mini"
10
+ },
11
+ "homepage": "https://ternava.usestrict.dev/",
12
+ "bugs": {
13
+ "url": "https://github.com/ali-master/ternava/issues"
14
+ },
15
+ "author": {
16
+ "url": "https://github.com/ali-master",
17
+ "name": "Ali Torki",
18
+ "email": "ali_4286@live.com"
19
+ },
20
+ "keywords": [
21
+ "embeddings",
22
+ "semantic-search",
23
+ "vector-search",
24
+ "nearest-neighbor",
25
+ "on-device",
26
+ "edge",
27
+ "wasm",
28
+ "bitnet",
29
+ "ternary",
30
+ "minilm",
31
+ "sentence-embeddings",
32
+ "persian",
33
+ "farsi",
34
+ "bilingual",
35
+ "ternava"
36
+ ],
37
+ "type": "commonjs",
38
+ "main": "src/index.js",
39
+ "module": "src/index.mjs",
40
+ "types": "src/index.d.ts",
41
+ "exports": {
42
+ ".": {
43
+ "types": "./src/index.d.ts",
44
+ "node": {
45
+ "import": "./src/index.mjs",
46
+ "require": "./src/index.js"
47
+ },
48
+ "browser": "./src/index.browser.mjs",
49
+ "default": "./src/index.browser.mjs"
50
+ },
51
+ "./web": {
52
+ "types": "./pkg-web/tern_engine.d.ts",
53
+ "default": "./pkg-web/tern_engine.js"
54
+ },
55
+ "./runtime": {
56
+ "types": "./pkg-web/index.d.mts",
57
+ "default": "./pkg-web/index.mjs"
58
+ },
59
+ "./package.json": "./package.json"
60
+ },
61
+ "files": [
62
+ "src/",
63
+ "pkg-node/",
64
+ "pkg-bundler/",
65
+ "pkg-web/",
66
+ "README.md",
67
+ "CHANGELOG.md",
68
+ "LICENSE",
69
+ "scripts/check-package.mjs"
70
+ ],
71
+ "publishConfig": {
72
+ "access": "public"
73
+ },
74
+ "engines": {
75
+ "node": ">=18"
76
+ },
77
+ "scripts": {
78
+ "build": "PKG=packages/mini bash ../../scripts/build-engine.sh",
79
+ "test": "node --test tests/*.test.js",
80
+ "prepack": "node --experimental-wasm-modules scripts/check-package.mjs",
81
+ "release": "release-it"
82
+ }
83
+ }
@@ -0,0 +1 @@
1
+ { "type": "module" }
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Debug helper: returns a human-readable summary of the loaded model's
6
+ * header (format version, embedding format, dimensions, vocab size).
7
+ */
8
+ export function config_summary(): string;
9
+
10
+ /**
11
+ * Primary entry point: text → 384-dim L2-normalized embedding.
12
+ *
13
+ * Tokenizes via the embedded BERT vocab, runs the full forward pass against
14
+ * the embedded `.bin`, returns the output vector.
15
+ */
16
+ export function embed(text: string): Float32Array;
17
+
18
+ /**
19
+ * Identity of the exact packed model embedded in this build.
20
+ */
21
+ export function model_sha256(): string;
22
+
23
+ /**
24
+ * Debug helper: returns token IDs the tokenizer produced. Used by per-stage
25
+ * parity tests to confirm tokenization matches the Python `tokenizers` library.
26
+ */
27
+ export function tokenize(text: string): Uint32Array;
28
+
29
+ /**
30
+ * Identity of the exact tokenizer embedded in this build.
31
+ */
32
+ export function tokenizer_sha256(): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./tern_engine.d.ts" */
2
+ import * as wasm from "./tern_engine_bg.wasm";
3
+ import { __wbg_set_wasm } from "./tern_engine_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ config_summary, embed, model_sha256, tokenize, tokenizer_sha256
9
+ } from "./tern_engine_bg.js";
@@ -0,0 +1,320 @@
1
+ /**
2
+ * Debug helper: returns a human-readable summary of the loaded model's
3
+ * header (format version, embedding format, dimensions, vocab size).
4
+ * @returns {string}
5
+ */
6
+ export function config_summary() {
7
+ let deferred1_0;
8
+ let deferred1_1;
9
+ try {
10
+ const ret = wasm.config_summary();
11
+ deferred1_0 = ret[0];
12
+ deferred1_1 = ret[1];
13
+ return getStringFromWasm0(ret[0], ret[1]);
14
+ } finally {
15
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
16
+ }
17
+ }
18
+
19
+ /**
20
+ * Primary entry point: text → 384-dim L2-normalized embedding.
21
+ *
22
+ * Tokenizes via the embedded BERT vocab, runs the full forward pass against
23
+ * the embedded `.bin`, returns the output vector.
24
+ * @param {string} text
25
+ * @returns {Float32Array}
26
+ */
27
+ export function embed(text) {
28
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
29
+ const len0 = WASM_VECTOR_LEN;
30
+ const ret = wasm.embed(ptr0, len0);
31
+ var v2 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
32
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
33
+ return v2;
34
+ }
35
+
36
+ /**
37
+ * Identity of the exact packed model embedded in this build.
38
+ * @returns {string}
39
+ */
40
+ export function model_sha256() {
41
+ let deferred1_0;
42
+ let deferred1_1;
43
+ try {
44
+ const ret = wasm.model_sha256();
45
+ deferred1_0 = ret[0];
46
+ deferred1_1 = ret[1];
47
+ return getStringFromWasm0(ret[0], ret[1]);
48
+ } finally {
49
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
50
+ }
51
+ }
52
+
53
+ /**
54
+ * Debug helper: returns token IDs the tokenizer produced. Used by per-stage
55
+ * parity tests to confirm tokenization matches the Python `tokenizers` library.
56
+ * @param {string} text
57
+ * @returns {Uint32Array}
58
+ */
59
+ export function tokenize(text) {
60
+ const ptr0 = passStringToWasm0(text, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
61
+ const len0 = WASM_VECTOR_LEN;
62
+ const ret = wasm.tokenize(ptr0, len0);
63
+ var v2 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
64
+ wasm.__wbindgen_free(ret[0], ret[1] * 4, 4);
65
+ return v2;
66
+ }
67
+
68
+ /**
69
+ * Identity of the exact tokenizer embedded in this build.
70
+ * @returns {string}
71
+ */
72
+ export function tokenizer_sha256() {
73
+ let deferred1_0;
74
+ let deferred1_1;
75
+ try {
76
+ const ret = wasm.tokenizer_sha256();
77
+ deferred1_0 = ret[0];
78
+ deferred1_1 = ret[1];
79
+ return getStringFromWasm0(ret[0], ret[1]);
80
+ } finally {
81
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
82
+ }
83
+ }
84
+ export function __wbg___wbindgen_is_function_754e9f305ff6029e(arg0) {
85
+ const ret = typeof(arg0) === 'function';
86
+ return ret;
87
+ }
88
+ export function __wbg___wbindgen_is_object_56732c2bc353f41d(arg0) {
89
+ const val = arg0;
90
+ const ret = typeof(val) === 'object' && val !== null;
91
+ return ret;
92
+ }
93
+ export function __wbg___wbindgen_is_string_c236cabd84a4d769(arg0) {
94
+ const ret = typeof(arg0) === 'string';
95
+ return ret;
96
+ }
97
+ export function __wbg___wbindgen_is_undefined_67b456be8673d3d7(arg0) {
98
+ const ret = arg0 === undefined;
99
+ return ret;
100
+ }
101
+ export function __wbg___wbindgen_throw_1506f2235d1bdba0(arg0, arg1) {
102
+ throw new Error(getStringFromWasm0(arg0, arg1));
103
+ }
104
+ export function __wbg_call_9c758de292015997() { return handleError(function (arg0, arg1, arg2) {
105
+ const ret = arg0.call(arg1, arg2);
106
+ return ret;
107
+ }, arguments); }
108
+ export function __wbg_crypto_38df2bab126b63dc(arg0) {
109
+ const ret = arg0.crypto;
110
+ return ret;
111
+ }
112
+ export function __wbg_getRandomValues_c44a50d8cfdaebeb() { return handleError(function (arg0, arg1) {
113
+ arg0.getRandomValues(arg1);
114
+ }, arguments); }
115
+ export function __wbg_length_4a591ecaa01354d9(arg0) {
116
+ const ret = arg0.length;
117
+ return ret;
118
+ }
119
+ export function __wbg_msCrypto_bd5a034af96bcba6(arg0) {
120
+ const ret = arg0.msCrypto;
121
+ return ret;
122
+ }
123
+ export function __wbg_new_with_length_36a4998e27b014c5(arg0) {
124
+ const ret = new Uint8Array(arg0 >>> 0);
125
+ return ret;
126
+ }
127
+ export function __wbg_node_84ea875411254db1(arg0) {
128
+ const ret = arg0.node;
129
+ return ret;
130
+ }
131
+ export function __wbg_process_44c7a14e11e9f69e(arg0) {
132
+ const ret = arg0.process;
133
+ return ret;
134
+ }
135
+ export function __wbg_prototypesetcall_3249fc62a0fafa30(arg0, arg1, arg2) {
136
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
137
+ }
138
+ export function __wbg_randomFillSync_6c25eac9869eb53c() { return handleError(function (arg0, arg1) {
139
+ arg0.randomFillSync(arg1);
140
+ }, arguments); }
141
+ export function __wbg_require_b4edbdcf3e2a1ef0() { return handleError(function () {
142
+ const ret = module.require;
143
+ return ret;
144
+ }, arguments); }
145
+ export function __wbg_static_accessor_GLOBAL_9d53f2689e622ca1() {
146
+ const ret = typeof global === 'undefined' ? null : global;
147
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
148
+ }
149
+ export function __wbg_static_accessor_GLOBAL_THIS_a1a35cec07001a8a() {
150
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
151
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
152
+ }
153
+ export function __wbg_static_accessor_SELF_4c59f6c7ea29a144() {
154
+ const ret = typeof self === 'undefined' ? null : self;
155
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
156
+ }
157
+ export function __wbg_static_accessor_WINDOW_e70ae9f2eb052253() {
158
+ const ret = typeof window === 'undefined' ? null : window;
159
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
160
+ }
161
+ export function __wbg_subarray_4aa221f6a4f5ab22(arg0, arg1, arg2) {
162
+ const ret = arg0.subarray(arg1 >>> 0, arg2 >>> 0);
163
+ return ret;
164
+ }
165
+ export function __wbg_versions_276b2795b1c6a219(arg0) {
166
+ const ret = arg0.versions;
167
+ return ret;
168
+ }
169
+ export function __wbindgen_cast_0000000000000001(arg0, arg1) {
170
+ // Cast intrinsic for `Ref(Slice(U8)) -> NamedExternref("Uint8Array")`.
171
+ const ret = getArrayU8FromWasm0(arg0, arg1);
172
+ return ret;
173
+ }
174
+ export function __wbindgen_cast_0000000000000002(arg0, arg1) {
175
+ // Cast intrinsic for `Ref(String) -> Externref`.
176
+ const ret = getStringFromWasm0(arg0, arg1);
177
+ return ret;
178
+ }
179
+ export function __wbindgen_init_externref_table() {
180
+ const table = wasm.__wbindgen_externrefs;
181
+ const offset = table.grow(4);
182
+ table.set(0, undefined);
183
+ table.set(offset + 0, undefined);
184
+ table.set(offset + 1, null);
185
+ table.set(offset + 2, true);
186
+ table.set(offset + 3, false);
187
+ }
188
+ function addToExternrefTable0(obj) {
189
+ const idx = wasm.__externref_table_alloc();
190
+ wasm.__wbindgen_externrefs.set(idx, obj);
191
+ return idx;
192
+ }
193
+
194
+ function getArrayF32FromWasm0(ptr, len) {
195
+ ptr = ptr >>> 0;
196
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
197
+ }
198
+
199
+ function getArrayU32FromWasm0(ptr, len) {
200
+ ptr = ptr >>> 0;
201
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
202
+ }
203
+
204
+ function getArrayU8FromWasm0(ptr, len) {
205
+ ptr = ptr >>> 0;
206
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
207
+ }
208
+
209
+ let cachedFloat32ArrayMemory0 = null;
210
+ function getFloat32ArrayMemory0() {
211
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
212
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
213
+ }
214
+ return cachedFloat32ArrayMemory0;
215
+ }
216
+
217
+ function getStringFromWasm0(ptr, len) {
218
+ return decodeText(ptr >>> 0, len);
219
+ }
220
+
221
+ let cachedUint32ArrayMemory0 = null;
222
+ function getUint32ArrayMemory0() {
223
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
224
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
225
+ }
226
+ return cachedUint32ArrayMemory0;
227
+ }
228
+
229
+ let cachedUint8ArrayMemory0 = null;
230
+ function getUint8ArrayMemory0() {
231
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
232
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
233
+ }
234
+ return cachedUint8ArrayMemory0;
235
+ }
236
+
237
+ function handleError(f, args) {
238
+ try {
239
+ return f.apply(this, args);
240
+ } catch (e) {
241
+ const idx = addToExternrefTable0(e);
242
+ wasm.__wbindgen_exn_store(idx);
243
+ }
244
+ }
245
+
246
+ function isLikeNone(x) {
247
+ return x === undefined || x === null;
248
+ }
249
+
250
+ function passStringToWasm0(arg, malloc, realloc) {
251
+ if (realloc === undefined) {
252
+ const buf = cachedTextEncoder.encode(arg);
253
+ const ptr = malloc(buf.length, 1) >>> 0;
254
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
255
+ WASM_VECTOR_LEN = buf.length;
256
+ return ptr;
257
+ }
258
+
259
+ let len = arg.length;
260
+ let ptr = malloc(len, 1) >>> 0;
261
+
262
+ const mem = getUint8ArrayMemory0();
263
+
264
+ let offset = 0;
265
+
266
+ for (; offset < len; offset++) {
267
+ const code = arg.charCodeAt(offset);
268
+ if (code > 0x7F) break;
269
+ mem[ptr + offset] = code;
270
+ }
271
+ if (offset !== len) {
272
+ if (offset !== 0) {
273
+ arg = arg.slice(offset);
274
+ }
275
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
276
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
277
+ const ret = cachedTextEncoder.encodeInto(arg, view);
278
+
279
+ offset += ret.written;
280
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
281
+ }
282
+
283
+ WASM_VECTOR_LEN = offset;
284
+ return ptr;
285
+ }
286
+
287
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
288
+ cachedTextDecoder.decode();
289
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
290
+ let numBytesDecoded = 0;
291
+ function decodeText(ptr, len) {
292
+ numBytesDecoded += len;
293
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
294
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
295
+ cachedTextDecoder.decode();
296
+ numBytesDecoded = len;
297
+ }
298
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
299
+ }
300
+
301
+ const cachedTextEncoder = new TextEncoder();
302
+
303
+ if (!('encodeInto' in cachedTextEncoder)) {
304
+ cachedTextEncoder.encodeInto = function (arg, view) {
305
+ const buf = cachedTextEncoder.encode(arg);
306
+ view.set(buf);
307
+ return {
308
+ read: arg.length,
309
+ written: buf.length
310
+ };
311
+ };
312
+ }
313
+
314
+ let WASM_VECTOR_LEN = 0;
315
+
316
+
317
+ let wasm;
318
+ export function __wbg_set_wasm(val) {
319
+ wasm = val;
320
+ }
Binary file
@@ -0,0 +1,15 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const config_summary: () => [number, number];
5
+ export const embed: (a: number, b: number) => [number, number];
6
+ export const model_sha256: () => [number, number];
7
+ export const tokenize: (a: number, b: number) => [number, number];
8
+ export const tokenizer_sha256: () => [number, number];
9
+ export const __wbindgen_exn_store: (a: number) => void;
10
+ export const __externref_table_alloc: () => number;
11
+ export const __wbindgen_externrefs: WebAssembly.Table;
12
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
13
+ export const __wbindgen_malloc: (a: number, b: number) => number;
14
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
15
+ export const __wbindgen_start: () => void;
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Debug helper: returns a human-readable summary of the loaded model's
6
+ * header (format version, embedding format, dimensions, vocab size).
7
+ */
8
+ export function config_summary(): string;
9
+
10
+ /**
11
+ * Primary entry point: text → 384-dim L2-normalized embedding.
12
+ *
13
+ * Tokenizes via the embedded BERT vocab, runs the full forward pass against
14
+ * the embedded `.bin`, returns the output vector.
15
+ */
16
+ export function embed(text: string): Float32Array;
17
+
18
+ /**
19
+ * Identity of the exact packed model embedded in this build.
20
+ */
21
+ export function model_sha256(): string;
22
+
23
+ /**
24
+ * Debug helper: returns token IDs the tokenizer produced. Used by per-stage
25
+ * parity tests to confirm tokenization matches the Python `tokenizers` library.
26
+ */
27
+ export function tokenize(text: string): Uint32Array;
28
+
29
+ /**
30
+ * Identity of the exact tokenizer embedded in this build.
31
+ */
32
+ export function tokenizer_sha256(): string;