@thinletterio/vqweb 0.1.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/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,35 @@
1
+ thinletter embedding-quantization
2
+ Copyright 2026 Jan Rosecký (thinletter)
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE). It includes or derives from the
5
+ following third-party components:
6
+
7
+ 1. @wllama/wllama 3.6.1 (client/browser/vendor/wllama/: index.js, wllama.wasm; libllama build b10663-83d855c)
8
+ Copyright (c) 2024 Xuan Son NGUYEN. MIT License (client/browser/vendor/wllama/LICENCE).
9
+ llama.cpp / ggml inside the wasm: Copyright (c) 2023-2026 The ggml authors. MIT License.
10
+
11
+ 2. @huggingface/tokenizers 0.2.0 (client/vqweb/vendor/tokenizers/tokenizers.mjs)
12
+ Copyright 2018- The Hugging Face team. Apache License, Version 2.0 (client/vqweb/vendor/tokenizers/LICENSE).
13
+
14
+ 3. client/vqweb/embed.js contains a Q2_K block decoder ported operation by operation from llama.cpp
15
+ gguf-py/gguf/quants.py (Q2_K.dequantize_blocks). Portions derived from llama.cpp,
16
+ Copyright (c) 2023-2026 The ggml authors, MIT License:
17
+
18
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
19
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation
20
+ the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
21
+ to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above
22
+ copyright notice and this permission notice shall be included in all copies or substantial portions of the
23
+ Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
24
+ LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
25
+ SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27
+ DEALINGS IN THE SOFTWARE.
28
+
29
+ 4. The scalar export packs GGUF files with gguf-py (llama.cpp, MIT) as an imported library; the native evaluation uses
30
+ llama.cpp binaries built from third_party/ (not distributed here).
31
+
32
+ Methods: GPTQ (Frantar et al.), GPTVQ (van Baalen et al.), Hadamard/QuaRot-style rotations and the other borrowed ideas
33
+ are credited in research/prior_art.md. Derived model weights published
34
+ on Hugging Face keep the licence of their base model (microsoft/harrier-oss-v1-0.6b MIT, Qwen/Qwen3-Embedding-0.6B
35
+ Apache-2.0, BAAI/bge-m3 MIT) with attribution in each model card.
package/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # @thinletterio/vqweb
2
+
3
+ Vector-quantised **query encoders** in the browser on WebGPU. Load a released `.vqw` file (105–240 MiB), embed a query in
4
+ about 100 ms on an integrated GPU, and search **your existing document index** — the index was built with the full-precision
5
+ model and does not change. Apache-2.0.
6
+
7
+ - Models: [huggingface.co/thinletter](https://huggingface.co/thinletter) — harrier-0.6b (English, 2.1 / 1.8 bits per weight,
8
+ 105–129 MiB) and Qwen3-Embedding-0.6B (Czech-calibrated, 3.6 bits, 237 MiB). Each model card says which document encoder
9
+ and settings the file is a client of, and what it keeps of the full-precision retrieval quality (paired bootstrap on the
10
+ public test split; the browser reproduces the simulation).
11
+ - Demo: [thinletter.io/demo](https://thinletter.io/demo). Method and numbers: the
12
+ [technical report](https://github.com/rosecky/embedding-quantization-public/blob/main/docs/release/technical_report.md).
13
+
14
+ ## Install
15
+
16
+ ```
17
+ npm install @thinletterio/vqweb
18
+ ```
19
+
20
+ or without a bundler, straight from a CDN:
21
+
22
+ ```html
23
+ <script type="module">
24
+ import { loadVqwClient } from 'https://thinletter.io/vqweb/vqweb.js';
25
+ // or: https://cdn.jsdelivr.net/npm/@thinletterio/vqweb/dist/vqweb.js
26
+ </script>
27
+ ```
28
+
29
+ Requirements: WebGPU with the `shader-f16` feature (Chrome / Edge on desktop and Android; Safari 26 and Firefox where the
30
+ adapter reports `shader-f16`; `probeWebGPU()` tells you). There is no CPU fallback: check `probeWebGPU()` first and use the scalar GGUF files from the same Hugging
31
+ Face organisation with [wllama](https://github.com/ngxson/wllama) where WebGPU is missing.
32
+
33
+ ## Use
34
+
35
+ ```js
36
+ import { loadVqwClient, probeWebGPU } from '@thinletterio/vqweb';
37
+
38
+ const gpu = await probeWebGPU();
39
+ if (!gpu.ok) throw new Error(gpu.reason);
40
+
41
+ const client = await loadVqwClient(
42
+ 'https://huggingface.co/thinletter/qwen3-embedding-0.6b-vq-clients/resolve/main/qwen3-0.6b-vq3.5d2-webfaq_q-vocfull.vqw',
43
+ { onProgress: ({ phase, loaded, total }) => console.log(phase, loaded, total) },
44
+ );
45
+
46
+ const q = await client.embed('Kolik stojí parkování v centru Prahy?'); // Float32Array(1024), L2-normalised
47
+ // score = dot(q, docVector) for every document vector of your fp32 / int8 index built with Qwen/Qwen3-Embedding-0.6B
48
+
49
+ console.log(client.info.model.teacher, client.info.quant.bpwBlocks, client.info.timing);
50
+ client.dispose();
51
+ ```
52
+
53
+ What `loadVqwClient` does: downloads the container (with progress; a `.chunks.json` byte-chunk manifest as on thinletter.io
54
+ works too), keeps it in the origin's private file system (OPFS) so the next visit loads from disk, uploads the codebooks,
55
+ indices and scales to the GPU, fetches the tokenizer named in the container header, compiles the WebGPU pipelines and runs
56
+ one warm-up query. The container header carries the query prompt, the EOS rule, the byte-fallback token table and, for the
57
+ `*p` files, the prompt's precomputed keys and values — `embed(text)` takes the **raw query text**.
58
+
59
+ Options: `cache: 'none'` (memory only), `device` (bring your own `GPUDevice` with `shader-f16`), `powerPreference`
60
+ (`'low-power'` default = the integrated GPU where there is a choice), `tokenizerUrl` / `tokenizerConfigUrl` (override the
61
+ files next to the container), `warmup: false`. `client.embedMany(texts)` runs queries one after another (the runtime is
62
+ batch 1). `client.embedWithStats(text)` adds the token count and the milliseconds. `clearCache(url)` removes a cached file.
63
+
64
+ ### In a Web Worker
65
+
66
+ The package touches no DOM. Load the client in a worker to keep the page responsive during the ~1–3 s of upload and
67
+ pipeline compilation:
68
+
69
+ ```js
70
+ // worker.js
71
+ import { loadVqwClient } from '@thinletterio/vqweb';
72
+ let client;
73
+ onmessage = async ({ data }) => {
74
+ if (data.load) { client = await loadVqwClient(data.load, { onProgress: (p) => postMessage({ progress: p }) }); postMessage({ ready: client.info }); }
75
+ if (data.embed) postMessage({ id: data.id, vec: await client.embed(data.embed) });
76
+ };
77
+ ```
78
+
79
+ ### React
80
+
81
+ ```jsx
82
+ const [client, setClient] = useState(null);
83
+ useEffect(() => { let c; loadVqwClient(URL).then((x) => setClient(c = x)); return () => c?.dispose(); }, []);
84
+ ```
85
+
86
+ ## Which file
87
+
88
+ | file | base model (the index must be built with it) | bits / weight | size | keeps of fp32 nDCG@10 |
89
+ |---|---|---|---|---|
90
+ | `harrier-0.6b-vq2.0p-scifact.vqw` | microsoft/harrier-oss-v1-0.6b | 2.10 + prompt K/V | 122 MiB | SciFact 98.1 % |
91
+ | `harrier-0.6b-vq2.0-scidocs.vqw` | microsoft/harrier-oss-v1-0.6b | 2.10 | 127 MiB | SciDocs 94.7 % |
92
+ | `harrier-0.6b-vq1.75p-scifact.vqw` | microsoft/harrier-oss-v1-0.6b | 1.83 + prompt K/V | 107 MiB | SciFact 95.8 % |
93
+ | `qwen3-0.6b-vq3.5d2-webfaq_q-vocfull.vqw` | Qwen/Qwen3-Embedding-0.6B | 3.57 | 237 MiB | WebFAQ-cs 96.8 % |
94
+
95
+ All files: [thinletter/harrier-0.6b-vq-clients](https://huggingface.co/thinletter/harrier-0.6b-vq-clients) and
96
+ [thinletter/qwen3-embedding-0.6b-vq-clients](https://huggingface.co/thinletter/qwen3-embedding-0.6b-vq-clients). A file
97
+ calibrated on one corpus family transfers to similar text; for your own index the repository has the recipe to verify
98
+ (paired interval over your queries) and to compile a client calibrated on your corpus.
99
+
100
+ ## Numbers to expect
101
+
102
+ Integrated Intel GPU (Xe-LPG), Chrome: 103 ms per query for the 2.1-bit harrier file, 112 ms for the 3.6-bit Qwen3 file
103
+ (p50, ~30 tokens); load 2–3 s after the download; GPU memory = the file size plus ~40 MiB of activations. Discrete GPUs and
104
+ phones are not measured yet. The browser output equals the exporter's simulation of the same file to ±0.003 nDCG@10.
105
+
106
+ ## Advanced
107
+
108
+ The bundle exports the runtime modules unchanged (`parseVqw`, `VqwContainer`, `VqwRuntime`, `VqwTokenizer`,
109
+ `requestDevice`, `KERNELS`), so a bench or a layer test can drive the GPU pass directly; `client.embedTokens(ids,
110
+ { profile: true })` returns per-kernel GPU timestamps where the adapter supports them. Source, format description and
111
+ verification ladder: [`client/vqweb`](https://github.com/rosecky/embedding-quantization-public/tree/main/client/vqweb)
112
+ in the repository; this package is built from it by `packages/vqweb/build.mjs`.
113
+
114
+ ## Licence
115
+
116
+ Apache-2.0 (see LICENSE and NOTICE: bundles `@huggingface/tokenizers` 0.2.0, Apache-2.0, and a Q2_K decoder ported from
117
+ llama.cpp's gguf-py, MIT). The model files carry the licence of their base model (MIT for harrier, Apache-2.0 for
118
+ Qwen3-Embedding). Contact: info@thinletter.io
@@ -0,0 +1,131 @@
1
+ // Type declarations of @thinletter/vqweb (hand-written; the bundle is plain ES2022).
2
+ /// <reference types="@webgpu/types" />
3
+
4
+ export const VERSION: string;
5
+
6
+ export interface ProgressEvent {
7
+ /** download | upload | tokenizer | pipelines | warmup | ready */
8
+ phase: string;
9
+ loaded: number;
10
+ total: number;
11
+ }
12
+
13
+ export interface LoadOptions {
14
+ /** 'opfs' (default): keep the container and the tokenizer in the origin's private file system for the next visit; 'none': memory only. */
15
+ cache?: 'opfs' | 'none';
16
+ onProgress?: (p: ProgressEvent) => void;
17
+ /** Override tokenizer.json (default: the header's file name next to the container, falling back to tokenizer.json). */
18
+ tokenizerUrl?: string;
19
+ tokenizerConfigUrl?: string;
20
+ /** An existing GPUDevice with the shader-f16 feature; it is not destroyed by dispose(). */
21
+ device?: GPUDevice;
22
+ /** Adapter choice when the client creates the device (default 'low-power' = the integrated GPU where there is a choice). */
23
+ powerPreference?: 'low-power' | 'high-performance';
24
+ /** One untimed query after the pipelines compile (default true). */
25
+ warmup?: boolean;
26
+ /** Advanced runtime options: resid 'f32' | 'f16', tmax, tile, usePrefix. */
27
+ runtime?: Record<string, unknown>;
28
+ }
29
+
30
+ export interface AdapterInfo {
31
+ vendor?: string; architecture?: string; device?: string; description?: string;
32
+ shader_f16?: boolean; subgroups?: boolean; timestamp_query?: boolean;
33
+ maxComputeWorkgroupStorageSize?: number; maxStorageBufferBindingSize?: number; maxBufferSize?: number; maxComputeInvocationsPerWorkgroup?: number;
34
+ }
35
+
36
+ export interface ClientInfo {
37
+ file: { url: string; name: string; bytes: number; cached: boolean; persisted: boolean };
38
+ model: { teacher: string; hf: string | null; arch: string; layers: number; hidden: number; prompt: string; addEos: boolean; maxLen: number; prefixTokens: number; pooling: string };
39
+ quant: { method: string; bits: number; k: number; dim: number; bpwBlocks: number | null; calib: string | null; blocksize: number };
40
+ tokenizer: { rows: number; full: number | null; file: string; fallback: boolean };
41
+ adapter: AdapterInfo | null;
42
+ gpuBytes: number; weightBytes: number; activationBytes: number;
43
+ timing: { download_s: number; upload_s: number; tokenizer_s: number; pipelines_s: number; warmup_s: number };
44
+ version: string;
45
+ }
46
+
47
+ export interface EmbedResult {
48
+ /** The raw (not normalised) pooled vector. */
49
+ embedding: Float32Array;
50
+ /** Query tokens after the stored prompt K/V were cut (if the container carries them). */
51
+ T: number;
52
+ /** Prefix tokens taken from the container's stored K/V (0 = plain path). */
53
+ PP: number;
54
+ /** Wall-clock milliseconds of the GPU pass including the readback. */
55
+ ms: number;
56
+ dispatches: number;
57
+ profile?: { by_kind_ms: Record<string, number>; gpu_total_ms: number; span_ms: number };
58
+ }
59
+
60
+ export declare class VqwClient {
61
+ readonly info: ClientInfo;
62
+ readonly device: GPUDevice;
63
+ /** Advanced handles to the bundled runtime modules. */
64
+ readonly container: VqwContainer;
65
+ readonly runtime: VqwRuntime;
66
+ readonly tokenizer: VqwTokenizer;
67
+ readonly disposed: boolean;
68
+ /** Query text (without the prompt: the container applies its own) -> token ids on the container's table. */
69
+ tokenize(text: string): number[];
70
+ /** Raw runtime call on token ids. */
71
+ embedTokens(ids: number[], opts?: { profile?: boolean; debug?: boolean }): Promise<EmbedResult>;
72
+ /** One query -> L2-normalised Float32Array(hidden). */
73
+ embed(text: string): Promise<Float32Array>;
74
+ /** Several queries, one after another (the runtime is batch 1). */
75
+ embedMany(texts: string[]): Promise<Float32Array[]>;
76
+ embedWithStats(text: string): Promise<{ embedding: Float32Array; tokens: number; ms: number; gpuMs: number }>;
77
+ /** Free the GPU buffers (and the device when this client created it). */
78
+ dispose(): void;
79
+ }
80
+
81
+ /** Load a .vqw container (plain URL or a <file>.chunks.json byte-chunk manifest) and prepare it for queries. */
82
+ export function loadVqwClient(url: string, opts?: LoadOptions): Promise<VqwClient>;
83
+
84
+ /** Can this browser run a client? Requests an adapter, keeps no device. */
85
+ export function probeWebGPU(opts?: { powerPreference?: 'low-power' | 'high-performance' }): Promise<{
86
+ ok: boolean; reason: string | null; adapter: { vendor?: string; architecture?: string; device?: string; description?: string } | null; shaderF16: boolean | null;
87
+ }>;
88
+
89
+ /** Remove a cached container (by URL or file name) from this origin's private file system. */
90
+ export function clearCache(urlOrName: string): Promise<boolean>;
91
+
92
+ export function l2normalize(v: Float32Array | number[]): Float32Array;
93
+
94
+ // ---- advanced: the runtime modules as bundled (client/vqweb in the repository) --------------------------------------------------
95
+ export interface ParsedVqw {
96
+ header: any; dataStart: number; bytes: Uint8Array;
97
+ raw(name: string): Uint8Array;
98
+ view(name: string): Uint8Array | Uint16Array | Uint32Array | Int8Array | Int32Array | Float32Array;
99
+ }
100
+ export function parseVqw(data: ArrayBuffer | Uint8Array): ParsedVqw;
101
+ export function fetchVqw(url: string, onProgress?: (loaded: number, total: number) => void): Promise<ArrayBuffer>;
102
+ export function requestDevice(opts?: { powerPreference?: 'low-power' | 'high-performance'; label?: string }): Promise<{ adapter: GPUAdapter; device: GPUDevice; info: AdapterInfo }>;
103
+ export declare class VqwContainer {
104
+ constructor(parsed: ParsedVqw, device: GPUDevice);
105
+ static load(url: string, device: GPUDevice, opts?: { onProgress?: (loaded: number, total: number) => void }): Promise<VqwContainer>;
106
+ readonly header: any; readonly model: any; readonly quant: any; readonly rotation: any; readonly tokens: any; readonly prefix: { ids: number[]; tokens: number; text: string } | null;
107
+ readonly gpuBytes: number;
108
+ linear(prefix: string): any; norm(name: string): GPUBuffer; rot(n: number): any; prefixKV(li: number): { k: GPUBuffer; v: GPUBuffer } | null;
109
+ release(): void; destroy(): void;
110
+ }
111
+ export declare class VqwRuntime {
112
+ constructor(container: VqwContainer, device: GPUDevice, opts?: Record<string, unknown>);
113
+ static create(container: VqwContainer, device: GPUDevice, opts?: Record<string, unknown>): Promise<VqwRuntime>;
114
+ readonly actBytes: number; readonly tmax: number;
115
+ embed(ids: number[], opts?: { profile?: boolean; debug?: boolean }): Promise<EmbedResult>;
116
+ destroy(): void;
117
+ }
118
+ export declare class VqwTokenizer {
119
+ constructor(tokenizerJSON: any, tokenizerConfig: any, header: any, keptIds: Iterable<number>);
120
+ encode(query: string): number[];
121
+ encodeFull(text: string): number[];
122
+ retokenize(ids: number[]): number[];
123
+ decodeOne(id: number): string;
124
+ }
125
+ export const KERNELS: Record<string, string>;
126
+ export function loadModelBytes(url: string, opts?: { cache?: 'opfs' | 'none'; onProgress?: (loaded: number, total: number) => void }): Promise<{ buffer: ArrayBuffer; bytes: number; cached: boolean; persisted: boolean; name: string }>;
127
+ export function loadTokenizerFiles(containerUrl: string, header: any, opts?: { tokenizerUrl?: string; tokenizerConfigUrl?: string; cache?: 'opfs' | 'none' }): Promise<{ tokenizerJSON: any; tokenizerConfig: any; fallback: boolean }>;
128
+ export function fetchWithProgress(url: string, onProgress?: (loaded: number, total: number) => void, expectedBytes?: number | null): Promise<Uint8Array>;
129
+ export function opfsGet(name: string, size: number | null): Promise<File | null>;
130
+ export function opfsPut(name: string, parts: Array<Blob | ArrayBuffer | Uint8Array | string>): Promise<File | null>;
131
+ export function opfsRemove(name: string): Promise<boolean>;