@qvac/sdk 0.22.0 → 0.24.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.
Files changed (284) hide show
  1. package/NOTICE +194 -97
  2. package/README.md +29 -470
  3. package/dist/examples/asr/parakeet-sortformer.js +24 -14
  4. package/dist/examples/asr/parakeet-transcribepsy-filesystem.d.ts +2 -0
  5. package/dist/examples/asr/parakeet-transcribepsy-filesystem.js +105 -0
  6. package/dist/examples/asr/parakeet-unified-coreml.js +14 -9
  7. package/dist/examples/asr/whispercpp-prompt.js +9 -5
  8. package/dist/examples/assess-model-fit.d.ts +7 -9
  9. package/dist/examples/assess-model-fit.js +22 -43
  10. package/dist/examples/calc-tokens.d.ts +2 -0
  11. package/dist/examples/calc-tokens.js +21 -0
  12. package/dist/examples/classification/classify-image.js +11 -5
  13. package/dist/examples/completion-stop-reason.d.ts +3 -3
  14. package/dist/examples/completion-stop-reason.js +4 -4
  15. package/dist/examples/diffusion-flux3-klein.d.ts +2 -0
  16. package/dist/examples/diffusion-flux3-klein.js +102 -0
  17. package/dist/examples/diffusion-img2vid-ltx.js +7 -14
  18. package/dist/examples/diffusion-moss-image.d.ts +2 -0
  19. package/dist/examples/diffusion-moss-image.js +126 -0
  20. package/dist/examples/diffusion-qwen-image-21.d.ts +2 -0
  21. package/dist/examples/diffusion-qwen-image-21.js +115 -0
  22. package/dist/examples/diffusion-txt2vid-ltx.js +7 -14
  23. package/dist/examples/embed-multimodal.d.ts +2 -0
  24. package/dist/examples/embed-multimodal.js +80 -0
  25. package/dist/examples/embed-p2p.js +2 -2
  26. package/dist/examples/finetune/llamacpp-finetune.js +9 -4
  27. package/dist/examples/image/megaloc.d.ts +2 -0
  28. package/dist/examples/image/megaloc.js +37 -0
  29. package/dist/examples/llamacpp-multimodal.js +21 -1
  30. package/dist/examples/mcp-websearch.js +1 -1
  31. package/dist/examples/plugins.js +1 -1
  32. package/dist/examples/rag/rag-hyperdb/pipeline.js +2 -2
  33. package/dist/examples/rag/rag-turbovec.js +2 -2
  34. package/dist/examples/rerank.d.ts +2 -0
  35. package/dist/examples/rerank.js +33 -0
  36. package/dist/examples/sessions.d.ts +17 -0
  37. package/dist/examples/sessions.js +63 -0
  38. package/dist/examples/tools/llamacpp-deferred-tools.js +12 -8
  39. package/dist/examples/tools/llamacpp-tools-auto-dialect.js +4 -3
  40. package/dist/examples/tools/llamacpp-tools-gemma4.js +3 -3
  41. package/dist/examples/tools/llamacpp-tools-qwen35.js +4 -3
  42. package/dist/scripts/check-resource-collectors-packaging.js +7 -6
  43. package/dist/scripts/contract/build-contract.d.ts +2 -1
  44. package/dist/scripts/contract/build-contract.js +13 -1
  45. package/dist/scripts/contract/constants-registry.d.ts +19 -0
  46. package/dist/scripts/contract/constants-registry.js +9 -2
  47. package/dist/scripts/contract/method-shapes.d.ts +5 -0
  48. package/dist/scripts/contract/method-shapes.js +5 -0
  49. package/dist/scripts/enforce-inference-versions.d.ts +1 -1
  50. package/dist/scripts/enforce-inference-versions.js +28 -18
  51. package/dist/scripts/generate-bare-kit-runtimes.js +101 -69
  52. package/dist/src/client/api/assess-model-fit.d.ts +17 -17
  53. package/dist/src/client/api/assess-model-fit.js +19 -32
  54. package/dist/src/client/api/audio-edit.d.ts +5 -3
  55. package/dist/src/client/api/audio-edit.js +7 -5
  56. package/dist/src/client/api/audio-gen-result.js +136 -47
  57. package/dist/src/client/api/audio-gen.d.ts +40 -3
  58. package/dist/src/client/api/audio-gen.js +42 -5
  59. package/dist/src/client/api/audio-understand.d.ts +2 -2
  60. package/dist/src/client/api/audio-understand.js +4 -4
  61. package/dist/src/client/api/batch-completion.js +4 -3
  62. package/dist/src/client/api/bci-transcribe.js +3 -3
  63. package/dist/src/client/api/calc-tokens.d.ts +33 -0
  64. package/dist/src/client/api/calc-tokens.js +44 -0
  65. package/dist/src/client/api/cancel.d.ts +2 -2
  66. package/dist/src/client/api/cancel.js +3 -3
  67. package/dist/src/client/api/classify.d.ts +12 -5
  68. package/dist/src/client/api/classify.js +18 -6
  69. package/dist/src/client/api/client-request-id.d.ts +0 -15
  70. package/dist/src/client/api/client-request-id.js +15 -12
  71. package/dist/src/client/api/completion-stream.d.ts +9 -1
  72. package/dist/src/client/api/completion-stream.js +14 -3
  73. package/dist/src/client/api/decide.d.ts +1 -1
  74. package/dist/src/client/api/decide.js +3 -3
  75. package/dist/src/client/api/delete-cache.d.ts +9 -2
  76. package/dist/src/client/api/delete-cache.js +14 -4
  77. package/dist/src/client/api/diffusion.d.ts +38 -5
  78. package/dist/src/client/api/diffusion.js +42 -7
  79. package/dist/src/client/api/download-asset.js +3 -3
  80. package/dist/src/client/api/embed.d.ts +82 -29
  81. package/dist/src/client/api/embed.js +66 -21
  82. package/dist/src/client/api/finetune.js +3 -3
  83. package/dist/src/client/api/get-loaded-model-info.js +1 -1
  84. package/dist/src/client/api/get-model-info.d.ts +2 -2
  85. package/dist/src/client/api/get-model-info.js +3 -3
  86. package/dist/src/client/api/get-system-resources.d.ts +2 -2
  87. package/dist/src/client/api/get-system-resources.js +3 -3
  88. package/dist/src/client/api/heartbeat.d.ts +3 -2
  89. package/dist/src/client/api/heartbeat.js +4 -3
  90. package/dist/src/client/api/index.d.ts +8 -6
  91. package/dist/src/client/api/index.js +6 -4
  92. package/dist/src/client/api/invoke-plugin.d.ts +8 -2
  93. package/dist/src/client/api/invoke-plugin.js +18 -3
  94. package/dist/src/client/api/load-model.js +9 -6
  95. package/dist/src/client/api/logging-stream.d.ts +11 -2
  96. package/dist/src/client/api/logging-stream.js +12 -3
  97. package/dist/src/client/api/ocr.d.ts +5 -3
  98. package/dist/src/client/api/ocr.js +45 -22
  99. package/dist/src/client/api/rag.d.ts +1 -1
  100. package/dist/src/client/api/rag.js +3 -3
  101. package/dist/src/client/api/registry.d.ts +19 -8
  102. package/dist/src/client/api/registry.js +43 -17
  103. package/dist/src/client/api/rerank.d.ts +22 -0
  104. package/dist/src/client/api/rerank.js +39 -0
  105. package/dist/src/client/api/resume.d.ts +2 -1
  106. package/dist/src/client/api/resume.js +3 -3
  107. package/dist/src/client/api/rpc-server.d.ts +4 -4
  108. package/dist/src/client/api/rpc-server.js +12 -12
  109. package/dist/src/client/api/state.d.ts +2 -2
  110. package/dist/src/client/api/state.js +3 -3
  111. package/dist/src/client/api/subscribe-logs.d.ts +2 -2
  112. package/dist/src/client/api/subscribe-logs.js +4 -3
  113. package/dist/src/client/api/suspend.d.ts +4 -2
  114. package/dist/src/client/api/suspend.js +5 -4
  115. package/dist/src/client/api/text-to-speech.d.ts +14 -5
  116. package/dist/src/client/api/text-to-speech.js +86 -32
  117. package/dist/src/client/api/transcribe.d.ts +7 -3
  118. package/dist/src/client/api/transcribe.js +9 -3
  119. package/dist/src/client/api/translate.js +2 -2
  120. package/dist/src/client/api/unload-model.d.ts +19 -7
  121. package/dist/src/client/api/unload-model.js +31 -13
  122. package/dist/src/client/api/upscale.d.ts +6 -3
  123. package/dist/src/client/api/upscale.js +10 -5
  124. package/dist/src/client/api/vector-index.d.ts +51 -17
  125. package/dist/src/client/api/vector-index.js +101 -49
  126. package/dist/src/client/api/video-request.d.ts +5 -5
  127. package/dist/src/client/api/video.d.ts +3 -2
  128. package/dist/src/client/api/video.js +6 -5
  129. package/dist/src/client/api/vla.d.ts +9 -5
  130. package/dist/src/client/api/vla.js +17 -8
  131. package/dist/src/client/api/world-result.js +2 -2
  132. package/dist/src/client/api/world.d.ts +6 -6
  133. package/dist/src/client/api/world.js +6 -6
  134. package/dist/src/client/init-hooks.d.ts +6 -4
  135. package/dist/src/client/init-hooks.js +12 -15
  136. package/dist/src/client/logging-stream-registry.d.ts +6 -3
  137. package/dist/src/client/logging-stream-registry.js +36 -14
  138. package/dist/src/client/plugins-factory.d.ts +1 -1
  139. package/dist/src/client/plugins-factory.js +1 -1
  140. package/dist/src/client/rpc/bundle-stamp.d.ts +29 -0
  141. package/dist/src/client/rpc/bundle-stamp.js +75 -0
  142. package/dist/src/client/rpc/expo-home-dir.d.ts +2 -0
  143. package/dist/src/client/rpc/expo-home-dir.js +4 -0
  144. package/dist/src/client/rpc/expo-rpc-client.js +192 -138
  145. package/dist/src/client/rpc/node-rpc-client.js +324 -426
  146. package/dist/src/client/rpc/pear-runtime.d.ts +12 -0
  147. package/dist/src/client/rpc/pear-runtime.js +12 -0
  148. package/dist/src/client/rpc/rpc-client.d.ts +6 -4
  149. package/dist/src/client/rpc/rpc-client.js +168 -31
  150. package/dist/src/client/rpc/rpc-error.js +24 -2
  151. package/dist/src/client/rpc/unbundled-harness.d.ts +16 -0
  152. package/dist/src/client/rpc/unbundled-harness.js +27 -0
  153. package/dist/src/client/rpc/worker-failure.d.ts +27 -0
  154. package/dist/src/client/rpc/worker-failure.js +61 -0
  155. package/dist/src/client/session-registry.d.ts +75 -0
  156. package/dist/src/client/session-registry.js +149 -0
  157. package/dist/src/client/session.d.ts +125 -0
  158. package/dist/src/client/session.js +148 -0
  159. package/dist/src/commands/bundle/addons.d.ts +14 -0
  160. package/dist/src/commands/bundle/addons.js +65 -0
  161. package/dist/src/commands/bundle/constants.js +2 -0
  162. package/dist/src/commands/bundle/entry-gen.d.ts +1 -5
  163. package/dist/src/commands/bundle/entry-gen.js +18 -51
  164. package/dist/src/commands/bundle/index.d.ts +60 -14
  165. package/dist/src/commands/bundle/index.js +350 -126
  166. package/dist/src/commands/bundle/link.d.ts +58 -0
  167. package/dist/src/commands/bundle/link.js +135 -0
  168. package/dist/src/commands/bundle/node-support.d.ts +13 -0
  169. package/dist/src/commands/bundle/node-support.js +23 -0
  170. package/dist/src/commands/bundle/plugins.js +1 -1
  171. package/dist/src/commands/bundle/read-bundle.d.ts +9 -0
  172. package/dist/src/commands/bundle/read-bundle.js +27 -0
  173. package/dist/src/commands/bundle/resolve-sdk-import.d.ts +6 -0
  174. package/dist/src/commands/bundle/resolve-sdk-import.js +24 -28
  175. package/dist/src/commands/bundle/scratch.d.ts +35 -0
  176. package/dist/src/commands/bundle/scratch.js +178 -0
  177. package/dist/src/commands/bundle/targets.d.ts +14 -0
  178. package/dist/src/commands/bundle/targets.js +37 -0
  179. package/dist/src/commands/host-prebuilds/index.d.ts +8 -7
  180. package/dist/src/commands/host-prebuilds/index.js +13 -11
  181. package/dist/src/commands/index.d.ts +13 -12
  182. package/dist/src/commands/index.js +7 -7
  183. package/dist/src/commands/verify/abi.d.ts +21 -15
  184. package/dist/src/commands/verify/abi.js +12 -80
  185. package/dist/src/commands/verify/bare-kit-runtime.d.ts +20 -22
  186. package/dist/src/commands/verify/bare-kit-runtime.js +102 -150
  187. package/dist/src/commands/verify/bare-kit-runtimes.d.ts +10 -9
  188. package/dist/src/commands/verify/bare-kit-runtimes.js +21 -21
  189. package/dist/src/commands/verify/bundle-source.d.ts +1 -1
  190. package/dist/src/commands/verify/bundle-source.js +27 -23
  191. package/dist/src/commands/verify/engines-advice.d.ts +6 -12
  192. package/dist/src/commands/verify/engines-advice.js +9 -56
  193. package/dist/src/commands/verify/index.d.ts +34 -33
  194. package/dist/src/commands/verify/index.js +96 -204
  195. package/dist/src/commands/verify/node-modules-source.d.ts +1 -1
  196. package/dist/src/commands/verify/node-modules-source.js +1 -1
  197. package/dist/src/commands/verify/prebuilds.d.ts +4 -6
  198. package/dist/src/commands/verify/prebuilds.js +3 -4
  199. package/dist/src/commands/verify/resource-collectors.d.ts +0 -6
  200. package/dist/src/commands/verify/resource-collectors.js +3 -52
  201. package/dist/src/commands/verify/sidecar-runtime.d.ts +6 -0
  202. package/dist/src/commands/verify/sidecar-runtime.js +51 -0
  203. package/dist/src/expo/plugins/get-project-root.d.ts +1 -1
  204. package/dist/src/expo/plugins/withAndroidArchitecture.d.ts +1 -1
  205. package/dist/src/expo/plugins/withAndroidNdkVersion.d.ts +1 -1
  206. package/dist/src/expo/plugins/withAndroidNdkVersion.js +16 -10
  207. package/dist/src/expo/plugins/withBareKit.d.ts +59 -0
  208. package/dist/src/expo/plugins/withBareKit.js +204 -0
  209. package/dist/src/expo/plugins/withDeviceInfo.d.ts +1 -1
  210. package/dist/src/expo/plugins/withDeviceInfo.js +19 -5
  211. package/dist/src/expo/plugins/withMobileBundle.d.ts +5 -12
  212. package/dist/src/expo/plugins/withMobileBundle.js +38 -59
  213. package/dist/src/expo/plugins/withOpenCL.d.ts +1 -1
  214. package/dist/src/expo/plugins/withQvacSDK.d.ts +2 -1
  215. package/dist/src/expo/plugins/withQvacSDK.js +3 -0
  216. package/dist/src/index.d.ts +6 -5
  217. package/dist/src/index.js +10 -14
  218. package/dist/src/logging/addon.d.ts +1 -1
  219. package/dist/src/logging/base-logger.js +1 -1
  220. package/dist/src/logging/utils.js +11 -3
  221. package/dist/src/plugin-ids.d.ts +3 -1
  222. package/dist/src/plugin-ids.js +4 -0
  223. package/dist/src/schemas/public.d.ts +1 -1
  224. package/dist/src/schemas/public.js +1 -1
  225. package/dist/src/schemas/sdk-errors-client.d.ts +5 -6
  226. package/dist/src/schemas/sdk-errors-client.js +30 -36
  227. package/dist/src/schemas/sdk-errors-server.d.ts +12 -1
  228. package/dist/src/schemas/sdk-errors-server.js +65 -2
  229. package/dist/src/server/rpc/rpc-utils.d.ts +26 -0
  230. package/dist/src/server/rpc/rpc-utils.js +41 -0
  231. package/dist/src/utils/aggregate-events.d.ts +1 -1
  232. package/dist/src/utils/aggregate-events.js +2 -2
  233. package/dist/src/utils/errors-client.d.ts +37 -29
  234. package/dist/src/utils/errors-client.js +50 -41
  235. package/dist/src/utils/errors-server.d.ts +65 -1
  236. package/dist/src/utils/errors-server.js +122 -1
  237. package/dist/src/utils/mcp-adapter.d.ts +1 -1
  238. package/dist/src/utils/mcp-adapter.js +1 -1
  239. package/dist/src/utils/tool-helpers.js +1 -1
  240. package/dist/src/utils/withTimeout.js +34 -17
  241. package/dist/src/worker/handle-request.js +26 -21
  242. package/dist/src/worker/handler-utils.d.ts +2 -6
  243. package/dist/src/worker/handler-utils.js +2 -20
  244. package/dist/src/worker/index.d.ts +2 -4
  245. package/dist/src/worker/index.js +24 -34
  246. package/dist/src/worker/plugins/ggml-image-embedding.d.ts +2 -0
  247. package/dist/src/worker/plugins/ggml-image-embedding.js +1 -0
  248. package/dist/src/worker/plugins/llamacpp-rerank.d.ts +2 -0
  249. package/dist/src/worker/plugins/llamacpp-rerank.js +1 -0
  250. package/dist/src/worker/shim.d.ts +4 -0
  251. package/dist/src/worker/shim.js +7 -0
  252. package/dist/src/worker/start.d.ts +9 -0
  253. package/dist/src/worker/start.js +16 -0
  254. package/dist/src/worker/unbundled-shim.d.ts +2 -0
  255. package/dist/src/worker/unbundled-shim.js +4 -0
  256. package/docs/system-resources-support-matrix.md +27 -19
  257. package/package.json +91 -74
  258. package/src/electron-forge/index.cjs +65 -91
  259. package/dist/examples/model-fit-ui/server.d.ts +0 -24
  260. package/dist/examples/model-fit-ui/server.js +0 -221
  261. package/dist/src/client/rpc/ensure-worker-ready.d.ts +0 -9
  262. package/dist/src/client/rpc/ensure-worker-ready.js +0 -17
  263. package/dist/src/client/rpc/init-timeout.d.ts +0 -26
  264. package/dist/src/client/rpc/init-timeout.js +0 -25
  265. package/dist/src/client/rpc/worker-startup-error.d.ts +0 -12
  266. package/dist/src/client/rpc/worker-startup-error.js +0 -13
  267. package/dist/src/commands/bundle/bare-pack.d.ts +0 -21
  268. package/dist/src/commands/bundle/bare-pack.js +0 -77
  269. package/dist/src/commands/bundle/manifest.d.ts +0 -25
  270. package/dist/src/commands/bundle/manifest.js +0 -192
  271. package/dist/src/expo/plugins/link-addons.d.ts +0 -18
  272. package/dist/src/expo/plugins/link-addons.js +0 -65
  273. package/dist/src/pear/pre.d.ts +0 -21
  274. package/dist/src/pear/pre.js +0 -448
  275. package/dist/src/server/env.d.ts +0 -22
  276. package/dist/src/server/env.js +0 -59
  277. package/dist/src/server/utils/qvac-paths.d.ts +0 -2
  278. package/dist/src/server/utils/qvac-paths.js +0 -5
  279. package/dist/src/server/utils/worker-lock.d.ts +0 -3
  280. package/dist/src/server/utils/worker-lock.js +0 -67
  281. package/dist/src/worker/create-server.d.ts +0 -8
  282. package/dist/src/worker/create-server.js +0 -51
  283. package/dist/src/worker/lifecycle.d.ts +0 -23
  284. package/dist/src/worker/lifecycle.js +0 -149
