@konneal/engine 0.2.167 → 0.2.168
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-LV6WNGYK.js → ask-RUMLIO35.js} +2 -2
- package/dist/{chunk-YWXLXXGH.js → chunk-AGL4NGXY.js} +1 -1
- package/dist/{chunk-KD2AHOOQ.js → chunk-BFOCWZ7U.js} +1 -1
- package/dist/{chunk-OD3KBF4I.js → chunk-LIZJLRXZ.js} +54 -0
- package/dist/{search-ZQCAISQV.js → search-Y4Y46Y57.js} +2 -2
- package/dist/worker_public/src/index.js +4 -4
- package/package.json +1 -1
- package/workers/worker_public/src/stages/figureSeat.ts +69 -0
- package/workers/worker_public/src/stages/index.ts +2 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleAsk
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-AGL4NGXY.js";
|
|
4
4
|
import "./chunk-ECOYO7EX.js";
|
|
5
5
|
import "./chunk-PTY2OSC4.js";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-LIZJLRXZ.js";
|
|
7
7
|
import "./chunk-LU7VIMD7.js";
|
|
8
8
|
import "./chunk-QY556RJM.js";
|
|
9
9
|
import "./chunk-ETLSWSZ7.js";
|
|
@@ -22994,6 +22994,59 @@ Which of these figures best answers the question? Reply with ONLY: {"pick": N} u
|
|
|
22994
22994
|
}
|
|
22995
22995
|
};
|
|
22996
22996
|
|
|
22997
|
+
// workers/worker_public/src/stages/figureSeat.ts
|
|
22998
|
+
var figureSeat = {
|
|
22999
|
+
name: "figure-seat",
|
|
23000
|
+
failure: "additive",
|
|
23001
|
+
when: (c) => FIGURE_Q.test(c.query),
|
|
23002
|
+
run: async (c) => {
|
|
23003
|
+
try {
|
|
23004
|
+
const counts = /* @__PURE__ */ new Map();
|
|
23005
|
+
for (const h of c.finalHits.slice(0, 5)) {
|
|
23006
|
+
const dn = String(h.metadata.doc_number ?? "");
|
|
23007
|
+
if (dn) counts.set(dn, (counts.get(dn) ?? 0) + 1);
|
|
23008
|
+
}
|
|
23009
|
+
const docNumber = c.u?.doc_number ?? [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
23010
|
+
if (!docNumber) return;
|
|
23011
|
+
const seated = new Set(
|
|
23012
|
+
c.finalHits.filter((h) => h.metadata.block === "figure").map((h) => String(h.metadata.unit_id ?? h.id))
|
|
23013
|
+
);
|
|
23014
|
+
const rows = await portStore(c.env).prepare(
|
|
23015
|
+
`SELECT id, doc_id, docidentifier, clause_anchor, clause_title, doc_number, edition, language, status, corpus, tier, text, unit_id
|
|
23016
|
+
FROM chunks WHERE doc_number = ?1 AND block = 'figure' AND unit_id IS NOT NULL LIMIT 3`
|
|
23017
|
+
).bind(String(docNumber)).all();
|
|
23018
|
+
const fresh = [];
|
|
23019
|
+
for (const r of rows.results ?? []) {
|
|
23020
|
+
if (seated.has(String(r.unit_id))) continue;
|
|
23021
|
+
fresh.push({
|
|
23022
|
+
id: String(r.id),
|
|
23023
|
+
score: 0,
|
|
23024
|
+
rerank_score: 0,
|
|
23025
|
+
text: String(r.text ?? ""),
|
|
23026
|
+
metadata: {
|
|
23027
|
+
doc_id: String(r.doc_id ?? ""),
|
|
23028
|
+
docidentifier: String(r.docidentifier ?? ""),
|
|
23029
|
+
doc_number: String(r.doc_number ?? docNumber),
|
|
23030
|
+
clause_anchor: r.clause_anchor ? String(r.clause_anchor) : void 0,
|
|
23031
|
+
clause_title: r.clause_title ? String(r.clause_title) : void 0,
|
|
23032
|
+
edition: r.edition ? String(r.edition) : void 0,
|
|
23033
|
+
language: r.language ? String(r.language) : void 0,
|
|
23034
|
+
status: r.status ? String(r.status) : void 0,
|
|
23035
|
+
corpus: r.corpus ? String(r.corpus) : void 0,
|
|
23036
|
+
tier: r.tier ? String(r.tier) : void 0,
|
|
23037
|
+
block: "figure",
|
|
23038
|
+
unit_id: String(r.unit_id)
|
|
23039
|
+
}
|
|
23040
|
+
});
|
|
23041
|
+
}
|
|
23042
|
+
if (!fresh.length) return;
|
|
23043
|
+
c.finalHits = [...fresh, ...c.finalHits];
|
|
23044
|
+
console.log("figure-seat: seated", fresh.length, "figure chunk(s) of doc", docNumber);
|
|
23045
|
+
} catch {
|
|
23046
|
+
}
|
|
23047
|
+
}
|
|
23048
|
+
};
|
|
23049
|
+
|
|
22997
23050
|
// workers/worker_public/src/stages/termNudge.ts
|
|
22998
23051
|
var termNudge = {
|
|
22999
23052
|
name: "term-nudge",
|
|
@@ -23492,6 +23545,7 @@ var STAGES = [
|
|
|
23492
23545
|
typedPin,
|
|
23493
23546
|
sectionDescent,
|
|
23494
23547
|
dedup,
|
|
23548
|
+
figureSeat,
|
|
23495
23549
|
vlmFigureRerank,
|
|
23496
23550
|
windowFloor
|
|
23497
23551
|
];
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-AGL4NGXY.js";
|
|
8
8
|
import "../../chunk-ECOYO7EX.js";
|
|
9
9
|
import {
|
|
10
10
|
TOOLS_REGISTRY,
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
} from "../../chunk-PTY2OSC4.js";
|
|
14
14
|
import {
|
|
15
15
|
handleSearch
|
|
16
|
-
} from "../../chunk-
|
|
16
|
+
} from "../../chunk-BFOCWZ7U.js";
|
|
17
17
|
import {
|
|
18
18
|
buildMessages,
|
|
19
19
|
citations,
|
|
@@ -38,7 +38,7 @@ import {
|
|
|
38
38
|
sessionFrom,
|
|
39
39
|
telemetry,
|
|
40
40
|
understandQuery
|
|
41
|
-
} from "../../chunk-
|
|
41
|
+
} from "../../chunk-LIZJLRXZ.js";
|
|
42
42
|
import {
|
|
43
43
|
embed,
|
|
44
44
|
generateOnce
|
|
@@ -1125,7 +1125,7 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
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-RUMLIO35.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-Y4Y46Y57.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 });
|
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.168",
|
|
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",
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// The figure seat (TODO.sota/18.3's completion — the guaranteed place):
|
|
2
|
+
// a figure-SEEKING question deterministically seats the asked document's
|
|
3
|
+
// own figure chunks in the window. No embedding contest, no variance —
|
|
4
|
+
// the question names a figure; the document's figures get their places;
|
|
5
|
+
// the VLM rerank then orders them by image and the seeking completion
|
|
6
|
+
// attaches the block from the producer's payload. The D1 read is one
|
|
7
|
+
// bounded query (doc_number + block, LIMIT 3), additive, ablatable like
|
|
8
|
+
// any stage. Positioned BEFORE the VLM rerank so the rerank sees the
|
|
9
|
+
// seated figures and can order them by image.
|
|
10
|
+
import { FIGURE_Q } from "./vlmFigureRerank.ts";
|
|
11
|
+
import { portStore } from "../env.ts";
|
|
12
|
+
import type { Stage } from "./types.ts";
|
|
13
|
+
import type { Hit } from "../../../shared/chunk";
|
|
14
|
+
|
|
15
|
+
export const figureSeat: Stage = {
|
|
16
|
+
name: "figure-seat",
|
|
17
|
+
failure: "additive",
|
|
18
|
+
when: (c) => FIGURE_Q.test(c.query),
|
|
19
|
+
run: async (c) => {
|
|
20
|
+
try {
|
|
21
|
+
const counts = new Map<string, number>();
|
|
22
|
+
for (const h of c.finalHits.slice(0, 5)) {
|
|
23
|
+
const dn = String((h.metadata as any).doc_number ?? "");
|
|
24
|
+
if (dn) counts.set(dn, (counts.get(dn) ?? 0) + 1);
|
|
25
|
+
}
|
|
26
|
+
const docNumber = (c.u as any)?.doc_number ?? [...counts.entries()].sort((a, b) => b[1] - a[1])[0]?.[0];
|
|
27
|
+
if (!docNumber) return;
|
|
28
|
+
const seated = new Set(
|
|
29
|
+
c.finalHits.filter((h: Hit) => (h.metadata as any).block === "figure").map((h: Hit) => String((h.metadata as any).unit_id ?? h.id)),
|
|
30
|
+
);
|
|
31
|
+
const rows = await portStore(c.env)
|
|
32
|
+
.prepare(
|
|
33
|
+
`SELECT id, doc_id, docidentifier, clause_anchor, clause_title, doc_number, edition, language, status, corpus, tier, text, unit_id
|
|
34
|
+
FROM chunks WHERE doc_number = ?1 AND block = 'figure' AND unit_id IS NOT NULL LIMIT 3`,
|
|
35
|
+
)
|
|
36
|
+
.bind(String(docNumber))
|
|
37
|
+
.all();
|
|
38
|
+
const fresh: Hit[] = [];
|
|
39
|
+
for (const r of (rows.results ?? []) as any[]) {
|
|
40
|
+
if (seated.has(String(r.unit_id))) continue;
|
|
41
|
+
fresh.push({
|
|
42
|
+
id: String(r.id),
|
|
43
|
+
score: 0,
|
|
44
|
+
rerank_score: 0,
|
|
45
|
+
text: String(r.text ?? ""),
|
|
46
|
+
metadata: {
|
|
47
|
+
doc_id: String(r.doc_id ?? ""),
|
|
48
|
+
docidentifier: String(r.docidentifier ?? ""),
|
|
49
|
+
doc_number: String(r.doc_number ?? docNumber),
|
|
50
|
+
clause_anchor: r.clause_anchor ? String(r.clause_anchor) : undefined,
|
|
51
|
+
clause_title: r.clause_title ? String(r.clause_title) : undefined,
|
|
52
|
+
edition: r.edition ? String(r.edition) : undefined,
|
|
53
|
+
language: r.language ? String(r.language) : undefined,
|
|
54
|
+
status: r.status ? String(r.status) : undefined,
|
|
55
|
+
corpus: r.corpus ? String(r.corpus) : undefined,
|
|
56
|
+
tier: r.tier ? String(r.tier) : undefined,
|
|
57
|
+
block: "figure",
|
|
58
|
+
unit_id: String(r.unit_id),
|
|
59
|
+
} as any,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (!fresh.length) return;
|
|
63
|
+
c.finalHits = [...fresh, ...c.finalHits];
|
|
64
|
+
console.log("figure-seat: seated", fresh.length, "figure chunk(s) of doc", docNumber);
|
|
65
|
+
} catch {
|
|
66
|
+
// additive — the text ranking stands
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
@@ -34,6 +34,7 @@ import { overviewDemote } from "./overviewDemote.ts";
|
|
|
34
34
|
import { familyBoost } from "./familyBoost.ts";
|
|
35
35
|
import { rerankStage, lexicalRrf } from "./rerank.ts";
|
|
36
36
|
import { vlmFigureRerank } from "./vlmFigureRerank.ts";
|
|
37
|
+
import { figureSeat } from "./figureSeat.ts";
|
|
37
38
|
import { termNudge } from "./termNudge.ts";
|
|
38
39
|
import { conceptSteer } from "./conceptSteer.ts";
|
|
39
40
|
import { editionSteer } from "./editionSteer.ts";
|
|
@@ -76,6 +77,7 @@ export const STAGES: Stage[] = [
|
|
|
76
77
|
typedPin,
|
|
77
78
|
sectionDescent,
|
|
78
79
|
dedup,
|
|
80
|
+
figureSeat,
|
|
79
81
|
vlmFigureRerank,
|
|
80
82
|
windowFloor,
|
|
81
83
|
];
|