@konneal/engine 0.2.164 → 0.2.165
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/dist/ask-LBAELODD.js +16 -0
- package/dist/{chunk-GVCOGEJC.js → chunk-35NEP7QL.js} +6 -6
- package/dist/{chunk-K7UGBTBZ.js → chunk-6GJGMM5G.js} +4 -4
- package/dist/{chunk-E74MNLBC.js → chunk-7SLZ5OEO.js} +68 -3
- package/dist/{chunk-D6UUAL7I.js → chunk-C67BN6G3.js} +1 -1
- package/dist/{chunk-ZD6TYLET.js → chunk-DNKWDI4G.js} +4 -0
- package/dist/{chunk-GJATVGBS.js → chunk-HIQSYUAU.js} +1 -1
- package/dist/{chunk-FHRGC6TP.js → chunk-POW7OTLB.js} +1 -1
- package/dist/{chunk-K5WL3DKH.js → chunk-X6GUTX76.js} +3 -3
- package/dist/config.d.ts +1 -0
- package/dist/search-BTPZ6U63.js +14 -0
- package/dist/{tools-JZY6GSYC.js → tools-OCR2HLT5.js} +4 -4
- package/dist/worker_mcp/src/index.js +2 -2
- package/dist/worker_public/src/config.js +1 -1
- package/dist/worker_public/src/index.js +10 -10
- package/dist/worker_public/src/requestScope.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/src/config.ts +4 -0
- package/workers/worker_public/src/stages/index.ts +2 -0
- package/workers/worker_public/src/stages/vlmFigureRerank.ts +80 -0
- package/dist/ask-B7XXKYZP.js +0 -16
- package/dist/search-IXNVNOOY.js +0 -14
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleAsk
|
|
3
|
+
} from "./chunk-35NEP7QL.js";
|
|
4
|
+
import "./chunk-ECOYO7EX.js";
|
|
5
|
+
import "./chunk-X6GUTX76.js";
|
|
6
|
+
import "./chunk-7SLZ5OEO.js";
|
|
7
|
+
import "./chunk-POW7OTLB.js";
|
|
8
|
+
import "./chunk-HIQSYUAU.js";
|
|
9
|
+
import "./chunk-ETLSWSZ7.js";
|
|
10
|
+
import "./chunk-C67BN6G3.js";
|
|
11
|
+
import "./chunk-DNKWDI4G.js";
|
|
12
|
+
import "./chunk-3FYJM7LH.js";
|
|
13
|
+
import "./chunk-LSZTJI7V.js";
|
|
14
|
+
export {
|
|
15
|
+
handleAsk
|
|
16
|
+
};
|
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
tableRetyped,
|
|
33
33
|
toolNote,
|
|
34
34
|
verdictNote
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-X6GUTX76.js";
|
|
36
36
|
import {
|
|
37
37
|
NO_CONTEXT,
|
|
38
38
|
STAGE_NAMES,
|
|
@@ -75,18 +75,18 @@ import {
|
|
|
75
75
|
tokenBudget,
|
|
76
76
|
understandQuery,
|
|
77
77
|
usageTotal
|
|
78
|
-
} from "./chunk-
|
|
78
|
+
} from "./chunk-7SLZ5OEO.js";
|
|
79
79
|
import {
|
|
80
80
|
embed,
|
|
81
81
|
generateOnce
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-POW7OTLB.js";
|
|
83
83
|
import {
|
|
84
84
|
corsHeaders,
|
|
85
85
|
err,
|
|
86
86
|
json,
|
|
87
87
|
readJson,
|
|
88
88
|
validateQuery
|
|
89
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-HIQSYUAU.js";
|
|
90
90
|
import {
|
|
91
91
|
cacheableAnswer,
|
|
92
92
|
canonicalRefusal,
|
|
@@ -99,7 +99,7 @@ import {
|
|
|
99
99
|
requestSalt,
|
|
100
100
|
resolveRequestScope,
|
|
101
101
|
standardKeysFrom
|
|
102
|
-
} from "./chunk-
|
|
102
|
+
} from "./chunk-C67BN6G3.js";
|
|
103
103
|
import {
|
|
104
104
|
LIMITS,
|
|
105
105
|
MODELS,
|
|
@@ -110,7 +110,7 @@ import {
|
|
|
110
110
|
requestEffort,
|
|
111
111
|
roleModel,
|
|
112
112
|
sha256Hex
|
|
113
|
-
} from "./chunk-
|
|
113
|
+
} from "./chunk-DNKWDI4G.js";
|
|
114
114
|
import {
|
|
115
115
|
P
|
|
116
116
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -6,24 +6,24 @@ import {
|
|
|
6
6
|
sessionFrom,
|
|
7
7
|
telemetry,
|
|
8
8
|
understandQuery
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-7SLZ5OEO.js";
|
|
10
10
|
import {
|
|
11
11
|
corsHeaders,
|
|
12
12
|
err,
|
|
13
13
|
json,
|
|
14
14
|
readJson,
|
|
15
15
|
validateQuery
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-HIQSYUAU.js";
|
|
17
17
|
import {
|
|
18
18
|
entitlementScope,
|
|
19
19
|
standardKeysFrom
|
|
20
|
-
} from "./chunk-
|
|
20
|
+
} from "./chunk-C67BN6G3.js";
|
|
21
21
|
import {
|
|
22
22
|
LIMITS,
|
|
23
23
|
MODELS,
|
|
24
24
|
num,
|
|
25
25
|
sha256Hex
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-DNKWDI4G.js";
|
|
27
27
|
import {
|
|
28
28
|
portModelRunner
|
|
29
29
|
} from "./chunk-LSZTJI7V.js";
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed,
|
|
3
3
|
rerank
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-POW7OTLB.js";
|
|
5
5
|
import {
|
|
6
6
|
bubbleConfirmPage,
|
|
7
7
|
isAllowedBubbleOrigin
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-HIQSYUAU.js";
|
|
9
9
|
import {
|
|
10
10
|
DATASETS,
|
|
11
11
|
LIMITS,
|
|
@@ -15,12 +15,13 @@ import {
|
|
|
15
15
|
processExpansion,
|
|
16
16
|
sha256Hex,
|
|
17
17
|
today
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-DNKWDI4G.js";
|
|
19
19
|
import {
|
|
20
20
|
P
|
|
21
21
|
} from "./chunk-3FYJM7LH.js";
|
|
22
22
|
import {
|
|
23
23
|
hasLane,
|
|
24
|
+
portBlobs,
|
|
24
25
|
portIndex,
|
|
25
26
|
portModelRunner,
|
|
26
27
|
portStore
|
|
@@ -22921,6 +22922,69 @@ var lexicalRrf = {
|
|
|
22921
22922
|
}
|
|
22922
22923
|
};
|
|
22923
22924
|
|
|
22925
|
+
// workers/worker_public/src/stages/vlmFigureRerank.ts
|
|
22926
|
+
var FIGURE_Q = /\bfig(ure|s)?\b/i;
|
|
22927
|
+
function parsePick(text, kept) {
|
|
22928
|
+
const t = text;
|
|
22929
|
+
const s8 = typeof text === "string" ? text : typeof t?.response === "string" ? t.response : t?.choices?.[0]?.message?.content ?? "";
|
|
22930
|
+
const pick = Number(String(s8).match(/"pick"\s*:\s*(\d+)/)?.[1] ?? 0);
|
|
22931
|
+
return pick >= 1 && pick <= kept ? pick : 0;
|
|
22932
|
+
}
|
|
22933
|
+
var vlmFigureRerank = {
|
|
22934
|
+
name: "vlm-figure-rerank",
|
|
22935
|
+
failure: "additive",
|
|
22936
|
+
when: (c) => FIGURE_Q.test(c.query) && c.finalHits.some((h) => h.metadata.block === "figure" && h.metadata.unit_id),
|
|
22937
|
+
run: async (c) => {
|
|
22938
|
+
const figures = c.finalHits.filter((h) => h.metadata.block === "figure" && h.metadata.unit_id).slice(0, 3);
|
|
22939
|
+
if (!figures.length) return;
|
|
22940
|
+
try {
|
|
22941
|
+
const ids = figures.map((h) => String(h.metadata.unit_id));
|
|
22942
|
+
const ph = ids.map((_, i) => `?${i + 1}`).join(",");
|
|
22943
|
+
const rows = await portStore(c.env).prepare(
|
|
22944
|
+
`SELECT unit_id, json_extract(payload,'$.uri') AS uri FROM unit_payloads WHERE unit_id IN (${ph})`
|
|
22945
|
+
).bind(...ids).all();
|
|
22946
|
+
const uris = new Map((rows.results ?? []).map((r) => [r.unit_id, r.uri]));
|
|
22947
|
+
const content = [
|
|
22948
|
+
{
|
|
22949
|
+
type: "text",
|
|
22950
|
+
text: `Question: ${c.query}
|
|
22951
|
+
|
|
22952
|
+
Which of these figures best answers the question? Reply with ONLY: {"pick": N} using the image's number, or {"pick": 0} if none is relevant.`
|
|
22953
|
+
}
|
|
22954
|
+
];
|
|
22955
|
+
const kept = [];
|
|
22956
|
+
let n = 0;
|
|
22957
|
+
for (const h of figures) {
|
|
22958
|
+
const uri = String(uris.get(String(h.metadata.unit_id)) ?? "");
|
|
22959
|
+
const m = uri.match(/^\/assets\/(.+)/);
|
|
22960
|
+
if (!m) continue;
|
|
22961
|
+
const obj = await portBlobs(c.env).get(m[1]);
|
|
22962
|
+
if (!obj?.body) continue;
|
|
22963
|
+
const buf = new Uint8Array(await new Response(obj.body).arrayBuffer());
|
|
22964
|
+
let binary = "";
|
|
22965
|
+
for (let i = 0; i < buf.length; i += 8192) binary += String.fromCharCode(...buf.subarray(i, i + 8192));
|
|
22966
|
+
n += 1;
|
|
22967
|
+
content.push({ type: "text", text: `Image ${n}:` });
|
|
22968
|
+
content.push({ type: "image_url", image_url: { url: `data:image/png;base64,${btoa(binary)}` } });
|
|
22969
|
+
kept.push({ h, label: n });
|
|
22970
|
+
}
|
|
22971
|
+
if (!kept.length) return;
|
|
22972
|
+
const raced = await Promise.race([
|
|
22973
|
+
portModelRunner(c.env).run({ model: MODELS.vlmFigure, messages: [{ role: "user", content }], maxTokens: 256, effort: "low" }),
|
|
22974
|
+
new Promise((r) => setTimeout(() => r(null), 15e3))
|
|
22975
|
+
]);
|
|
22976
|
+
const pick = parsePick(raced?.text ?? raced, kept.length);
|
|
22977
|
+
const chosen = kept.find((k) => k.label === pick);
|
|
22978
|
+
if (!chosen) return;
|
|
22979
|
+
const top = Math.max(...c.finalHits.map((h) => h.rerank_score ?? h.score ?? 0));
|
|
22980
|
+
chosen.h.rerank_score = top + 1;
|
|
22981
|
+
c.finalHits = [chosen.h, ...c.finalHits.filter((h) => h !== chosen.h)];
|
|
22982
|
+
console.log("vlm-figure-rerank: promoted", chosen.h.metadata.unit_id, "over", c.finalHits.length - 1, "text-ranked hits");
|
|
22983
|
+
} catch {
|
|
22984
|
+
}
|
|
22985
|
+
}
|
|
22986
|
+
};
|
|
22987
|
+
|
|
22924
22988
|
// workers/worker_public/src/stages/termNudge.ts
|
|
22925
22989
|
var termNudge = {
|
|
22926
22990
|
name: "term-nudge",
|
|
@@ -23419,6 +23483,7 @@ var STAGES = [
|
|
|
23419
23483
|
typedPin,
|
|
23420
23484
|
sectionDescent,
|
|
23421
23485
|
dedup,
|
|
23486
|
+
vlmFigureRerank,
|
|
23422
23487
|
windowFloor
|
|
23423
23488
|
];
|
|
23424
23489
|
var STAGE_NAMES = STAGES.map((s8) => s8.name);
|
|
@@ -11,6 +11,10 @@ var MODELS = {
|
|
|
11
11
|
// Vision image-parts land with answer contract v2; text answers work now.
|
|
12
12
|
anon: "@cf/zai-org/glm-5.3-flash",
|
|
13
13
|
member: "@cf/zai-org/glm-5.3-flash",
|
|
14
|
+
// the VLM figure rerank (TODO.sota/18.3): the newly-landed
|
|
15
|
+
// vision-capable MoE scores figure IMAGES against figure-seeking
|
|
16
|
+
// questions — one bounded call per figure question, ablatable stage
|
|
17
|
+
vlmFigure: "@cf/deepseek-ai/deepseek-v4.1-flash-1017",
|
|
14
18
|
// hot-path understanding/summarize stays on the cheap Qwen (cost-first lane)
|
|
15
19
|
understand: "@cf/qwen/qwen3-30b-a3b-fp8",
|
|
16
20
|
// the api_call act's intent-to-act mapping (TODO.ai-platform/09) — the
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-POW7OTLB.js";
|
|
4
4
|
import {
|
|
5
5
|
standardKeysFrom
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-C67BN6G3.js";
|
|
7
7
|
import {
|
|
8
8
|
THRESHOLDS
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-DNKWDI4G.js";
|
|
10
10
|
import {
|
|
11
11
|
P
|
|
12
12
|
} from "./chunk-3FYJM7LH.js";
|
package/dist/config.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ export declare const MODELS: {
|
|
|
3
3
|
readonly rerank: "@cf/baai/bge-reranker-base";
|
|
4
4
|
readonly anon: "@cf/zai-org/glm-5.3-flash";
|
|
5
5
|
readonly member: "@cf/zai-org/glm-5.3-flash";
|
|
6
|
+
readonly vlmFigure: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
6
7
|
readonly understand: "@cf/qwen/qwen3-30b-a3b-fp8";
|
|
7
8
|
readonly acts: "@cf/qwen/qwen3-30b-a3b-fp8";
|
|
8
9
|
readonly fallback: "@cf/qwen/qwen3-30b-a3b-fp8";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleSearch
|
|
3
|
+
} from "./chunk-6GJGMM5G.js";
|
|
4
|
+
import "./chunk-7SLZ5OEO.js";
|
|
5
|
+
import "./chunk-POW7OTLB.js";
|
|
6
|
+
import "./chunk-HIQSYUAU.js";
|
|
7
|
+
import "./chunk-ETLSWSZ7.js";
|
|
8
|
+
import "./chunk-C67BN6G3.js";
|
|
9
|
+
import "./chunk-DNKWDI4G.js";
|
|
10
|
+
import "./chunk-3FYJM7LH.js";
|
|
11
|
+
import "./chunk-LSZTJI7V.js";
|
|
12
|
+
export {
|
|
13
|
+
handleSearch
|
|
14
|
+
};
|
|
@@ -4,10 +4,10 @@ import {
|
|
|
4
4
|
parseToolCall,
|
|
5
5
|
runTool,
|
|
6
6
|
toolNote
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
10
|
-
import "./chunk-
|
|
7
|
+
} from "./chunk-X6GUTX76.js";
|
|
8
|
+
import "./chunk-POW7OTLB.js";
|
|
9
|
+
import "./chunk-C67BN6G3.js";
|
|
10
|
+
import "./chunk-DNKWDI4G.js";
|
|
11
11
|
import "./chunk-3FYJM7LH.js";
|
|
12
12
|
import "./chunk-LSZTJI7V.js";
|
|
13
13
|
export {
|
|
@@ -4,16 +4,16 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-35NEP7QL.js";
|
|
8
8
|
import "../../chunk-ECOYO7EX.js";
|
|
9
9
|
import {
|
|
10
10
|
TOOLS_REGISTRY,
|
|
11
11
|
bindModelNode,
|
|
12
12
|
modelGroundingBlock
|
|
13
|
-
} from "../../chunk-
|
|
13
|
+
} from "../../chunk-X6GUTX76.js";
|
|
14
14
|
import {
|
|
15
15
|
handleSearch
|
|
16
|
-
} from "../../chunk-
|
|
16
|
+
} from "../../chunk-6GJGMM5G.js";
|
|
17
17
|
import {
|
|
18
18
|
buildMessages,
|
|
19
19
|
citations,
|
|
@@ -38,11 +38,11 @@ import {
|
|
|
38
38
|
sessionFrom,
|
|
39
39
|
telemetry,
|
|
40
40
|
understandQuery
|
|
41
|
-
} from "../../chunk-
|
|
41
|
+
} from "../../chunk-7SLZ5OEO.js";
|
|
42
42
|
import {
|
|
43
43
|
embed,
|
|
44
44
|
generateOnce
|
|
45
|
-
} from "../../chunk-
|
|
45
|
+
} from "../../chunk-POW7OTLB.js";
|
|
46
46
|
import {
|
|
47
47
|
authenticate,
|
|
48
48
|
corsHeaders,
|
|
@@ -51,14 +51,14 @@ import {
|
|
|
51
51
|
readJson,
|
|
52
52
|
validateQuery,
|
|
53
53
|
withCors
|
|
54
|
-
} from "../../chunk-
|
|
54
|
+
} from "../../chunk-HIQSYUAU.js";
|
|
55
55
|
import {
|
|
56
56
|
canonicalRefusal
|
|
57
57
|
} from "../../chunk-ETLSWSZ7.js";
|
|
58
58
|
import {
|
|
59
59
|
entitlementScope,
|
|
60
60
|
standardKeysFrom
|
|
61
|
-
} from "../../chunk-
|
|
61
|
+
} from "../../chunk-C67BN6G3.js";
|
|
62
62
|
import {
|
|
63
63
|
LIMITS,
|
|
64
64
|
MODELS,
|
|
@@ -69,7 +69,7 @@ import {
|
|
|
69
69
|
roleModel,
|
|
70
70
|
sha256Hex,
|
|
71
71
|
today
|
|
72
|
-
} from "../../chunk-
|
|
72
|
+
} from "../../chunk-DNKWDI4G.js";
|
|
73
73
|
import {
|
|
74
74
|
P,
|
|
75
75
|
setProfile
|
|
@@ -1119,13 +1119,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1119
1119
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
1120
1120
|
body: JSON.stringify({ ...args, stream: false })
|
|
1121
1121
|
});
|
|
1122
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
1122
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-OCR2HLT5.js");
|
|
1123
1123
|
let payload;
|
|
1124
1124
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
1125
1125
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1126
1126
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1127
1127
|
} else {
|
|
1128
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1128
|
+
const res = name === "ask" ? await (await import("../../ask-LBAELODD.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-BTPZ6U63.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1129
1129
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1130
1130
|
}
|
|
1131
1131
|
telemetry(env, ctx, tier, `mcp:${name}`, null, !payload?.error, JSON.stringify(payload).length, await sha256Hex(`${name}:${JSON.stringify(args ?? {})}`), void 0, void 0, { durationMs: Date.now() - t0 });
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
requestSalt,
|
|
5
5
|
resolveRequestScope,
|
|
6
6
|
standardKeysFrom
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-C67BN6G3.js";
|
|
8
|
+
import "../../chunk-DNKWDI4G.js";
|
|
9
9
|
import "../../chunk-3FYJM7LH.js";
|
|
10
10
|
export {
|
|
11
11
|
entitlementScope,
|
package/package.json
CHANGED
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"playwright": "^1.62.1",
|
|
28
28
|
"yaml": "^2.9.1"
|
|
29
29
|
},
|
|
30
|
-
"version": "0.2.
|
|
30
|
+
"version": "0.2.165",
|
|
31
31
|
"description": "The Konneal engine: the publisher-agnostic build pipeline and API plane for standards intelligence (retrieval, answer contract, verdicts, evaluation).",
|
|
32
32
|
"license": "BSD-3-Clause",
|
|
33
33
|
"type": "module",
|
|
@@ -7,6 +7,10 @@ export const MODELS = {
|
|
|
7
7
|
// Vision image-parts land with answer contract v2; text answers work now.
|
|
8
8
|
anon: "@cf/zai-org/glm-5.3-flash",
|
|
9
9
|
member: "@cf/zai-org/glm-5.3-flash",
|
|
10
|
+
// the VLM figure rerank (TODO.sota/18.3): the newly-landed
|
|
11
|
+
// vision-capable MoE scores figure IMAGES against figure-seeking
|
|
12
|
+
// questions — one bounded call per figure question, ablatable stage
|
|
13
|
+
vlmFigure: "@cf/deepseek-ai/deepseek-v4.1-flash-1017",
|
|
10
14
|
// hot-path understanding/summarize stays on the cheap Qwen (cost-first lane)
|
|
11
15
|
understand: "@cf/qwen/qwen3-30b-a3b-fp8",
|
|
12
16
|
// the api_call act's intent-to-act mapping (TODO.ai-platform/09) — the
|
|
@@ -33,6 +33,7 @@ import { stdRefNudge } from "./stdRefNudge.ts";
|
|
|
33
33
|
import { overviewDemote } from "./overviewDemote.ts";
|
|
34
34
|
import { familyBoost } from "./familyBoost.ts";
|
|
35
35
|
import { rerankStage, lexicalRrf } from "./rerank.ts";
|
|
36
|
+
import { vlmFigureRerank } from "./vlmFigureRerank.ts";
|
|
36
37
|
import { termNudge } from "./termNudge.ts";
|
|
37
38
|
import { conceptSteer } from "./conceptSteer.ts";
|
|
38
39
|
import { editionSteer } from "./editionSteer.ts";
|
|
@@ -75,6 +76,7 @@ export const STAGES: Stage[] = [
|
|
|
75
76
|
typedPin,
|
|
76
77
|
sectionDescent,
|
|
77
78
|
dedup,
|
|
79
|
+
vlmFigureRerank,
|
|
78
80
|
windowFloor,
|
|
79
81
|
];
|
|
80
82
|
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
// VLM figure rerank (TODO.sota/18.3 — the hedge that sees past
|
|
2
|
+
// embeddings): a figure-SEEKING question's figure candidates are scored
|
|
3
|
+
// by a vision model on their actual images — the MKO figure chunks'
|
|
4
|
+
// text is thin (a breadcrumb line + a caption), so text ranking loses
|
|
5
|
+
// them to sibling tables no matter what the caption-augmented embed
|
|
6
|
+
// carries. One bounded vision call, the winner promoted to the front of
|
|
7
|
+
// the window with a rerank score above the incumbent top; every failure
|
|
8
|
+
// mode is additive (the text ranking stands). Off via the registry
|
|
9
|
+
// projection like any stage (ablate_stages drops it).
|
|
10
|
+
import { MODELS } from "../config.ts";
|
|
11
|
+
import { portBlobs, portModelRunner, portStore } from "../env.ts";
|
|
12
|
+
import type { Stage } from "./types.ts";
|
|
13
|
+
import type { Hit } from "../../../shared/chunk";
|
|
14
|
+
|
|
15
|
+
export const FIGURE_Q = /\bfig(ure|s)?\b/i;
|
|
16
|
+
|
|
17
|
+
export function parsePick(text: unknown, kept: number): number {
|
|
18
|
+
const t = text as any;
|
|
19
|
+
const s = typeof text === "string" ? text : typeof t?.response === "string" ? t.response : t?.choices?.[0]?.message?.content ?? "";
|
|
20
|
+
const pick = Number(String(s).match(/"pick"\s*:\s*(\d+)/)?.[1] ?? 0);
|
|
21
|
+
return pick >= 1 && pick <= kept ? pick : 0;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const vlmFigureRerank: Stage = {
|
|
25
|
+
name: "vlm-figure-rerank",
|
|
26
|
+
failure: "additive",
|
|
27
|
+
when: (c) => FIGURE_Q.test(c.query) && c.finalHits.some((h: Hit) => (h.metadata as any).block === "figure" && (h.metadata as any).unit_id),
|
|
28
|
+
run: async (c) => {
|
|
29
|
+
const figures = c.finalHits.filter((h: Hit) => (h.metadata as any).block === "figure" && (h.metadata as any).unit_id).slice(0, 3);
|
|
30
|
+
if (!figures.length) return;
|
|
31
|
+
try {
|
|
32
|
+
const ids = figures.map((h: Hit) => String((h.metadata as any).unit_id));
|
|
33
|
+
const ph = ids.map((_, i) => `?${i + 1}`).join(",");
|
|
34
|
+
const rows = await portStore(c.env).prepare(
|
|
35
|
+
`SELECT unit_id, json_extract(payload,'$.uri') AS uri FROM unit_payloads WHERE unit_id IN (${ph})`,
|
|
36
|
+
)
|
|
37
|
+
.bind(...ids)
|
|
38
|
+
.all();
|
|
39
|
+
const uris = new Map(((rows.results ?? []) as any[]).map((r: any) => [r.unit_id as string, r.uri as string | null]));
|
|
40
|
+
// the multimodal gotcha (2026-09-09): image parts ride a SHORT
|
|
41
|
+
// message — the question and the labels, nothing else
|
|
42
|
+
const content: any[] = [
|
|
43
|
+
{
|
|
44
|
+
type: "text",
|
|
45
|
+
text: `Question: ${c.query}\n\nWhich of these figures best answers the question? Reply with ONLY: {"pick": N} using the image's number, or {"pick": 0} if none is relevant.`,
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
const kept: { h: Hit; label: number }[] = [];
|
|
49
|
+
let n = 0;
|
|
50
|
+
for (const h of figures) {
|
|
51
|
+
const uri = String(uris.get(String((h.metadata as any).unit_id)) ?? "");
|
|
52
|
+
const m = uri.match(/^\/assets\/(.+)/);
|
|
53
|
+
if (!m) continue;
|
|
54
|
+
const obj = await portBlobs(c.env).get(m[1]);
|
|
55
|
+
if (!obj?.body) continue;
|
|
56
|
+
const buf = new Uint8Array(await new Response(obj.body).arrayBuffer());
|
|
57
|
+
let binary = "";
|
|
58
|
+
for (let i = 0; i < buf.length; i += 8192) binary += String.fromCharCode(...buf.subarray(i, i + 8192));
|
|
59
|
+
n += 1;
|
|
60
|
+
content.push({ type: "text", text: `Image ${n}:` });
|
|
61
|
+
content.push({ type: "image_url", image_url: { url: `data:image/png;base64,${btoa(binary)}` } });
|
|
62
|
+
kept.push({ h, label: n });
|
|
63
|
+
}
|
|
64
|
+
if (!kept.length) return;
|
|
65
|
+
const raced: any = await Promise.race([
|
|
66
|
+
portModelRunner(c.env).run({ model: MODELS.vlmFigure, messages: [{ role: "user", content }], maxTokens: 256, effort: "low" }),
|
|
67
|
+
new Promise<null>((r) => setTimeout(() => r(null), 15000)),
|
|
68
|
+
]);
|
|
69
|
+
const pick = parsePick(raced?.text ?? raced, kept.length);
|
|
70
|
+
const chosen = kept.find((k) => k.label === pick);
|
|
71
|
+
if (!chosen) return;
|
|
72
|
+
const top = Math.max(...c.finalHits.map((h: Hit) => h.rerank_score ?? h.score ?? 0));
|
|
73
|
+
chosen.h.rerank_score = top + 1;
|
|
74
|
+
c.finalHits = [chosen.h, ...c.finalHits.filter((h: Hit) => h !== chosen.h)];
|
|
75
|
+
console.log("vlm-figure-rerank: promoted", (chosen.h.metadata as any).unit_id, "over", c.finalHits.length - 1, "text-ranked hits");
|
|
76
|
+
} catch {
|
|
77
|
+
// additive — the text ranking stands
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
};
|
package/dist/ask-B7XXKYZP.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleAsk
|
|
3
|
-
} from "./chunk-GVCOGEJC.js";
|
|
4
|
-
import "./chunk-ECOYO7EX.js";
|
|
5
|
-
import "./chunk-K5WL3DKH.js";
|
|
6
|
-
import "./chunk-E74MNLBC.js";
|
|
7
|
-
import "./chunk-FHRGC6TP.js";
|
|
8
|
-
import "./chunk-GJATVGBS.js";
|
|
9
|
-
import "./chunk-ETLSWSZ7.js";
|
|
10
|
-
import "./chunk-D6UUAL7I.js";
|
|
11
|
-
import "./chunk-ZD6TYLET.js";
|
|
12
|
-
import "./chunk-3FYJM7LH.js";
|
|
13
|
-
import "./chunk-LSZTJI7V.js";
|
|
14
|
-
export {
|
|
15
|
-
handleAsk
|
|
16
|
-
};
|
package/dist/search-IXNVNOOY.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleSearch
|
|
3
|
-
} from "./chunk-K7UGBTBZ.js";
|
|
4
|
-
import "./chunk-E74MNLBC.js";
|
|
5
|
-
import "./chunk-FHRGC6TP.js";
|
|
6
|
-
import "./chunk-GJATVGBS.js";
|
|
7
|
-
import "./chunk-ETLSWSZ7.js";
|
|
8
|
-
import "./chunk-D6UUAL7I.js";
|
|
9
|
-
import "./chunk-ZD6TYLET.js";
|
|
10
|
-
import "./chunk-3FYJM7LH.js";
|
|
11
|
-
import "./chunk-LSZTJI7V.js";
|
|
12
|
-
export {
|
|
13
|
-
handleSearch
|
|
14
|
-
};
|