@@ -0,0 +1,126 @@
1
+ import { close, diffusion, loadModel, unloadModel } from '@qvac/sdk';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ // Generate a poster from a MOSS-Image JSON layout prompt.
5
+ // Use the pinned model revisions from the diffusion addon's MOSS-Image downloader.
6
+ // Model terms (Apache-2.0): https://huggingface.co/OpenMOSS-Team/MOSS-Image-SFT
7
+ const HF = 'https://huggingface.co';
8
+ const mossRepo = `${HF}/Comfy-Org/MOSS-Image/resolve/530a4c94f92c35ef6818b1b035a983fe9dcf5f54`;
9
+ const outputDir = process.argv[2] || '.';
10
+ const diffusionModelSrc = process.argv[3] || `${mossRepo}/diffusion_models/moss_image_sft_bf16.safetensors`;
11
+ const llmModelSrc = process.argv[4] ||
12
+ `${HF}/unsloth/Qwen3.5-9B-GGUF/resolve/3885219b6810b007914f3a7950a8d1b469d598a5/Qwen3.5-9B-Q4_K_M.gguf`;
13
+ const vaeModelSrc = process.argv[5] || `${mossRepo}/vae/flux2-vae_small.safetensors`;
14
+ const tokenizerSrc = process.argv[6] ||
15
+ `${HF}/OpenMOSS-Team/MOSS-Image-SFT/resolve/f972bd4b4b9e3852133cc5da954d87bc32cd8fb9/tokenizer/tokenizer.json`;
16
+ const usage = 'Usage: node --import tsx examples/diffusion-moss-image.ts [outputDir] [model] [llm] [vae] [tokenizer]';
17
+ if (process.argv.includes('--help')) {
18
+ console.log(usage);
19
+ console.log('▸ Defaults download pinned Hugging Face weights. Model overrides accept paths or URLs.');
20
+ process.exit(0);
21
+ }
22
+ const width = 1024;
23
+ const height = 1024;
24
+ // Boxes are [y_min, x_min, y_max, x_max] in absolute pixels with the canvas
25
+ // centre as the origin, so a 1024×1024 canvas spans -512..512 on both axes.
26
+ // Keep them consistent with width and height.
27
+ const layout = {
28
+ summary: {
29
+ meta: ['poster'],
30
+ canvas: 'single',
31
+ caption: 'A minimalist travel poster of a snowy mountain at sunrise, flat illustration style.'
32
+ },
33
+ items: [
34
+ {
35
+ label: 'text',
36
+ caption: 'Bold white sans-serif title across the top of the poster.',
37
+ text: 'SUMMIT',
38
+ bbox: [-448, -352, -320, 352]
39
+ },
40
+ {
41
+ label: 'object',
42
+ caption: 'A snowy mountain peak lit by an orange sunrise.',
43
+ bbox: [-224, -320, 384, 320]
44
+ }
45
+ ],
46
+ bbox_coord_space: 'abs_centralized',
47
+ bbox_format: 'yxyx'
48
+ };
49
+ function modelSource(source) {
50
+ return /^https?:\/\//.test(source) ? source : path.resolve(source);
51
+ }
52
+ let modelId;
53
+ // Progress fires many times per percent on a multi-GB download; write once per whole percent
54
+ // of each file.
55
+ const lastPercent = new Map();
56
+ try {
57
+ console.log('▸ Loading MOSS-Image...');
58
+ modelId = await loadModel({
59
+ modelSrc: modelSource(diffusionModelSrc),
60
+ modelType: 'sdcpp-generation',
61
+ modelConfig: {
62
+ llmModelSrc: modelSource(llmModelSrc),
63
+ vaeModelSrc: modelSource(vaeModelSrc),
64
+ tokenizerSrc: modelSource(tokenizerSrc),
65
+ flash_attn: true
66
+ },
67
+ onProgress: (progress) => {
68
+ const percent = Math.floor(progress.percentage);
69
+ if (lastPercent.get(progress.downloadKey) === percent)
70
+ return;
71
+ lastPercent.set(progress.downloadKey, percent);
72
+ const mb = (bytes) => (bytes / 1e6).toFixed(1);
73
+ const line = `▸ Downloading ${progress.percentage.toFixed(0)}% (${mb(progress.downloaded)}/${mb(progress.total)} MB)`;
74
+ process.stderr.write(process.stderr.isTTY ? `\r${line}` : `${line}\n`);
75
+ if (progress.percentage >= 100)
76
+ process.stderr.write('\n');
77
+ }
78
+ });
79
+ console.log(`▸ Model loaded: ${modelId}`);
80
+ const { progressStream, outputs, stats } = diffusion({
81
+ modelId,
82
+ prompt: JSON.stringify(layout),
83
+ width,
84
+ height,
85
+ steps: 50,
86
+ cfg_scale: 3,
87
+ sampling_method: 'euler',
88
+ scheduler: 'discrete',
89
+ seed: 42
90
+ });
91
+ for await (const { step, totalSteps } of progressStream) {
92
+ console.log(`▸ step ${step}/${totalSteps}`);
93
+ }
94
+ const buffers = await outputs;
95
+ if (buffers.length === 0)
96
+ throw new Error('MOSS-Image returned no image.');
97
+ for (let i = 0; i < buffers.length; i++) {
98
+ const outputPath = path.join(outputDir, `moss_image_${i}.png`);
99
+ fs.writeFileSync(outputPath, buffers[i]);
100
+ console.log(`▸ Saved ${outputPath}`);
101
+ }
102
+ console.log('▸ Stats:', await stats);
103
+ }
104
+ catch (error) {
105
+ console.error('✖', error);
106
+ process.exitCode = 1;
107
+ }
108
+ finally {
109
+ try {
110
+ if (modelId)
111
+ await unloadModel({ modelId, clearStorage: false });
112
+ }
113
+ catch (error) {
114
+ console.error('✖ Unload failed:', error);
115
+ process.exitCode = 1;
116
+ }
117
+ try {
118
+ await close();
119
+ }
120
+ catch (error) {
121
+ console.error('✖ Cleanup failed:', error);
122
+ process.exitCode = 1;
123
+ }
124
+ }
125
+ if (!process.exitCode)
126
+ console.log('▸ Done');
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=diffusion-qwen-image-21.d.ts.map
@@ -0,0 +1,115 @@
1
+ import { close, diffusion, loadModel, unloadModel } from '@qvac/sdk';
2
+ import fs from 'fs';
3
+ import path from 'path';
4
+ // Combine two references into an RGBA image, with optional Qwen-Image-2.1-Turbo sampling.
5
+ // Set QWEN_TURBO=1 and pass Turbo weights as the model argument, as a path or URL.
6
+ // Use the pinned model revisions from the diffusion addon's Qwen-Image-2.1 downloader.
7
+ // Model terms: https://huggingface.co/Qwen/Qwen-Image-2.1/blob/d26bb61231c349cf6b7896fa83353113880e1ba3/LICENSE
8
+ const turbo = process.env['QWEN_TURBO'] === '1';
9
+ const HF = 'https://huggingface.co';
10
+ const encoderRepo = `${HF}/Qwen/Qwen3-VL-8B-Instruct-GGUF/resolve/f982a07559d4a2f6c8744d840bf6fccab30eea96`;
11
+ const referencePathA = process.argv[2];
12
+ const referencePathB = process.argv[3];
13
+ const prompt = process.argv[4] ||
14
+ 'Place the subjects from both reference images side by side. Generate an RGBA image with a transparent background and no scenery.';
15
+ const outputDir = process.argv[5] || '.';
16
+ const diffusionModelSrc = process.argv[6] ||
17
+ `${HF}/leejet/Qwen-Image-2.1-GGUF/resolve/cc11433936a06e9765f7c0c0b1f0436cfd2b9856/qwen_image_2.1-Q4_K.gguf`;
18
+ const llmModelSrc = process.argv[7] || `${encoderRepo}/Qwen3VL-8B-Instruct-Q4_K_M.gguf`;
19
+ const vaeModelSrc = process.argv[8] ||
20
+ `${HF}/Comfy-Org/Qwen-Image-2.1/resolve/a8342359c61979b06a8dafb1a47991fe1f30e994/vae/qwen_image_2.1_vae_bf16.safetensors`;
21
+ const projectionModelSrc = process.argv[9] || `${encoderRepo}/mmproj-Qwen3VL-8B-Instruct-F16.gguf`;
22
+ const usage = 'Usage: node --import tsx examples/diffusion-qwen-image-21.ts <referenceA> <referenceB> [prompt] [outputDir] [model] [llm] [vae] [projector]';
23
+ if (process.argv.includes('--help')) {
24
+ console.log(usage);
25
+ console.log('▸ Defaults download pinned Hugging Face weights. Model overrides accept paths or URLs.');
26
+ console.log('▸ Turbo: set QWEN_TURBO=1 and pass your Turbo weights as the model argument.');
27
+ console.log('▸ The default prompt combines both subjects on a transparent background.');
28
+ process.exit(0);
29
+ }
30
+ if (!referencePathA || !referencePathB) {
31
+ console.error('✖ two reference image paths are required');
32
+ console.error(usage);
33
+ process.exit(1);
34
+ }
35
+ if (turbo && !process.argv[6]) {
36
+ console.error('✖ Pass the Turbo diffusion weights as the model argument, as a path or URL');
37
+ process.exit(1);
38
+ }
39
+ function modelSource(source) {
40
+ return /^https?:\/\//.test(source) ? source : path.resolve(source);
41
+ }
42
+ let modelId;
43
+ try {
44
+ const init_images = [referencePathA, referencePathB].map((file) => new Uint8Array(fs.readFileSync(file)));
45
+ console.log('▸ Loading Qwen-Image-2.1 split-layout model...');
46
+ modelId = await loadModel({
47
+ modelSrc: modelSource(diffusionModelSrc),
48
+ modelType: 'sdcpp-generation',
49
+ modelConfig: {
50
+ llmModelSrc: modelSource(llmModelSrc),
51
+ vaeModelSrc: modelSource(vaeModelSrc),
52
+ projectionModelSrc: modelSource(projectionModelSrc),
53
+ flash_attn: true
54
+ },
55
+ onProgress: (progress) => {
56
+ const mb = (bytes) => (bytes / 1e6).toFixed(1);
57
+ const line = `▸ Downloading ${progress.percentage.toFixed(0)}% (${mb(progress.downloaded)}/${mb(progress.total)} MB)`;
58
+ process.stderr.write(process.stderr.isTTY ? `\r${line}` : `${line}\n`);
59
+ if (progress.percentage >= 100)
60
+ process.stderr.write('\n');
61
+ }
62
+ });
63
+ console.log(`▸ Model loaded: ${modelId}`);
64
+ console.log(`▸ Generating from "${referencePathA}" and "${referencePathB}": "${prompt}"`);
65
+ const { progressStream, outputs, stats } = diffusion({
66
+ modelId,
67
+ prompt,
68
+ init_images,
69
+ width: 512,
70
+ height: 512,
71
+ ...(!turbo && { steps: 30 }),
72
+ cfg_scale: turbo ? 1 : 6,
73
+ ...(turbo && {
74
+ // Official Turbo sample_sigmas plus the native terminal zero.
75
+ custom_sigmas: [1, 0.978453, 0.95418, 0.926626, 0.89508, 0.845148, 0.704534, 0.414568, 0]
76
+ }),
77
+ sampling_method: 'euler',
78
+ seed: 42
79
+ });
80
+ for await (const { step, totalSteps } of progressStream) {
81
+ console.log(`▸ step ${step}/${totalSteps}`);
82
+ }
83
+ const buffers = await outputs;
84
+ if (buffers.length === 0)
85
+ throw new Error('Qwen-Image-2.1 returned no image.');
86
+ for (let i = 0; i < buffers.length; i++) {
87
+ const outputPath = path.join(outputDir, `qwen_image_21${turbo ? '_turbo' : ''}_${i}.png`);
88
+ fs.writeFileSync(outputPath, buffers[i]);
89
+ console.log(`▸ Saved ${outputPath}`);
90
+ }
91
+ console.log('▸ Stats:', await stats);
92
+ }
93
+ catch (error) {
94
+ console.error('✖', error);
95
+ process.exitCode = 1;
96
+ }
97
+ finally {
98
+ try {
99
+ if (modelId)
100
+ await unloadModel({ modelId, clearStorage: false });
101
+ }
102
+ catch (error) {
103
+ console.error('✖ Unload failed:', error);
104
+ process.exitCode = 1;
105
+ }
106
+ try {
107
+ await close();
108
+ }
109
+ catch (error) {
110
+ console.error('✖ Cleanup failed:', error);
111
+ process.exitCode = 1;
112
+ }
113
+ }
114
+ if (!process.exitCode)
115
+ console.log('▸ Done');
@@ -1,4 +1,4 @@
1
- import { loadModel, unloadModel, video } from '@qvac/sdk';
1
+ import { GEMMA_3_12B_Q4_K_XL, loadModel, LTX_2_3_22B_DISTILLED_EMBEDDINGS_CONNECTORS, LTX_2_3_22B_Q5_K_M, LTX_2_3_AUDIO_VAE, LTX_2_3_VIDEO_VAE, unloadModel, video } from '@qvac/sdk';
2
2
  import fs from 'fs';
