@qvac/sdk 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +48 -11
- package/bare-imports.json +35 -0
- package/dist/client/api/cancel.d.ts +12 -3
- package/dist/client/api/cancel.js +12 -3
- package/dist/client/api/get-model-info.d.ts +2 -2
- package/dist/client/api/get-model-info.js +2 -2
- package/dist/client/api/index.d.ts +2 -1
- package/dist/client/api/index.js +2 -1
- package/dist/client/api/load-model.js +6 -1
- package/dist/client/api/ocr.d.ts +31 -0
- package/dist/client/api/ocr.js +88 -0
- package/dist/client/api/rag.d.ts +215 -20
- package/dist/client/api/rag.js +382 -23
- package/dist/client/api/translate.js +10 -11
- package/dist/client/api/unload-model.js +1 -1
- package/dist/client/init-hooks.d.ts +4 -3
- package/dist/client/init-hooks.js +40 -31
- package/dist/client/rpc/bare-client.d.ts +1 -178
- package/dist/client/rpc/bare-client.js +42 -9
- package/dist/client/rpc/expo-rpc-client.js +57 -2
- package/dist/client/rpc/node-rpc-client.js +5 -1
- package/dist/client/rpc/rpc-client.d.ts +1 -1
- package/dist/client/rpc/rpc-client.js +11 -57
- package/dist/examples/config/blind-relay/blind-relay.config.d.ts +5 -0
- package/dist/examples/config/blind-relay/blind-relay.config.js +7 -0
- package/dist/examples/config/default/default.config.d.ts +8 -0
- package/dist/examples/config/default/default.config.js +6 -0
- package/dist/examples/default-config-usage.d.ts +17 -0
- package/dist/examples/default-config-usage.js +47 -0
- package/dist/examples/delegated-inference/consumer.js +1 -0
- package/dist/examples/download-with-blind-relays.js +4 -3
- package/dist/examples/embed-hyperdrive.js +4 -0
- package/dist/examples/kv-cache-custom-key.js +16 -1
- package/dist/examples/llamacpp-sharded.js +12 -3
- package/dist/examples/ocr-fasttext.d.ts +2 -0
- package/dist/examples/ocr-fasttext.js +52 -0
- package/dist/examples/quickstart.d.ts +2 -0
- package/dist/examples/quickstart.js +28 -0
- package/dist/examples/rag/rag-hyperdb/cancellation.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb/cancellation.js +75 -0
- package/dist/examples/rag/rag-hyperdb/ingest.d.ts +2 -0
- package/dist/examples/rag/{rag-hyperdb.js → rag-hyperdb/ingest.js} +10 -4
- package/dist/examples/rag/rag-hyperdb/pipeline.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb/pipeline.js +74 -0
- package/dist/examples/rag/rag-hyperdb/workspaces.d.ts +2 -0
- package/dist/examples/rag/rag-hyperdb/workspaces.js +178 -0
- package/dist/examples/translation/translation-bergamot-batch.d.ts +2 -0
- package/dist/examples/translation/translation-bergamot-batch.js +49 -0
- package/dist/examples/translation/translation-bergamot.d.ts +2 -0
- package/dist/examples/translation/translation-bergamot.js +39 -0
- package/dist/examples/translation/translation-indic.js +1 -0
- package/dist/examples/translation/translation-opus.js +1 -0
- package/dist/examples/translation/translation-stream.js +1 -0
- package/dist/expo/plugins/withMobileBundle.js +29 -10
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -1
- package/dist/logging/addon.js +23 -7
- package/dist/logging/base-logger.js +2 -2
- package/dist/logging/client-logger.js +15 -4
- package/dist/logging/index.d.ts +1 -0
- package/dist/logging/index.js +1 -0
- package/dist/logging/logger.js +11 -3
- package/dist/logging/namespaces.d.ts +1 -0
- package/dist/logging/namespaces.js +1 -0
- package/dist/logging/registry.d.ts +5 -0
- package/dist/logging/registry.js +17 -5
- package/dist/logging/transport.js +2 -2
- package/dist/logging/utils.d.ts +2 -0
- package/dist/logging/utils.js +62 -0
- package/dist/models/hyperdrive/models.d.ts +1096 -178
- package/dist/models/hyperdrive/models.js +1476 -507
- package/dist/schemas/archive.d.ts +9 -0
- package/dist/schemas/archive.js +17 -0
- package/dist/schemas/cancel.d.ts +6 -0
- package/dist/schemas/cancel.js +5 -0
- package/dist/schemas/common.d.ts +582 -77
- package/dist/schemas/common.js +6 -1
- package/dist/schemas/delegate.d.ts +1 -0
- package/dist/schemas/delegate.js +1 -0
- package/dist/schemas/download-asset.d.ts +21 -9
- package/dist/schemas/get-model-info.d.ts +12 -10
- package/dist/schemas/get-model-info.js +9 -1
- package/dist/schemas/index.d.ts +6 -2
- package/dist/schemas/index.js +9 -2
- package/dist/schemas/llamacpp-config.d.ts +112 -8
- package/dist/schemas/llamacpp-config.js +40 -8
- package/dist/schemas/load-model.d.ts +2993 -525
- package/dist/schemas/load-model.js +88 -33
- package/dist/schemas/logging-stream.d.ts +2 -2
- package/dist/schemas/model-src-utils.d.ts +38 -16
- package/dist/schemas/model-src-utils.js +4 -8
- package/dist/schemas/model-types.d.ts +154 -0
- package/dist/schemas/model-types.js +140 -0
- package/dist/schemas/ocr.d.ts +88 -0
- package/dist/schemas/ocr.js +52 -0
- package/dist/schemas/rag.d.ts +183 -52
- package/dist/schemas/rag.js +148 -23
- package/dist/schemas/reload-config.d.ts +20 -8
- package/dist/schemas/reload-config.js +7 -5
- package/dist/schemas/runtime-context.d.ts +19 -0
- package/dist/schemas/runtime-context.js +7 -0
- package/dist/schemas/sdk-config.d.ts +697 -2
- package/dist/schemas/sdk-config.js +99 -1
- package/dist/schemas/sdk-errors-client.d.ts +1 -0
- package/dist/schemas/sdk-errors-client.js +5 -0
- package/dist/schemas/sdk-errors-server.d.ts +14 -0
- package/dist/schemas/sdk-errors-server.js +70 -0
- package/dist/schemas/shard.d.ts +21 -0
- package/dist/schemas/shard.js +17 -0
- package/dist/schemas/translate.d.ts +68 -23
- package/dist/schemas/translate.js +37 -11
- package/dist/schemas/translation-config.d.ts +272 -29
- package/dist/schemas/translation-config.js +63 -6
- package/dist/scripts/run-unit-tests.d.ts +2 -0
- package/dist/scripts/run-unit-tests.js +17 -0
- package/dist/server/bare/addons/llamacpp-completion/cache-logger.d.ts +6 -0
- package/dist/server/bare/addons/llamacpp-completion/cache-logger.js +34 -0
- package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/create-model.d.ts +1 -5
- package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/create-model.js +3 -26
- package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/handlers/completion-stream.js +26 -7
- package/dist/server/bare/addons/llamacpp-completion/index.d.ts +4 -0
- package/dist/server/bare/addons/llamacpp-completion/index.js +3 -0
- package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/kv-cache-utils.d.ts +4 -1
- package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/kv-cache-utils.js +43 -10
- package/dist/server/bare/addons/llamacpp-embedding/create-model.d.ts +8 -0
- package/dist/server/bare/addons/llamacpp-embedding/create-model.js +38 -0
- package/dist/server/bare/addons/llamacpp-embedding/index.d.ts +3 -0
- package/dist/server/bare/addons/llamacpp-embedding/index.js +2 -0
- package/dist/server/bare/addons/load-model.js +28 -24
- package/dist/server/bare/addons/{translation → nmtcpp-translation}/create-model.js +23 -8
- package/dist/server/bare/addons/{translation → nmtcpp-translation}/handlers/translate.js +35 -11
- package/dist/server/bare/addons/onnx-ocr/create-model.d.ts +10 -0
- package/dist/server/bare/addons/onnx-ocr/create-model.js +39 -0
- package/dist/server/bare/addons/onnx-ocr/handlers/ocr-stream.d.ts +10 -0
- package/dist/server/bare/addons/onnx-ocr/handlers/ocr-stream.js +109 -0
- package/dist/server/bare/addons/onnx-ocr/index.d.ts +3 -0
- package/dist/server/bare/addons/onnx-ocr/index.js +2 -0
- package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/create-model.js +2 -1
- package/dist/server/bare/delegate-rpc-client.js +19 -1
- package/dist/server/bare/rag-hyperdb/handlers/chunk.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/chunk.js +7 -0
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/close-workspace.js +9 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.d.ts +1 -1
- package/dist/server/bare/rag-hyperdb/handlers/delete-embeddings.js +9 -10
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/delete-workspace.js +14 -0
- package/dist/server/bare/rag-hyperdb/handlers/ingest.d.ts +9 -0
- package/dist/server/bare/rag-hyperdb/handlers/ingest.js +18 -0
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.d.ts +3 -0
- package/dist/server/bare/rag-hyperdb/handlers/list-workspaces.js +4 -0
- package/dist/server/bare/rag-hyperdb/handlers/reindex.d.ts +9 -0
- package/dist/server/bare/rag-hyperdb/handlers/reindex.js +16 -0
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.d.ts +7 -4
- package/dist/server/bare/rag-hyperdb/handlers/save-embeddings.js +13 -14
- package/dist/server/bare/rag-hyperdb/handlers/search.js +10 -10
- package/dist/server/bare/rag-hyperdb/index.d.ts +8 -1
- package/dist/server/bare/rag-hyperdb/index.js +8 -1
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.d.ts +7 -0
- package/dist/server/bare/rag-hyperdb/rag-operation-manager.js +39 -0
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.d.ts +15 -0
- package/dist/server/bare/rag-hyperdb/rag-workspace-manager.js +135 -0
- package/dist/server/bare/registry/config-registry.js +11 -0
- package/dist/server/bare/registry/logging-stream-registry.js +3 -3
- package/dist/server/bare/registry/model-config-registry.d.ts +4 -0
- package/dist/server/bare/registry/model-config-registry.js +15 -0
- package/dist/server/bare/registry/model-config-utils.d.ts +15 -0
- package/dist/server/bare/registry/model-config-utils.js +110 -0
- package/dist/server/bare/registry/model-registry.d.ts +6 -29
- package/dist/server/bare/registry/runtime-context-registry.d.ts +7 -0
- package/dist/server/bare/registry/runtime-context-registry.js +26 -0
- package/dist/server/bare/utils/loader-adapter.d.ts +7 -0
- package/dist/server/bare/utils/loader-adapter.js +9 -0
- package/dist/server/error-handlers.js +4 -2
- package/dist/server/rpc/handle-request.js +91 -9
- package/dist/server/rpc/handlers/cancelHandler.js +10 -1
- package/dist/server/rpc/handlers/completion-stream.js +1 -1
- package/dist/server/rpc/handlers/delete-cache.js +1 -1
- package/dist/server/rpc/handlers/embed.js +1 -1
- package/dist/server/rpc/handlers/get-model-info.d.ts +1 -1
- package/dist/server/rpc/handlers/get-model-info.js +22 -10
- package/dist/server/rpc/handlers/index.d.ts +4 -1
- package/dist/server/rpc/handlers/index.js +2 -0
- package/dist/server/rpc/handlers/load-model/download-manager.d.ts +11 -11
- package/dist/server/rpc/handlers/load-model/download-manager.js +36 -26
- package/dist/server/rpc/handlers/{load-model.d.ts → load-model/handler.d.ts} +2 -2
- package/dist/server/rpc/handlers/load-model/handler.js +179 -0
- package/dist/server/rpc/handlers/load-model/http.js +342 -33
- package/dist/server/rpc/handlers/load-model/hyperdrive.js +5 -3
- package/dist/server/rpc/handlers/load-model/index.d.ts +2 -2
- package/dist/server/rpc/handlers/load-model/index.js +2 -2
- package/dist/server/rpc/handlers/load-model/resolve.js +32 -3
- package/dist/server/rpc/handlers/load-model-delegated.js +6 -3
- package/dist/server/rpc/handlers/ocr-stream.d.ts +3 -0
- package/dist/server/rpc/handlers/ocr-stream.js +39 -0
- package/dist/server/rpc/handlers/rag.d.ts +2 -2
- package/dist/server/rpc/handlers/rag.js +107 -43
- package/dist/server/rpc/handlers/text-to-speech.js +1 -1
- package/dist/server/rpc/handlers/transcribe-stream.js +1 -1
- package/dist/server/rpc/handlers/translate.js +6 -15
- package/dist/server/utils/archive.d.ts +3 -0
- package/dist/server/utils/archive.js +171 -0
- package/dist/server/utils/audio/decoder.js +2 -2
- package/dist/server/utils/cache.d.ts +5 -5
- package/dist/server/utils/cache.js +6 -6
- package/dist/server/utils/config-transform.d.ts +2 -2
- package/dist/server/utils/config-transform.js +8 -6
- package/dist/server/utils/formatting.d.ts +13 -0
- package/dist/server/utils/formatting.js +26 -0
- package/dist/server/utils/gguf-tensor-extractor.d.ts +15 -0
- package/dist/server/utils/gguf-tensor-extractor.js +314 -0
- package/dist/server/utils/index.d.ts +3 -1
- package/dist/server/utils/index.js +3 -1
- package/dist/server/utils/shard-utils.d.ts +42 -16
- package/dist/server/utils/shard-utils.js +95 -7
- package/dist/server/worker.js +8 -3
- package/dist/utils/errors-base.d.ts +1 -1
- package/dist/utils/errors-base.js +2 -2
- package/dist/utils/errors-client.d.ts +12 -0
- package/dist/utils/errors-client.js +20 -0
- package/dist/utils/errors-server.d.ts +33 -0
- package/dist/utils/errors-server.js +55 -0
- package/package.json +42 -17
- package/dist/client/rpc/bare-rpc-client.d.ts +0 -4
- package/dist/client/rpc/bare-rpc-client.js +0 -94
- package/dist/examples/config/config-path.d.ts +0 -8
- package/dist/examples/config/config-path.js +0 -13
- package/dist/examples/rag/rag-hyperdb-workspaces.d.ts +0 -2
- package/dist/examples/rag/rag-hyperdb-workspaces.js +0 -106
- package/dist/examples/rag/rag-hyperdb.d.ts +0 -2
- package/dist/server/bare/addons/llamacpp/index.d.ts +0 -4
- package/dist/server/bare/addons/llamacpp/index.js +0 -3
- package/dist/server/bare/rag-hyperdb/rag-manager.d.ts +0 -5
- package/dist/server/bare/rag-hyperdb/rag-manager.js +0 -66
- package/dist/server/rpc/handlers/load-model.js +0 -111
- package/dist/server/utils/hash.d.ts +0 -5
- package/dist/server/utils/hash.js +0 -11
- package/dist/utils/getProcessSafe.d.ts +0 -7
- package/dist/utils/getProcessSafe.js +0 -17
- package/dist/utils/runtime.d.ts +0 -30
- package/dist/utils/runtime.js +0 -48
- /package/dist/server/bare/addons/{llamacpp → llamacpp-completion}/handlers/completion-stream.d.ts +0 -0
- /package/dist/server/bare/addons/{llamacpp → llamacpp-embedding}/handlers/embed.d.ts +0 -0
- /package/dist/server/bare/addons/{llamacpp → llamacpp-embedding}/handlers/embed.js +0 -0
- /package/dist/server/bare/addons/{translation → nmtcpp-translation}/create-model.d.ts +0 -0
- /package/dist/server/bare/addons/{translation → nmtcpp-translation}/handlers/translate.d.ts +0 -0
- /package/dist/server/bare/addons/{translation → nmtcpp-translation}/index.d.ts +0 -0
- /package/dist/server/bare/addons/{translation → nmtcpp-translation}/index.js +0 -0
- /package/dist/server/bare/addons/{tts → onnx-tts}/create-model.d.ts +0 -0
- /package/dist/server/bare/addons/{tts → onnx-tts}/create-model.js +0 -0
- /package/dist/server/bare/addons/{tts → onnx-tts}/handlers/text-to-speech.d.ts +0 -0
- /package/dist/server/bare/addons/{tts → onnx-tts}/handlers/text-to-speech.js +0 -0
- /package/dist/server/bare/addons/{tts → onnx-tts}/index.d.ts +0 -0
- /package/dist/server/bare/addons/{tts → onnx-tts}/index.js +0 -0
- /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/create-model.d.ts +0 -0
- /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/handlers/transcribe-stream.d.ts +0 -0
- /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/handlers/transcribe-stream.js +0 -0
- /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/index.d.ts +0 -0
- /package/dist/server/bare/addons/{whispercpp → whispercpp-transcription}/index.js +0 -0
package/README.md
CHANGED
|
@@ -135,11 +135,12 @@ try {
|
|
|
135
135
|
- Translation: between different languages.
|
|
136
136
|
- Text-to-Speech: TTS via ONNX.
|
|
137
137
|
- Multimodal: via [`llama.cpp`] — i.e., process and understand multiple types of media within the same conversation context.
|
|
138
|
-
- RAG:
|
|
138
|
+
- RAG: retrieval-augmented generation with progress streaming, cancellation, and workspace management.
|
|
139
139
|
- Delegated inference: perform peer-to-peer edge inference via Holepunch stack.
|
|
140
140
|
|
|
141
141
|
### Utilities
|
|
142
142
|
|
|
143
|
+
- Configuration: customize SDK behavior via config files (`qvac.config.json`, `.js`, or `.ts`).
|
|
143
144
|
- Logging: visibility into what's happening inside your models during loading, inference, and other operations.
|
|
144
145
|
- Download Lifecycle: pause and resume model downloads.
|
|
145
146
|
- Blind Relays: establish peer connections through NAT/firewalls by routing traffic through relay nodes.
|
|
@@ -180,11 +181,19 @@ bun run examples/path/to/example.ts
|
|
|
180
181
|
### Embeddings
|
|
181
182
|
|
|
182
183
|
- Single and batch embeddings: [`examples/embed-hyperdrive.ts`](examples/embed-hyperdrive.ts)
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
-
|
|
187
|
-
-
|
|
184
|
+
|
|
185
|
+
**RAG with HyperDB** (cross-platform):
|
|
186
|
+
|
|
187
|
+
- Ingest (full pipeline): [`examples/rag/rag-hyperdb/ingest.ts`](examples/rag/rag-hyperdb/ingest.ts)
|
|
188
|
+
- Segregated pipeline: [`examples/rag/rag-hyperdb/pipeline.ts`](examples/rag/rag-hyperdb/pipeline.ts) _(Segregated flow: chunk → embed → save)_
|
|
189
|
+
- Workspaces: [`examples/rag/rag-hyperdb/workspaces.ts`](examples/rag/rag-hyperdb/workspaces.ts) _(Workspace lifecycle: list, close, delete)_
|
|
190
|
+
- Cancellation: [`examples/rag/rag-hyperdb/cancellation.ts`](examples/rag/rag-hyperdb/cancellation.ts) _(progress + cancel)_
|
|
191
|
+
|
|
192
|
+
**RAG with other backends** (desktop only):
|
|
193
|
+
|
|
194
|
+
- LanceDB: [`examples/rag/rag-lancedb.ts`](examples/rag/rag-lancedb.ts)
|
|
195
|
+
- ChromaDB: [`examples/rag/rag-chromadb.ts`](examples/rag/rag-chromadb.ts) _(requires ChromaDB server)_
|
|
196
|
+
- SQLite-Vector: [`examples/rag/rag-sqlite.ts`](examples/rag/rag-sqlite.ts) _(SQLite-Vector WASM)_
|
|
188
197
|
|
|
189
198
|
### Translation
|
|
190
199
|
|
|
@@ -232,6 +241,29 @@ for await (const log of loggingStream({ id: modelId })) {
|
|
|
232
241
|
- Log streaming: [`examples/logging-streaming.ts`](examples/logging-streaming.ts)
|
|
233
242
|
- Log with custom file transport: [`examples/logging-file-transport.ts`](examples/logging-file-transport.ts)
|
|
234
243
|
|
|
244
|
+
### Configuration
|
|
245
|
+
|
|
246
|
+
Customize SDK behavior using a config file. The SDK auto-discovers `qvac.config.{json,js,ts}` in your project root, or you can specify a path via `QVAC_CONFIG_PATH` environment variable.
|
|
247
|
+
|
|
248
|
+
**Supported formats:**
|
|
249
|
+
|
|
250
|
+
- `qvac.config.json` - JSON format
|
|
251
|
+
- `qvac.config.js` - JavaScript with `export default`
|
|
252
|
+
- `qvac.config.ts` - TypeScript with `export default`
|
|
253
|
+
|
|
254
|
+
**Available options:**
|
|
255
|
+
|
|
256
|
+
| Option | Type | Default | Description |
|
|
257
|
+
| ------------------------- | ---------- | ---------------- | --------------------------------------------------- |
|
|
258
|
+
| `cacheDirectory` | `string` | `~/.qvac/models` | Where models and assets are stored |
|
|
259
|
+
| `swarmRelays` | `string[]` | `[]` | Hyperswarm relay public keys for P2P |
|
|
260
|
+
| `loggerLevel` | `string` | `"info"` | Log level: `"error"`, `"warn"`, `"info"`, `"debug"` |
|
|
261
|
+
| `loggerConsoleOutput` | `boolean` | `true` | Enable/disable console output |
|
|
262
|
+
| `httpDownloadConcurrency` | `number` | `3` | Max concurrent HTTP downloads for sharded models |
|
|
263
|
+
| `httpConnectionTimeoutMs` | `number` | `10000` | HTTP connection timeout in milliseconds |
|
|
264
|
+
|
|
265
|
+
- Config usage example: [`examples/default-config-usage.ts`](examples/default-config-usage.ts)
|
|
266
|
+
|
|
235
267
|
### Download Lifecycle
|
|
236
268
|
|
|
237
269
|
- Pause and resume download: [`examples/download-with-cancel.ts`](examples/download-with-cancel.ts)
|
|
@@ -241,18 +273,23 @@ for await (const log of loggingStream({ id: modelId })) {
|
|
|
241
273
|
Blind relays help establish peer connections through NAT/firewalls by routing traffic through relay nodes.
|
|
242
274
|
|
|
243
275
|
- Model downloads via Hyperdrive: [`examples/download-with-blind-relays.ts`](./examples/download-with-blind-relays.ts)
|
|
244
|
-
- Delegated inference: You can reuse the same pattern for delegated inference by
|
|
276
|
+
- Delegated inference: You can reuse the same pattern for delegated inference by adding `swarmRelays` to your config file before starting your provider/consumer.
|
|
245
277
|
|
|
246
278
|
> [!NOTE]
|
|
247
279
|
> The examples use mock relay keys. For real deployments, you **must** use your own relay servers or trusted public relays.
|
|
248
280
|
|
|
249
281
|
### Sharded Models
|
|
250
282
|
|
|
251
|
-
|
|
252
|
-
- Load models from local filesystem: [`examples/llamacpp-filesystem.ts`](examples/llamacpp-filesystem.ts)
|
|
283
|
+
Sharded models are split into multiple files following the pattern: `<name>-00001-of-0000X.<ext>`. The SDK automatically downloads and loads all parts with detailed progress tracking.
|
|
253
284
|
|
|
254
|
-
|
|
255
|
-
|
|
285
|
+
**Supported formats:**
|
|
286
|
+
|
|
287
|
+
- Archives (`.tar`, `.tar.gz`, `.tgz`): HTTP or local with automatic extraction
|
|
288
|
+
- HTTP sharded URL: pass the download URL of any shard and the SDK will fetch the remaining shards
|
|
289
|
+
- Hyperdrive: use any sharded Hyperdrive model source
|
|
290
|
+
- Local shards: pass the path to any shard file. _(Note: All shards must be in the same directory)_
|
|
291
|
+
|
|
292
|
+
See: [`examples/llamacpp-sharded.ts`](examples/llamacpp-sharded.ts)
|
|
256
293
|
|
|
257
294
|
## Basic flow
|
|
258
295
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
{
|
|
2
|
+
"#rpc": {
|
|
3
|
+
"react-native": "./dist/client/rpc/expo-rpc-client.js",
|
|
4
|
+
"bare": "./dist/client/rpc/bare-client.js",
|
|
5
|
+
"default": "./dist/client/rpc/node-rpc-client.js"
|
|
6
|
+
},
|
|
7
|
+
"child_process": {
|
|
8
|
+
"bare": "bare-subprocess",
|
|
9
|
+
"default": "child_process"
|
|
10
|
+
},
|
|
11
|
+
"crypto": {
|
|
12
|
+
"bare": "bare-crypto",
|
|
13
|
+
"default": "crypto"
|
|
14
|
+
},
|
|
15
|
+
"fs": {
|
|
16
|
+
"bare": "bare-fs",
|
|
17
|
+
"default": "fs"
|
|
18
|
+
},
|
|
19
|
+
"os": {
|
|
20
|
+
"bare": "bare-os",
|
|
21
|
+
"default": "os"
|
|
22
|
+
},
|
|
23
|
+
"path": {
|
|
24
|
+
"bare": "bare-path",
|
|
25
|
+
"default": "path"
|
|
26
|
+
},
|
|
27
|
+
"process": {
|
|
28
|
+
"bare": "bare-process",
|
|
29
|
+
"default": "process"
|
|
30
|
+
},
|
|
31
|
+
"readline": {
|
|
32
|
+
"bare": "bare-readline",
|
|
33
|
+
"default": "readline"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -3,10 +3,11 @@ import { type CancelParams } from "../../schemas/index";
|
|
|
3
3
|
* Cancels an ongoing operation.
|
|
4
4
|
*
|
|
5
5
|
* @param params - The parameters for the cancellation
|
|
6
|
-
* @param params.operation - The type of operation to cancel ("inference" or "
|
|
6
|
+
* @param params.operation - The type of operation to cancel ("inference", "downloadAsset", or "rag")
|
|
7
7
|
* @param params.modelId - The model ID (required for inference cancellation)
|
|
8
8
|
* @param params.downloadKey - The download key (required for download cancellation)
|
|
9
9
|
* @param params.clearCache - If true, deletes the partial download file (default: false)
|
|
10
|
+
* @param params.workspace - The RAG workspace to cancel (optional, defaults to "default")
|
|
10
11
|
* @throws {QvacErrorBase} When the response type is invalid or when the cancellation fails
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
@@ -15,11 +16,19 @@ import { type CancelParams } from "../../schemas/index";
|
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* // Pause download (preserves partial file for automatic resume)
|
|
18
|
-
* await cancel({ operation: "
|
|
19
|
+
* await cancel({ operation: "downloadAsset", downloadKey: "download-key" });
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
21
22
|
* // Cancel download completely (deletes partial file)
|
|
22
|
-
* await cancel({ operation: "
|
|
23
|
+
* await cancel({ operation: "downloadAsset", downloadKey: "download-key", clearCache: true });
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* // Cancel RAG operation on default workspace
|
|
27
|
+
* await cancel({ operation: "rag" });
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* // Cancel RAG operation on specific workspace
|
|
31
|
+
* await cancel({ operation: "rag", workspace: "my-workspace" });
|
|
23
32
|
*/
|
|
24
33
|
export declare function cancel(params: CancelParams): Promise<void>;
|
|
25
34
|
//# sourceMappingURL=cancel.d.ts.map
|
|
@@ -5,10 +5,11 @@ import { InvalidResponseError, CancelFailedError } from "../../utils/errors-clie
|
|
|
5
5
|
* Cancels an ongoing operation.
|
|
6
6
|
*
|
|
7
7
|
* @param params - The parameters for the cancellation
|
|
8
|
-
* @param params.operation - The type of operation to cancel ("inference" or "
|
|
8
|
+
* @param params.operation - The type of operation to cancel ("inference", "downloadAsset", or "rag")
|
|
9
9
|
* @param params.modelId - The model ID (required for inference cancellation)
|
|
10
10
|
* @param params.downloadKey - The download key (required for download cancellation)
|
|
11
11
|
* @param params.clearCache - If true, deletes the partial download file (default: false)
|
|
12
|
+
* @param params.workspace - The RAG workspace to cancel (optional, defaults to "default")
|
|
12
13
|
* @throws {QvacErrorBase} When the response type is invalid or when the cancellation fails
|
|
13
14
|
*
|
|
14
15
|
* @example
|
|
@@ -17,11 +18,19 @@ import { InvalidResponseError, CancelFailedError } from "../../utils/errors-clie
|
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
19
20
|
* // Pause download (preserves partial file for automatic resume)
|
|
20
|
-
* await cancel({ operation: "
|
|
21
|
+
* await cancel({ operation: "downloadAsset", downloadKey: "download-key" });
|
|
21
22
|
*
|
|
22
23
|
* @example
|
|
23
24
|
* // Cancel download completely (deletes partial file)
|
|
24
|
-
* await cancel({ operation: "
|
|
25
|
+
* await cancel({ operation: "downloadAsset", downloadKey: "download-key", clearCache: true });
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* // Cancel RAG operation on default workspace
|
|
29
|
+
* await cancel({ operation: "rag" });
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* // Cancel RAG operation on specific workspace
|
|
33
|
+
* await cancel({ operation: "rag", workspace: "my-workspace" });
|
|
25
34
|
*/
|
|
26
35
|
export async function cancel(params) {
|
|
27
36
|
const request = {
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type GetModelInfoParams } from "../../schemas/index";
|
|
2
|
-
export declare
|
|
2
|
+
export declare function getModelInfo(params: GetModelInfoParams): Promise<{
|
|
3
3
|
name: string;
|
|
4
4
|
modelId: string;
|
|
5
5
|
hyperdriveKey: string;
|
|
6
6
|
hyperbeeKey: string;
|
|
7
7
|
expectedSize: number;
|
|
8
8
|
sha256Checksum: string;
|
|
9
|
-
addon: "
|
|
9
|
+
addon: "llamacpp-completion" | "whispercpp-transcription" | "llamacpp-embedding" | "nmtcpp-translation" | "onnx-tts" | "onnx-ocr" | "vad";
|
|
10
10
|
isCached: boolean;
|
|
11
11
|
isLoaded: boolean;
|
|
12
12
|
cacheFiles: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {} from "../../schemas/index.js";
|
|
2
2
|
import { send } from "../rpc/rpc-client.js";
|
|
3
3
|
import { InvalidResponseError } from "../../utils/errors-client.js";
|
|
4
|
-
export
|
|
4
|
+
export async function getModelInfo(params) {
|
|
5
5
|
const request = {
|
|
6
6
|
type: "getModelInfo",
|
|
7
7
|
name: params.name,
|
|
@@ -11,4 +11,4 @@ export const getModelInfo = async (params) => {
|
|
|
11
11
|
throw new InvalidResponseError("getModelInfo");
|
|
12
12
|
}
|
|
13
13
|
return response.modelInfo;
|
|
14
|
-
}
|
|
14
|
+
}
|
|
@@ -11,7 +11,8 @@ export { translate } from "./translate";
|
|
|
11
11
|
export { cancel } from "./cancel";
|
|
12
12
|
export { startQVACProvider } from "./provide";
|
|
13
13
|
export { stopQVACProvider } from "./stop-provider";
|
|
14
|
-
export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag";
|
|
14
|
+
export { ragChunk, ragIngest, ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings, ragReindex, ragListWorkspaces, ragCloseWorkspace, ragDeleteWorkspace, } from "./rag";
|
|
15
15
|
export { textToSpeech } from "./text-to-speech";
|
|
16
16
|
export { getModelInfo } from "./get-model-info";
|
|
17
|
+
export { ocr } from "./ocr";
|
|
17
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/client/api/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { translate } from "./translate.js";
|
|
|
11
11
|
export { cancel } from "./cancel.js";
|
|
12
12
|
export { startQVACProvider } from "./provide.js";
|
|
13
13
|
export { stopQVACProvider } from "./stop-provider.js";
|
|
14
|
-
export { ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings } from "./rag.js";
|
|
14
|
+
export { ragChunk, ragIngest, ragSaveEmbeddings, ragSearch, ragDeleteEmbeddings, ragReindex, ragListWorkspaces, ragCloseWorkspace, ragDeleteWorkspace, } from "./rag.js";
|
|
15
15
|
export { textToSpeech } from "./text-to-speech.js";
|
|
16
16
|
export { getModelInfo } from "./get-model-info.js";
|
|
17
|
+
export { ocr } from "./ocr.js";
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { send, stream } from "../rpc/rpc-client.js";
|
|
2
2
|
import { startLoggingStreamForModel } from "../logging-stream-registry.js";
|
|
3
|
-
import { loadModelOptionsToRequestSchema, reloadConfigOptionsToRequestSchema, } from "../../schemas/index.js";
|
|
3
|
+
import { loadModelOptionsToRequestSchema, reloadConfigOptionsToRequestSchema, isModelTypeAlias, normalizeModelType, } from "../../schemas/index.js";
|
|
4
4
|
import { ModelLoadFailedError, StreamEndedError, InvalidResponseError, } from "../../utils/errors-client.js";
|
|
5
5
|
import { getClientLogger } from "../../logging/index.js";
|
|
6
6
|
const logger = getClientLogger();
|
|
7
7
|
export async function loadModel(options) {
|
|
8
8
|
const isReloadConfig = "modelId" in options && !("modelSrc" in options);
|
|
9
|
+
// Warn about deprecated alias usage
|
|
10
|
+
if (!isReloadConfig && isModelTypeAlias(options.modelType)) {
|
|
11
|
+
const canonical = normalizeModelType(options.modelType);
|
|
12
|
+
logger.warn(`Model type "${options.modelType}" is an alias and will be deprecated. Use "${canonical}" instead.`);
|
|
13
|
+
}
|
|
9
14
|
const request = isReloadConfig
|
|
10
15
|
? reloadConfigOptionsToRequestSchema.parse(options)
|
|
11
16
|
: loadModelOptionsToRequestSchema.parse(options);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type OCRClientParams, type OCRTextBlock, type OCRStats } from "../../schemas/index";
|
|
2
|
+
/**
|
|
3
|
+
* Performs Optical Character Recognition (OCR) on an image to extract text.
|
|
4
|
+
*
|
|
5
|
+
* @param params - The OCR parameters
|
|
6
|
+
* @param params.modelId - The identifier of the loaded OCR model to use
|
|
7
|
+
* @param params.image - Image input as either a file path (string) or image buffer
|
|
8
|
+
* @param params.options - Optional OCR options (e.g., paragraph mode)
|
|
9
|
+
* @param params.stream - Whether to stream blocks as they're detected (true) or return all at once (false). Defaults to false
|
|
10
|
+
* @returns Object with blockStream generator, blocks promise, and stats promise
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // Non-streaming mode (default) - get all blocks at once
|
|
14
|
+
* const { blocks } = ocr({ modelId, image: "/path/to/image.png" });
|
|
15
|
+
* for (const block of await blocks) {
|
|
16
|
+
* console.log(block.text, block.bbox, block.confidence);
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* // Streaming mode - process blocks as they arrive
|
|
20
|
+
* const { blockStream } = ocr({ modelId, image: imageBuffer, stream: true });
|
|
21
|
+
* for await (const blocks of blockStream) {
|
|
22
|
+
* console.log("Detected:", blocks);
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare function ocr(params: OCRClientParams): {
|
|
27
|
+
blockStream: AsyncGenerator<OCRTextBlock[]>;
|
|
28
|
+
blocks: Promise<OCRTextBlock[]>;
|
|
29
|
+
stats: Promise<OCRStats | undefined>;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=ocr.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { ocrStreamResponseSchema, } from "../../schemas/index.js";
|
|
2
|
+
import { stream as streamRpc } from "../rpc/rpc-client.js";
|
|
3
|
+
/**
|
|
4
|
+
* Performs Optical Character Recognition (OCR) on an image to extract text.
|
|
5
|
+
*
|
|
6
|
+
* @param params - The OCR parameters
|
|
7
|
+
* @param params.modelId - The identifier of the loaded OCR model to use
|
|
8
|
+
* @param params.image - Image input as either a file path (string) or image buffer
|
|
9
|
+
* @param params.options - Optional OCR options (e.g., paragraph mode)
|
|
10
|
+
* @param params.stream - Whether to stream blocks as they're detected (true) or return all at once (false). Defaults to false
|
|
11
|
+
* @returns Object with blockStream generator, blocks promise, and stats promise
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* // Non-streaming mode (default) - get all blocks at once
|
|
15
|
+
* const { blocks } = ocr({ modelId, image: "/path/to/image.png" });
|
|
16
|
+
* for (const block of await blocks) {
|
|
17
|
+
* console.log(block.text, block.bbox, block.confidence);
|
|
18
|
+
* }
|
|
19
|
+
*
|
|
20
|
+
* // Streaming mode - process blocks as they arrive
|
|
21
|
+
* const { blockStream } = ocr({ modelId, image: imageBuffer, stream: true });
|
|
22
|
+
* for await (const blocks of blockStream) {
|
|
23
|
+
* console.log("Detected:", blocks);
|
|
24
|
+
* }
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
export function ocr(params) {
|
|
28
|
+
const request = {
|
|
29
|
+
type: "ocrStream",
|
|
30
|
+
modelId: params.modelId,
|
|
31
|
+
image: typeof params.image === "string"
|
|
32
|
+
? { type: "filePath", value: params.image }
|
|
33
|
+
: { type: "base64", value: params.image.toString("base64") },
|
|
34
|
+
...(params.options && { options: params.options }),
|
|
35
|
+
};
|
|
36
|
+
let ocrStats;
|
|
37
|
+
let statsResolver = () => { };
|
|
38
|
+
const statsPromise = new Promise((resolve) => {
|
|
39
|
+
statsResolver = resolve;
|
|
40
|
+
});
|
|
41
|
+
if (params.stream) {
|
|
42
|
+
const blockStream = (async function* () {
|
|
43
|
+
for await (const response of streamRpc(request)) {
|
|
44
|
+
if (response.type === "ocrStream") {
|
|
45
|
+
const streamResponse = ocrStreamResponseSchema.parse(response);
|
|
46
|
+
if (streamResponse.blocks && streamResponse.blocks.length > 0) {
|
|
47
|
+
yield streamResponse.blocks;
|
|
48
|
+
}
|
|
49
|
+
if (streamResponse.done) {
|
|
50
|
+
ocrStats = streamResponse.stats;
|
|
51
|
+
statsResolver(ocrStats);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})();
|
|
56
|
+
return {
|
|
57
|
+
blockStream,
|
|
58
|
+
blocks: Promise.resolve([]),
|
|
59
|
+
stats: statsPromise,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const blockStream = (async function* () {
|
|
64
|
+
// Empty generator for non-streaming mode
|
|
65
|
+
})();
|
|
66
|
+
const blocksPromise = (async () => {
|
|
67
|
+
let allBlocks = [];
|
|
68
|
+
for await (const response of streamRpc(request)) {
|
|
69
|
+
if (response.type === "ocrStream") {
|
|
70
|
+
const streamResponse = ocrStreamResponseSchema.parse(response);
|
|
71
|
+
if (streamResponse.blocks) {
|
|
72
|
+
allBlocks = allBlocks.concat(streamResponse.blocks);
|
|
73
|
+
}
|
|
74
|
+
if (streamResponse.done) {
|
|
75
|
+
ocrStats = streamResponse.stats;
|
|
76
|
+
statsResolver(ocrStats);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return allBlocks;
|
|
81
|
+
})();
|
|
82
|
+
return {
|
|
83
|
+
blockStream,
|
|
84
|
+
blocks: blocksPromise,
|
|
85
|
+
stats: statsPromise,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
package/dist/client/api/rag.d.ts
CHANGED
|
@@ -1,42 +1,237 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RagChunkParams, RagDoc, RagIngestParams, RagSaveEmbeddingsParams, RagSaveEmbeddingsResult, RagSearchParams, RagSearchResult, RagDeleteEmbeddingsParams, RagReindexParams, RagReindexResult, RagWorkspaceInfo, RagCloseWorkspaceParams, RagDeleteWorkspaceParams } from "../../schemas/index";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Chunks documents into smaller pieces for embedding.
|
|
4
|
+
* Part of the segregated flow: ragChunk() → embed() → ragSaveEmbeddings()
|
|
4
5
|
*
|
|
5
|
-
* @param params - The parameters for
|
|
6
|
-
* @param params.
|
|
7
|
-
* @param params.
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
*
|
|
11
|
-
* @
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
* @param params - The parameters for chunking
|
|
7
|
+
* @param params.documents - Documents to chunk (string or array)
|
|
8
|
+
* @param params.chunkOpts - Chunking options (chunkSize, chunkOverlap, chunkStrategy)
|
|
9
|
+
* @returns Array of chunk results with id and content
|
|
10
|
+
* @throws {RAGChunkFailedError} When the operation fails
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* const chunks = await ragChunk({
|
|
15
|
+
* documents: ["Long document text here..."],
|
|
16
|
+
* chunkOpts: {
|
|
17
|
+
* chunkSize: 256,
|
|
18
|
+
* chunkOverlap: 50,
|
|
19
|
+
* chunkStrategy: "paragraph",
|
|
20
|
+
* },
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function ragChunk(params: RagChunkParams): Promise<RagDoc[]>;
|
|
25
|
+
/**
|
|
26
|
+
* Ingests documents into the RAG vector database.
|
|
27
|
+
* Full pipeline: chunk → embed → save
|
|
28
|
+
*
|
|
29
|
+
* **Workspace lifecycle:** This operation implicitly opens (or creates) the workspace.
|
|
30
|
+
* The workspace remains open until closed.
|
|
31
|
+
*
|
|
32
|
+
* @param params - The parameters for ingestion
|
|
33
|
+
* @param params.modelId - The embedding model identifier
|
|
34
|
+
* @param params.documents - Documents to ingest (string or array)
|
|
35
|
+
* @param params.chunk - Whether to chunk documents (default: true)
|
|
36
|
+
* @param params.chunkOpts - Chunking options
|
|
37
|
+
* @param params.workspace - Workspace for isolated storage (default: "default"). Created if it doesn't exist.
|
|
38
|
+
* @param params.onProgress - Progress callback (stage, current, total)
|
|
39
|
+
* @param params.progressInterval - Minimum interval between progress updates in ms
|
|
40
|
+
* @returns Processing results and dropped indices
|
|
41
|
+
* @throws {RAGSaveFailedError} When the operation fails
|
|
42
|
+
* @throws {StreamEndedError} When streaming ends unexpectedly (only when using onProgress)
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* // Simple ingest
|
|
47
|
+
* const result = await ragIngest({
|
|
48
|
+
* modelId,
|
|
49
|
+
* documents: ["Document 1", "Document 2"],
|
|
50
|
+
* });
|
|
51
|
+
*
|
|
52
|
+
* // With progress tracking
|
|
53
|
+
* const result = await ragIngest({
|
|
54
|
+
* modelId,
|
|
55
|
+
* documents: ["Document 1", "Document 2"],
|
|
56
|
+
* workspace: "my-docs",
|
|
57
|
+
* onProgress: (stage, current, total) => {
|
|
58
|
+
* console.log(`[${stage}] ${current}/${total}`);
|
|
59
|
+
* },
|
|
60
|
+
* });
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare function ragIngest(params: RagIngestParams): Promise<{
|
|
15
64
|
processed: RagSaveEmbeddingsResult[];
|
|
16
65
|
droppedIndices: number[];
|
|
17
66
|
}>;
|
|
67
|
+
/**
|
|
68
|
+
* Saves pre-embedded documents to the RAG vector database.
|
|
69
|
+
* Part of the segregated flow: chunk() → embed() → saveEmbeddings()
|
|
70
|
+
*
|
|
71
|
+
* **Workspace lifecycle:** This operation implicitly opens (or creates) the workspace.
|
|
72
|
+
* The workspace remains open until closed.
|
|
73
|
+
*
|
|
74
|
+
* @param params - The parameters for saving
|
|
75
|
+
* @param params.documents - Pre-embedded documents (must have id, content, embedding, embeddingModelId)
|
|
76
|
+
* @param params.workspace - Workspace for isolated storage (default: "default"). Created if it doesn't exist.
|
|
77
|
+
* @param params.onProgress - Progress callback (stage, current, total)
|
|
78
|
+
* @param params.progressInterval - Minimum interval between progress updates in ms
|
|
79
|
+
* @returns Array of save results
|
|
80
|
+
* @throws {RAGSaveFailedError} When the operation fails
|
|
81
|
+
* @throws {StreamEndedError} When streaming ends unexpectedly (only when using onProgress)
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* // Segregated flow
|
|
86
|
+
* const chunks = await ragChunk({ documents: ["text1", "text2"] });
|
|
87
|
+
* const embeddings = await embed({ modelId, text: chunks.map(c => c.content) });
|
|
88
|
+
* const embeddedDocs = chunks.map((chunk, i) => ({
|
|
89
|
+
* ...chunk,
|
|
90
|
+
* embedding: embeddings[i],
|
|
91
|
+
* embeddingModelId: modelId,
|
|
92
|
+
* }));
|
|
93
|
+
* const result = await ragSaveEmbeddings({
|
|
94
|
+
* documents: embeddedDocs,
|
|
95
|
+
* workspace: "my-workspace",
|
|
96
|
+
* });
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare function ragSaveEmbeddings(params: RagSaveEmbeddingsParams): Promise<RagSaveEmbeddingsResult[]>;
|
|
18
100
|
/**
|
|
19
101
|
* Searches for similar documents in the RAG vector database.
|
|
20
102
|
*
|
|
103
|
+
* **Workspace lifecycle:** This operation requires an existing workspace. If the workspace
|
|
104
|
+
* doesn't exist, returns an empty array.
|
|
105
|
+
*
|
|
21
106
|
* @param params - The parameters for searching
|
|
22
107
|
* @param params.modelId - The identifier of the embedding model to use
|
|
23
108
|
* @param params.query - The search query text
|
|
24
109
|
* @param params.topK - Number of top results to retrieve (default: 5)
|
|
25
110
|
* @param params.n - Number of centroids to use for IVF index search (default: 3)
|
|
26
|
-
* @param params.workspace -
|
|
27
|
-
* @
|
|
28
|
-
* @
|
|
111
|
+
* @param params.workspace - Workspace to search in (default: "default").
|
|
112
|
+
* @returns Array of search results with id, content, and score. Empty array if workspace doesn't exist.
|
|
113
|
+
* @throws {RAGSearchFailedError} When the operation fails
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const results = await ragSearch({
|
|
118
|
+
* modelId,
|
|
119
|
+
* query: "AI and machine learning",
|
|
120
|
+
* topK: 5,
|
|
121
|
+
* workspace: "my-docs",
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
29
124
|
*/
|
|
30
125
|
export declare function ragSearch(params: RagSearchParams): Promise<RagSearchResult[]>;
|
|
31
126
|
/**
|
|
32
127
|
* Deletes document embeddings from the RAG vector database.
|
|
33
128
|
*
|
|
129
|
+
* **Workspace lifecycle:** This operation requires an existing workspace.
|
|
130
|
+
*
|
|
34
131
|
* @param params - The parameters for deleting embeddings
|
|
35
|
-
* @param params.modelId - The identifier of the embedding model (must match workspace model)
|
|
36
132
|
* @param params.ids - Array of document IDs to delete
|
|
37
|
-
* @param params.workspace -
|
|
38
|
-
* @throws {
|
|
39
|
-
*
|
|
133
|
+
* @param params.workspace - Workspace to delete from (default: "default")
|
|
134
|
+
* @throws {RAGDeleteFailedError} When the operation fails or workspace doesn't exist
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* await ragDeleteEmbeddings({
|
|
139
|
+
* ids: ["doc-1", "doc-2"],
|
|
140
|
+
* workspace: "my-docs",
|
|
141
|
+
* });
|
|
142
|
+
* ```
|
|
143
|
+
*/
|
|
144
|
+
export declare function ragDeleteEmbeddings(params: RagDeleteEmbeddingsParams): Promise<void>;
|
|
145
|
+
/**
|
|
146
|
+
* Reindexes the RAG database to optimize search performance.
|
|
147
|
+
* For HyperDB, this rebalances centroids using k-means clustering.
|
|
148
|
+
*
|
|
149
|
+
* **Workspace lifecycle:** This operation requires an existing workspace.
|
|
150
|
+
*
|
|
151
|
+
* **Note:** Reindex requires a minimum number of documents to perform clustering.
|
|
152
|
+
* For HyperDB, this is 16 documents by default. If there are insufficient documents,
|
|
153
|
+
* `reindexed` will be `false` with `details` explaining the reason.
|
|
154
|
+
*
|
|
155
|
+
* @param params - The parameters for reindexing
|
|
156
|
+
* @param params.workspace - Workspace to reindex (default: "default"). Must already exist.
|
|
157
|
+
* @param params.onProgress - Progress callback (stage, current, total)
|
|
158
|
+
* @returns Reindex result with `reindexed` boolean and optional `details`
|
|
159
|
+
* @throws {RAGSaveFailedError} When the operation fails or workspace doesn't exist
|
|
160
|
+
* @throws {StreamEndedError} When streaming ends unexpectedly (only when using onProgress)
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* // Simple reindex
|
|
165
|
+
* const result = await ragReindex({
|
|
166
|
+
* workspace: "my-docs",
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* // Check result
|
|
170
|
+
* if (!result.reindexed) {
|
|
171
|
+
* console.log("Reindex skipped:", result.details?.reason);
|
|
172
|
+
* }
|
|
173
|
+
*
|
|
174
|
+
* // With progress tracking
|
|
175
|
+
* const result = await ragReindex({
|
|
176
|
+
* workspace: "my-docs",
|
|
177
|
+
* onProgress: (stage, current, total) => {
|
|
178
|
+
* console.log(`[${stage}] ${current}/${total}`);
|
|
179
|
+
* },
|
|
180
|
+
* });
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare function ragReindex(params: RagReindexParams): Promise<RagReindexResult>;
|
|
184
|
+
/**
|
|
185
|
+
* Lists all RAG workspaces with their open status.
|
|
186
|
+
*
|
|
187
|
+
* Returns all workspaces that exist on disk. The `open` field indicates whether
|
|
188
|
+
* the workspace is currently loaded in memory and holding active resources
|
|
189
|
+
* (Corestore, HyperDB adapter, and possibly a RAG instance).
|
|
190
|
+
*
|
|
191
|
+
* @returns Array of workspace info with name and open status
|
|
192
|
+
* @throws {RAGListWorkspacesFailedError} When the operation fails
|
|
193
|
+
*
|
|
194
|
+
* @example
|
|
195
|
+
* ```typescript
|
|
196
|
+
* const workspaces = await ragListWorkspaces();
|
|
197
|
+
* // [{ name: "default", open: true }, { name: "my-docs", open: false }]
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare function ragListWorkspaces(): Promise<RagWorkspaceInfo[]>;
|
|
201
|
+
/**
|
|
202
|
+
* Closes a RAG workspace, releasing in-memory resources (Corestore, HyperDB adapter, RAG instance).
|
|
203
|
+
*
|
|
204
|
+
* **Workspace lifecycle:** Workspaces are implicitly opened.
|
|
205
|
+
* This function explicitly closes them, releasing memory and file locks. The workspace data
|
|
206
|
+
* remains on disk unless `deleteOnClose` is set to true.
|
|
207
|
+
*
|
|
208
|
+
* @param params - The parameters for closing
|
|
209
|
+
* @param params.workspace - Name of the workspace to close (default: "default")
|
|
210
|
+
* @param params.deleteOnClose - If true, deletes the workspace data from disk after closing (default: false)
|
|
211
|
+
* @throws {RAGCloseWorkspaceFailedError} When the operation fails
|
|
212
|
+
*
|
|
213
|
+
* @example
|
|
214
|
+
* ```typescript
|
|
215
|
+
* // Close a specific workspace
|
|
216
|
+
* await ragCloseWorkspace({ workspace: "my-docs" });
|
|
217
|
+
*
|
|
218
|
+
* // Close and delete in one call
|
|
219
|
+
* await ragCloseWorkspace({ workspace: "my-docs", deleteOnClose: true });
|
|
220
|
+
* ```
|
|
221
|
+
*/
|
|
222
|
+
export declare function ragCloseWorkspace(params?: RagCloseWorkspaceParams): Promise<void>;
|
|
223
|
+
/**
|
|
224
|
+
* Deletes a RAG workspace and all its data.
|
|
225
|
+
* The workspace must not be currently loaded/in-use.
|
|
226
|
+
*
|
|
227
|
+
* @param params - The parameters for deletion
|
|
228
|
+
* @param params.workspace - Name of the workspace to delete
|
|
229
|
+
* @throws {RAGDeleteFailedError} When the workspace doesn't exist or is currently loaded
|
|
230
|
+
*
|
|
231
|
+
* @example
|
|
232
|
+
* ```typescript
|
|
233
|
+
* await ragDeleteWorkspace({ workspace: "my-docs" });
|
|
234
|
+
* ```
|
|
40
235
|
*/
|
|
41
|
-
export declare function
|
|
236
|
+
export declare function ragDeleteWorkspace(params: RagDeleteWorkspaceParams): Promise<void>;
|
|
42
237
|
//# sourceMappingURL=rag.d.ts.map
|