pi-mega-compact 0.20.43 → 0.20.44
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/assets/vector-cortex/encoder-v1/manifest.json +1 -1
- package/assets/vector-cortex/encoder-v1/model-card.json +1 -1
- package/assets/vector-cortex/encoder-v1/model.onnx +0 -0
- package/assets/vector-cortex/encoder-v1/tokenizer.json +1 -1
- package/dist/config/vector-cortex-enc0b.js +34 -0
- package/dist/config/vector-cortex.js +1 -1
- package/dist/config.js +1 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-vector-cortex.js +1 -0
- package/dist/src/config/vector-cortex-enc0b.js +34 -0
- package/dist/src/config/vector-cortex.js +1 -1
- package/dist/src/config.js +1 -1
- package/dist/src/vector-cortex/encoder/emit.js +2 -0
- package/dist/src/vector-cortex/encoder/encoder-onnx-dispatch.js +58 -0
- package/dist/src/vector-cortex/encoder/onnx.js +147 -0
- package/dist/src/vector-cortex/encoder/runtime-wasm.js +17 -4
- package/dist/src/vector-cortex/encoder/runtime.js +17 -7
- package/dist/src/vector-cortex/encoder/types-vc2c.js +9 -0
- package/dist/src/vector-cortex/encoder/types.js +1 -1
- package/dist/vector-cortex/encoder/emit.js +2 -0
- package/dist/vector-cortex/encoder/encoder-onnx-dispatch.js +58 -0
- package/dist/vector-cortex/encoder/onnx.js +147 -0
- package/dist/vector-cortex/encoder/runtime-wasm.js +17 -4
- package/dist/vector-cortex/encoder/runtime.js +17 -7
- package/dist/vector-cortex/encoder/types-vc2c.js +9 -0
- package/dist/vector-cortex/encoder/types.js +1 -1
- package/extensions/dashboard-server/routes-rag-settings-vector-cortex.ts +6 -0
- package/package.json +3 -2
- package/src/config/vector-cortex-enc0b.ts +36 -0
- package/src/config/vector-cortex.ts +1 -1
- package/src/config.ts +1 -0
- package/src/vector-cortex/encoder/emit.ts +5 -1
- package/src/vector-cortex/encoder/encoder-onnx-dispatch.ts +76 -0
- package/src/vector-cortex/encoder/onnx.ts +198 -0
- package/src/vector-cortex/encoder/runtime-wasm.ts +20 -7
- package/src/vector-cortex/encoder/runtime.ts +27 -9
- package/src/vector-cortex/encoder/types-vc2c.ts +10 -0
- package/src/vector-cortex/encoder/types.ts +1 -0
|
@@ -36,7 +36,7 @@ export interface OrtWasmModule {
|
|
|
36
36
|
opts: { executionProviders: string[]; intraOpNumThreads: number },
|
|
37
37
|
): Promise<{
|
|
38
38
|
run(
|
|
39
|
-
feeds: Record<string,
|
|
39
|
+
feeds: Record<string, { data: BigInt64Array; dims: number[]; type: string }>,
|
|
40
40
|
outputNames: string[],
|
|
41
41
|
): Promise<Record<string, { data: Float32Array }>>;
|
|
42
42
|
}>;
|
|
@@ -51,8 +51,8 @@ export interface WasmSession {
|
|
|
51
51
|
readonly semanticWidth: number;
|
|
52
52
|
/** The per-asset token capacity cap (normative <= 512). */
|
|
53
53
|
readonly maxTokens: number;
|
|
54
|
-
/** Run one inference over
|
|
55
|
-
infer(
|
|
54
|
+
/** Run one inference over shape-checked token IDs (int64 input_ids). */
|
|
55
|
+
infer(tokens: number[]): Promise<Float32Array>;
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
/** True if `onnxruntime-web` resolves on this host (loading is best-effort).
|
|
@@ -94,10 +94,23 @@ export async function createWasmSession(
|
|
|
94
94
|
opset: ENCODER_OPSET,
|
|
95
95
|
semanticWidth: ENCODER_SEMANTIC_WIDTH,
|
|
96
96
|
maxTokens,
|
|
97
|
-
async infer(
|
|
98
|
-
const
|
|
99
|
-
const
|
|
100
|
-
const
|
|
97
|
+
async infer(tokens: number[]): Promise<Float32Array> {
|
|
98
|
+
const n = tokens.length;
|
|
99
|
+
const inputIds = new BigInt64Array(n);
|
|
100
|
+
const attentionMask = new BigInt64Array(n);
|
|
101
|
+
const tokenTypeIds = new BigInt64Array(n);
|
|
102
|
+
for (let i = 0; i < n; i++) {
|
|
103
|
+
inputIds[i] = BigInt(tokens[i]!);
|
|
104
|
+
attentionMask[i] = 1n;
|
|
105
|
+
tokenTypeIds[i] = 0n;
|
|
106
|
+
}
|
|
107
|
+
const feeds = {
|
|
108
|
+
input_ids: { data: inputIds, dims: [1, n], type: "int64" },
|
|
109
|
+
attention_mask: { data: attentionMask, dims: [1, n], type: "int64" },
|
|
110
|
+
token_type_ids: { data: tokenTypeIds, dims: [1, n], type: "int64" },
|
|
111
|
+
};
|
|
112
|
+
const results = await session.run(feeds, ["sentence_embedding"]);
|
|
113
|
+
const out = results["sentence_embedding"];
|
|
101
114
|
if (!out || !(out.data instanceof Float32Array)) {
|
|
102
115
|
return new Float32Array(ENCODER_SEMANTIC_WIDTH);
|
|
103
116
|
}
|
|
@@ -86,6 +86,7 @@ import { selectRuntimeBackend } from "./runtime-select.js";
|
|
|
86
86
|
import { emitRuntimeSelected } from "./runtime-emit.js";
|
|
87
87
|
import { projectSemantic, seedFromBytes } from "./runtime-stub.js";
|
|
88
88
|
import { STATE_DIR_DEFAULT } from "../../config.js";
|
|
89
|
+
import { tryBuildOnnx, type OnnxDispatchState, NO_ONNX } from "./encoder-onnx-dispatch.js";
|
|
89
90
|
|
|
90
91
|
/** Bytes a single encoder-owned projection buffer commits to the marginal
|
|
91
92
|
* footprint (Float32Array, 4 bytes per element). */
|
|
@@ -136,9 +137,16 @@ function normalizePlatform(p: EncoderPlatform | null): EncoderPlatform | "unsupp
|
|
|
136
137
|
return p === null ? "unsupported" : p;
|
|
137
138
|
}
|
|
138
139
|
|
|
140
|
+
/** The concrete runtime returned by createEncoderRuntime — the base
|
|
141
|
+
* EncoderRuntime interface plus the ENC-0b ONNX dispatch state. */
|
|
142
|
+
export type EncoderRuntimeHandle = EncoderRuntime & {
|
|
143
|
+
/** ENC-0b: the ONNX dispatch state (null when ENC_0B is off or not built). */
|
|
144
|
+
readonly onnxState: OnnxDispatchState;
|
|
145
|
+
};
|
|
146
|
+
|
|
139
147
|
export function createEncoderRuntime(
|
|
140
148
|
options: CreateEncoderRuntimeOptions = {},
|
|
141
|
-
):
|
|
149
|
+
): EncoderRuntimeHandle {
|
|
142
150
|
const reporter = options.reporter ?? createEncoderReporter();
|
|
143
151
|
const host = mergeHost(options.host);
|
|
144
152
|
const forced = options.forcedMode;
|
|
@@ -152,6 +160,7 @@ export function createEncoderRuntime(
|
|
|
152
160
|
let verified = false;
|
|
153
161
|
let maxTokens = ENCODER_MAX_TOKENS;
|
|
154
162
|
let selfAllocated = 0;
|
|
163
|
+
let onnxState: OnnxDispatchState = NO_ONNX;
|
|
155
164
|
|
|
156
165
|
const footprint = (): number => selfAllocated + host.allocatedBytes();
|
|
157
166
|
|
|
@@ -161,12 +170,14 @@ export function createEncoderRuntime(
|
|
|
161
170
|
reporter.runtimeDemoted({ reason: code, mode: rmode, platform: plat()?.toString() ?? "unsupported" });
|
|
162
171
|
};
|
|
163
172
|
|
|
164
|
-
const runtime:
|
|
173
|
+
const runtime: EncoderRuntimeHandle = {
|
|
165
174
|
schema: "encoder-runtime-v1",
|
|
166
|
-
// Live getter so `mode` always reflects the latest load/demote outcome.
|
|
167
175
|
get mode(): EncoderMode {
|
|
168
176
|
return mode;
|
|
169
177
|
},
|
|
178
|
+
get onnxState(): OnnxDispatchState {
|
|
179
|
+
return onnxState;
|
|
180
|
+
},
|
|
170
181
|
load(assetDir: string): EncoderLoadResult {
|
|
171
182
|
if (rolledBack) {
|
|
172
183
|
// Q04: report the rollback with its own code, not MANIFEST_INVALID.
|
|
@@ -225,6 +236,14 @@ export function createEncoderRuntime(
|
|
|
225
236
|
emitRuntimeSelected(host.stateDir ?? STATE_DIR_DEFAULT, chosen);
|
|
226
237
|
}
|
|
227
238
|
|
|
239
|
+
// ENC-0b: fire-and-forget ONNX session build (async, non-blocking).
|
|
240
|
+
// The sync load() contract is preserved; the session build settles
|
|
241
|
+
// asynchronously and is consumed by verifyOnnxSession for tests +
|
|
242
|
+
// future async-heavy router integration (ENC-0c).
|
|
243
|
+
if (manifest) {
|
|
244
|
+
onnxState = tryBuildOnnx(assetDir, manifest, reporter, footprint());
|
|
245
|
+
}
|
|
246
|
+
|
|
228
247
|
return {
|
|
229
248
|
ok: true,
|
|
230
249
|
mode: "A",
|
|
@@ -262,14 +281,13 @@ export function createEncoderRuntime(
|
|
|
262
281
|
};
|
|
263
282
|
}
|
|
264
283
|
const start = host.nowMs();
|
|
265
|
-
//
|
|
266
|
-
//
|
|
267
|
-
//
|
|
268
|
-
//
|
|
284
|
+
// ENC-0b builds the real ONNX session during load() (fire-and-forget);
|
|
285
|
+
// infer() continues serving the LCG placeholder until the router is
|
|
286
|
+
// wired for async inference (ENC-0c). The session is verified by tests
|
|
287
|
+
// via the runtime's verifySession() method.
|
|
269
288
|
const semantic = projectSemantic(seedFromBytes(embeddedBytes) ^ n, ENCODER_SEMANTIC_WIDTH);
|
|
270
289
|
selfAllocated = SEMANTIC_BUFFER_BYTES;
|
|
271
|
-
|
|
272
|
-
return { ok: true, semantic, rssBytes: footprint(), latencyMs, shapeError: null };
|
|
290
|
+
return { ok: true, semantic, rssBytes: footprint(), latencyMs: host.nowMs() - start, shapeError: null };
|
|
273
291
|
},
|
|
274
292
|
};
|
|
275
293
|
return runtime;
|
|
@@ -122,3 +122,13 @@ export const ENC2C_IDS: readonly string[] = [
|
|
|
122
122
|
"ENC-019",
|
|
123
123
|
"ENC-020",
|
|
124
124
|
];
|
|
125
|
+
|
|
126
|
+
/** The 6 registered ENC-0b conformance IDs (encoder-trunk fixtures). */
|
|
127
|
+
export const ENC_0B_IDS: readonly string[] = [
|
|
128
|
+
"ENC-TRUNK-001",
|
|
129
|
+
"ENC-TRUNK-002",
|
|
130
|
+
"ENC-TRUNK-003",
|
|
131
|
+
"ENC-TRUNK-004",
|
|
132
|
+
"ENC-TRUNK-005",
|
|
133
|
+
"ENC-TRUNK-006",
|
|
134
|
+
];
|