3
3
  import path from 'path';
4
4
  // Text-to-video (+ synchronized audio) with LTX-2. Unlike Wan, LTX-2 uses a
@@ -10,19 +10,12 @@ import path from 'path';
10
10
  // This example needs powerful hardware: LTX-2.3 is a ~21B model, budget at
11
11
  // least 20+ GB of video / unified memory.
12
12
  //
13
- // No LTX-2 model constants ship in the SDK registry, so the model sources
14
- // default to public HuggingFace URLs (the SDK downloads http(s) sources
15
- // directly). Pass your own paths / URLs via argv to override.
16
- const HF = 'https://huggingface.co';
17
- const diffusionModelSrc = process.argv[2] ||
18
- `${HF}/QuantStack/LTX-2.3-GGUF/resolve/main/LTX-2.3-distilled-1.1/LTX-2.3-22B-distilled-1.1-Q5_K_M.gguf`;
19
- const llmModelSrc = process.argv[3] || `${HF}/unsloth/gemma-3-12b-it-GGUF/resolve/main/gemma-3-12b-it-UD-Q4_K_XL.gguf`;
20
- const vaeModelSrc = process.argv[4] ||
21
- `${HF}/unsloth/LTX-2.3-GGUF/resolve/main/vae/ltx-2.3-22b-distilled_video_vae.safetensors`;
22
- const audioVaeModelSrc = process.argv[5] ||
23
- `${HF}/unsloth/LTX-2.3-GGUF/resolve/main/vae/ltx-2.3-22b-distilled_audio_vae.safetensors`;
24
- const embeddingsConnectorsModelSrc = process.argv[6] ||
25
- `${HF}/unsloth/LTX-2.3-GGUF/resolve/main/text_encoders/ltx-2.3-22b-distilled_embeddings_connectors.safetensors`;
13
+ // Pass your own paths / URLs via argv to override any of the five sources.
14
+ const diffusionModelSrc = process.argv[2] || LTX_2_3_22B_Q5_K_M;
15
+ const llmModelSrc = process.argv[3] || GEMMA_3_12B_Q4_K_XL;
16
+ const vaeModelSrc = process.argv[4] || LTX_2_3_VIDEO_VAE;
17
+ const audioVaeModelSrc = process.argv[5] || LTX_2_3_AUDIO_VAE;
18
+ const embeddingsConnectorsModelSrc = process.argv[6] || LTX_2_3_22B_DISTILLED_EMBEDDINGS_CONNECTORS;
26
19
  const prompt = process.argv[7] || 'a claymation cat playing jazz on a piano';
27
20
  const outputDir = process.argv[8] || '.';
28
21
  try {
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=embed-multimodal.d.ts.map
@@ -0,0 +1,80 @@
1
+ // Embed text, an image, and audio with EmbeddingGemma 2 in one shared vector space.
2
+ // Usage: npx tsx embed-multimodal.ts [image.jpg] [audio.wav]
3
+ // Defaults use image/test.jpg and audio/sample-16khz.wav from the source repository.
4
+ import { close, embedBatch, EMBEDDINGGEMMA_2_Q8_0, loadModel, MMPROJ_EMBEDDINGGEMMA_2_Q8_0, unloadModel } from '@qvac/sdk';
5
+ import { resolve } from 'node:path';
6
+ import { fileURLToPath } from 'node:url';
7
+ // EmbeddingGemma 2 normalizes its embeddings, so their dot product is cosine similarity.
8
+ function cosineSimilarity(vecA, vecB) {
9
+ let dotProduct = 0;
10
+ for (let i = 0; i < vecA.length; i++) {
11
+ dotProduct += vecA[i] * vecB[i];
12
+ }
13
+ return dotProduct;
14
+ }
15
+ let modelId;
16
+ try {
17
+ const [imagePath = fileURLToPath(new URL('./image/test.jpg', import.meta.url)), audioPath = fileURLToPath(new URL('./audio/sample-16khz.wav', import.meta.url))] = process.argv.slice(2);
18
+ console.error('▸ Loading EmbeddingGemma 2 and its projector');
19
+ modelId = await loadModel({
20
+ modelType: 'llamacpp-embedding',
21
+ modelSrc: EMBEDDINGGEMMA_2_Q8_0,
22
+ modelConfig: {
23
+ projectionModelSrc: MMPROJ_EMBEDDINGGEMMA_2_Q8_0,
24
+ ctxSize: 2048,
25
+ batchSize: 2048
26
+ },
27
+ onProgress: (p) => {
28
+ const mb = (n) => (n / 1e6).toFixed(1);
29
+ const line = `▸ Downloading ${p.percentage.toFixed(0)}% (${mb(p.downloaded)}/${mb(p.total)} MB)`;
30
+ process.stderr.write(process.stderr.isTTY ? `\r${line}` : `${line}\n`);
31
+ if (p.percentage >= 100)
32
+ process.stderr.write('\n');
33
+ }
34
+ });
35
+ const { embedding, stats } = await embedBatch({
36
+ modelId,
37
+ inputs: [
38
+ 'task: search result | query: a newspaper report about the Titanic',
39
+ ['title: none | text: ', { media: { type: 'filePath', value: resolve(imagePath) } }],
40
+ [{ media: { type: 'filePath', value: resolve(audioPath) } }]
41
+ ]
42
+ });
43
+ const [textEmbedding, imageEmbedding, audioEmbedding] = embedding;
44
+ if (!textEmbedding || !imageEmbedding || !audioEmbedding) {
45
+ throw new Error('Expected text, image, and audio embeddings');
46
+ }
47
+ const labels = ['Text query', `Image: ${imagePath}`, `Audio: ${audioPath}`];
48
+ for (const [index, values] of embedding.entries()) {
49
+ console.log(labels[index]);
50
+ console.log('Embedding dimensions:', values.length);
51
+ console.log('First 10 values:', values.slice(0, 10));
52
+ }
53
+ console.log('Text/image similarity:', cosineSimilarity(textEmbedding, imageEmbedding).toFixed(4));
54
+ console.log('Text/audio similarity:', cosineSimilarity(textEmbedding, audioEmbedding).toFixed(4));
55
+ console.log('Higher scores indicate a closer match to the text query.');
56
+ if (stats)
57
+ console.log('Performance stats:', stats);
58
+ }
59
+ catch (error) {
60
+ console.error('✖', error);
61
+ process.exitCode = 1;
62
+ }
63
+ finally {
64
+ if (modelId) {
65
+ try {
66
+ await unloadModel({ modelId });
67
+ }
68
+ catch (error) {
69
+ console.error('✖ Failed to unload model:', error);
70
+ process.exitCode = 1;
71
+ }
72
+ }
73
+ try {
74
+ await close();
75
+ }
76
+ catch (error) {
77
+ console.error('✖ Failed to close SDK connection:', error);
78
+ process.exitCode = 1;
79
+ }
80
+ }
@@ -1,4 +1,4 @@
1
- import { embed, GTE_LARGE_FP16, loadModel, unloadModel } from '@qvac/sdk';
1
+ import { embed, embedBatch, GTE_LARGE_FP16, loadModel, unloadModel } from '@qvac/sdk';
2
2
  function cosineSimilarity(vecA, vecB) {
3
3
  let dotProduct = 0;
4
4
  for (let i = 0; i < vecA.length; i++) {
@@ -37,7 +37,7 @@ try {
37
37
  'A fast auburn fox leaps over a sleepy canine',
38
38
  'Python is a programming language'
39
39
  ];
40
- const { embedding: batchEmbeddings } = await embed({ modelId, text: texts });
40
+ const { embedding: batchEmbeddings } = await embedBatch({ modelId, inputs: texts });
41
41
  console.log('Input: Array of', texts.length, 'texts');
42
42
  console.log('Output: Array of', batchEmbeddings.length, 'embeddings');
43
43
  const [emb1, emb2, emb3] = batchEmbeddings;
@@ -1,5 +1,10 @@
1
+ import path from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
1
3
  import { finetune, loadModel, QWEN3_600M_INST_Q4, unloadModel } from '@qvac/sdk';
2
4
  const pauseResumeEnabled = process.argv.includes('--pause-resume');
5
+ // The worker resolves dataset paths against the process working directory, so
6
+ // derive them from this file's own folder instead.
7
+ const datasetDir = path.dirname(fileURLToPath(import.meta.url));
3
8
  let modelId;
4
9
  let exitCode = 0;
5
10
  async function readProgress(handle, onTick) {
@@ -22,10 +27,10 @@ try {
22
27
  const finetuneParams = {
23
28
  modelId: loadedModelId,
24
29
  options: {
25
- trainDatasetDir: './examples/finetune/input/small_train_HF.jsonl',
30
+ trainDatasetDir: path.join(datasetDir, 'train.jsonl'),
26
31
  validation: {
27
32
  type: 'dataset',
28
- path: './examples/finetune/input/small_eval_HF.jsonl'
33
+ path: path.join(datasetDir, 'eval.jsonl')
29
34
  },
30
35
  numberOfEpochs: 2,
31
36
  learningRate: 1e-4,
@@ -33,8 +38,8 @@ try {
33
38
  loraModules: 'attn_q,attn_k,attn_v,attn_o,ffn_gate,ffn_up,ffn_down',
34
39
  assistantLossOnly: true,
35
40
  checkpointSaveSteps: 2,
36
- checkpointSaveDir: './examples/finetune/results/checkpoints',
37
- outputParametersDir: './examples/finetune/results'
41
+ checkpointSaveDir: './finetune-output/checkpoints',
42
+ outputParametersDir: './finetune-output'
38
43
  }
39
44
  };
40
45
  const handle = finetune(finetuneParams);
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=megaloc.d.ts.map
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Compare two images using the MegaLoc F16 model.
3
+ * Pass a GGUF URL or local file after the two JPEG/PNG paths to use custom weights.
4
+ */
5
+ import { readFile } from 'node:fs/promises';
6
+ import { loadModel, embedBatch, unloadModel, close, ModelType, MEGALOC_F16 } from '@qvac/sdk';
7
+ let modelId;
8
+ try {
9
+ const [firstPath, secondPath, modelSrc = MEGALOC_F16] = process.argv.slice(2);
10
+ if (!firstPath || !secondPath) {
11
+ throw new Error('Usage: megaloc <first.jpg> <second.jpg> [GGUF URL or path]');
12
+ }
13
+ console.log('▸ Loading MegaLoc');
14
+ modelId = await loadModel({ modelSrc, modelType: ModelType.ggmlImageEmbedding });
15
+ const { embedding, stats } = await embedBatch({
16
+ modelId,
17
+ inputs: [{ image: await readFile(firstPath) }, { image: await readFile(secondPath) }]
18
+ });
19
+ const [first, second] = embedding;
20
+ if (!first || !second)
21
+ throw new Error('Expected two image descriptors');
22
+ const similarity = first.reduce((sum, value, index) => sum + value * second[index], 0);
23
+ console.log(JSON.stringify({ similarity, dimensions: first.length, stats }, null, 2));
24
+ }
25
+ catch (error) {
26
+ console.error('✖', error instanceof Error ? error.message : String(error));
27
+ process.exitCode = 1;
28
+ }
29
+ finally {
30
+ try {
31
+ if (modelId)
32
+ await unloadModel({ modelId });
33
+ }
34
+ finally {
35
+ await close();
36
+ }
37
+ }
@@ -10,7 +10,9 @@ try {
10
10
  const modelId = await loadModel({
11
11
  modelSrc: SMOLVLM2_500M_MULTIMODAL_Q8_0,
12
12
  modelConfig: {
13
- ctx_size: 1024,
13
+ // An image is tiled into hundreds of context units before a single word
14
+ // of the prompt is counted, and the comparison below sends two at once.
15
+ ctx_size: 8192,
14
16
  projectionModelSrc: MMPROJ_SMOLVLM2_500M_MULTIMODAL_Q8_0
15
17
  },
16
18
  onProgress: (p) => {
@@ -56,6 +58,24 @@ try {
56
58
  const stats2 = await result2.stats;
57
59
  console.log('\n▸ Performance Stats:', stats2);
58
60
  console.log('▸ --------------------------------');
61
+ // Ordered text and media: each image keeps its position in the turn, so the
62
+ // text can sit next to the picture it refers to. Attachments can't do this,
63
+ // because they are all sent before the text.
64
+ const content = [
65
+ { type: 'text', text: 'Image A: ' },
66
+ { type: 'media', path: imageFilePath },
67
+ { type: 'text', text: '\nImage B: ' },
68
+ { type: 'media', path: imageFilePath2 },
69
+ { type: 'text', text: '\nWhich image is a newspaper?' }
70
+ ];
71
+ const history3 = [{ role: 'user', content }];
72
+ const result3 = completion({ modelId, history: history3, stream: true });
73
+ for await (const token of result3.tokenStream) {
74
+ process.stdout.write(token);
75
+ }
76
+ const stats3 = await result3.stats;
77
+ console.log('\n▸ Performance Stats:', stats3);
78
+ console.log('▸ --------------------------------');
59
79
  await unloadModel({ modelId, clearStorage: false });
60
80
  }
61
81
  catch (error) {
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * Run with: npx tsx examples/mcp-websearch.ts
11
11
  */
12
- import { completion, loadModel, unloadModel, QWEN3_1_7B_INST_Q4 } from '../src/index.js';
12
+ import { completion, loadModel, unloadModel, QWEN3_1_7B_INST_Q4 } from '@qvac/sdk';
13
13
  // MCP SDK is a user-installed optional dependency
14
14
  // Install with: npm install @modelcontextprotocol/sdk
15
15
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
@@ -10,7 +10,7 @@
10
10
  * 3. Embeddings -> fails (plugin not selected)
11
11
  *
12
12
  */
13
- import { bundleSdk } from '../src/commands/index.js';
13
+ import { bundleSdk } from '@qvac/sdk/commands';
14
14
  import { existsSync, rmSync } from 'fs';
15
15
  import path from 'path';
16
16
  const configDir = import.meta.dirname ?? process.cwd();
@@ -1,4 +1,4 @@
1
- import { loadModel, unloadModel, embed, GTE_LARGE_FP16, ragChunk, ragSaveEmbeddings, ragSearch, ragCloseWorkspace } from '@qvac/sdk';
1
+ import { loadModel, unloadModel, embedBatch, GTE_LARGE_FP16, ragChunk, ragSaveEmbeddings, ragSearch, ragCloseWorkspace } from '@qvac/sdk';
2
2
  try {
3
3
  // Get query from command line or use default
4
4
  const query = process.argv[2] || 'machine learning algorithms';
@@ -36,7 +36,7 @@ try {
36
36
  console.log(`▸ Created ${chunks.length} chunks`);
37
37
  console.log('▸ Step 2: Generating embeddings (batch)...');
38
38
  const texts = chunks.map((chunk) => chunk.content);
39
- const { embedding: embeddings } = await embed({ modelId, text: texts });
39
+ const { embedding: embeddings } = await embedBatch({ modelId, inputs: texts });
40
40
  const embeddedDocs = chunks.map((chunk, i) => ({
41
41
  id: chunk.id,
42
42
  content: chunk.content,
@@ -1,4 +1,4 @@
1
- import { createVectorIndex, embed, loadModel, loadVectorIndex, unloadModel, GTE_LARGE_FP16, VectorIndexStorage } from '@qvac/sdk';
1
+ import { createVectorIndex, embed, embedBatch, loadModel, loadVectorIndex, unloadModel, GTE_LARGE_FP16, VectorIndexStorage } from '@qvac/sdk';
2
2
  // Retrieval over documents kept in your own store. The SDK holds only the
3
3
  // vectors, in a TurboVec index inside the worker; the documents stay in this
4
4
  // Map (or any database you choose) and result ids map back to them.
@@ -22,7 +22,7 @@ try {
22
22
  }
23
23
  });
24
24
  console.log('▸ Embedding documents...');
25
- const { embedding: vectors } = await embed({ modelId, text: [...documents.values()] });
25
+ const { embedding: vectors } = await embedBatch({ modelId, inputs: [...documents.values()] });
26
26
  console.log('▸ Building the vector index...');
27
27
  const index = await createVectorIndex({
28
28
  dim: vectors[0].length,
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=rerank.d.ts.map
@@ -0,0 +1,33 @@
1
+ import { loadModel, rerank, unloadModel, close } from '@qvac/sdk';
2
+ // Any reranker (cross-encoder) GGUF, such as bge-reranker, jina-reranker or Qwen3-Reranker.
3
+ const modelSrc = process.argv[2] ??
4
+ 'https://huggingface.co/ggml-org/models/resolve/499bc8821c6b12b4e53c5bffcb21ec206f212d81/jina-reranker-v1-tiny-en/ggml-model-f16.gguf';
5
+ const query = 'How do I get a refund for a duplicate charge?';
6
+ const documents = [
7
+ 'Refunds for duplicate or failed payments are issued within 5 business days.',
8
+ 'Our office is open Monday to Friday, 9am to 5pm.',
9
+ 'To change your password, open Settings and choose Security.',
10
+ 'If you were charged twice, contact billing with both transaction IDs.'
11
+ ];
12
+ let modelId;
13
+ try {
14
+ console.error('▸ Loading reranker');
15
+ modelId = await loadModel({ modelSrc, modelType: 'llamacpp-rerank' });
16
+ // One score per document, in input order. Higher is more relevant.
17
+ const scores = await rerank({ modelId, query, documents });
18
+ const ranked = documents
19
+ .map((document, index) => ({ score: scores[index], document }))
20
+ .sort((a, b) => b.score - a.score);
21
+ console.log(`Query: ${query}\n`);
22
+ for (const { score, document } of ranked)
23
+ console.log(`${score.toFixed(3)} ${document}`);
24
+ }
25
+ catch (error) {
26
+ console.error('✖', error);
27
+ process.exitCode = 1;
28
+ }
29
+ finally {
30
+ if (modelId)
31
+ await unloadModel({ modelId });
32
+ await close();
33
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Two caller sessions on one runtime.
3
+ *
4
+ * Each session gets its own requests and model leases:
5
+ *
6
+ * - Both sessions load the same configuration and get the same `modelId`;
7
+ * the second load adds a lease instead of loading the model again.
8
+ * - A session's `cancel({ requestId })` reaches only its own requests, so
9
+ * the second session's cancel leaves the first session's completion
10
+ * running; the first session's own cancel stops it.
11
+ * - `unloadModel()` releases the caller's lease. The model unloads when its
12
+ * last lease is released, here when the second session closes.
13
+ *
14
+ * Only the module-level `close()` stops the runtime; it ends every session.
15
+ */
16
+ export {};
17
+ //# sourceMappingURL=sessions.d.ts.map