@konneal/engine 0.2.26 → 0.2.28
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-YN63SADP.js → ask-KELYM6RJ.js} +2 -2
- package/dist/{chunk-WKG65DBA.js → chunk-4G5OGWXY.js} +1 -0
- package/dist/{chunk-GAPT3WEN.js → chunk-5LCPKJ6V.js} +1 -1
- package/dist/{chunk-ADQEM7IS.js → chunk-INCFGVH3.js} +12 -12
- package/dist/{search-MSFDEFQG.js → search-4UK3RBEQ.js} +2 -2
- package/dist/worker_public/src/index.js +21 -6
- package/package.json +1 -1
- package/workers/worker_public/src/ask.ts +16 -18
- package/workers/worker_public/src/faithfulness-context.ts +1 -1
- package/workers/worker_public/src/index.ts +21 -2
|
@@ -24405,6 +24405,7 @@ export {
|
|
|
24405
24405
|
embed,
|
|
24406
24406
|
generateOnce,
|
|
24407
24407
|
ftsMatchQuery,
|
|
24408
|
+
refCodec,
|
|
24408
24409
|
NO_CONTEXT,
|
|
24409
24410
|
parseContext,
|
|
24410
24411
|
namedDocumentIn,
|
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
parseContext,
|
|
19
19
|
portModelRunner,
|
|
20
20
|
rawSessionToken,
|
|
21
|
+
refCodec,
|
|
21
22
|
resolveDocScope,
|
|
22
23
|
resolveLiveAccount,
|
|
23
24
|
retrievalQuery,
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
syntheticUnderstanding,
|
|
28
29
|
telemetry,
|
|
29
30
|
understandQuery
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-4G5OGWXY.js";
|
|
31
32
|
import {
|
|
32
33
|
corsHeaders,
|
|
33
34
|
err,
|
|
@@ -2014,19 +2015,16 @@ ${summary}` }] : [],
|
|
|
2014
2015
|
if (aggregationVerdict) console.log("aggregation engine:", aggregationVerdict.operation, aggregationVerdict.table, "\u2192", aggregationVerdict.value);
|
|
2015
2016
|
let boundaryNote = null;
|
|
2016
2017
|
let boundaryBoost;
|
|
2017
|
-
let
|
|
2018
|
-
|
|
2019
|
-
const
|
|
2020
|
-
if (
|
|
2021
|
-
const
|
|
2022
|
-
|
|
2023
|
-
const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1").bind(family).first().catch(() => null);
|
|
2024
|
-
if (row?.edition) modelEditionBoost = String(row.edition);
|
|
2025
|
-
} else {
|
|
2026
|
-
modelEditionBoost = boundModel.standard;
|
|
2018
|
+
let editionBoost;
|
|
2019
|
+
try {
|
|
2020
|
+
const fam = understanding?.doc ? refCodec().familyOf(understanding.doc) : null;
|
|
2021
|
+
if (fam) {
|
|
2022
|
+
const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1").bind(fam).first().catch(() => null);
|
|
2023
|
+
if (row?.edition) editionBoost = String(row.edition);
|
|
2027
2024
|
}
|
|
2025
|
+
} catch {
|
|
2028
2026
|
}
|
|
2029
|
-
const lexicalBoost = [boundaryBoost,
|
|
2027
|
+
const lexicalBoost = [boundaryBoost, editionBoost].filter(Boolean).join(" ") || void 0;
|
|
2030
2028
|
if (P().sources?.licensed?.length) {
|
|
2031
2029
|
const match = matchLicensedTopic(q.query, P().sources.licensed);
|
|
2032
2030
|
if (match && !(standardKeys?.has(match.entry.key) ?? false)) {
|
|
@@ -2369,6 +2367,8 @@ export {
|
|
|
2369
2367
|
handleMemories,
|
|
2370
2368
|
checkQuoteAnchors,
|
|
2371
2369
|
standardForDocNumber,
|
|
2370
|
+
bindModelNode,
|
|
2371
|
+
modelGroundingBlock,
|
|
2372
2372
|
scoreJudge,
|
|
2373
2373
|
handleAsk
|
|
2374
2374
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleSearch
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-5LCPKJ6V.js";
|
|
4
4
|
import {
|
|
5
|
+
bindModelNode,
|
|
5
6
|
checkQuoteAnchors,
|
|
6
7
|
handleAsk,
|
|
7
8
|
handleMemories,
|
|
9
|
+
modelGroundingBlock,
|
|
8
10
|
scoreJudge,
|
|
9
11
|
standardForDocNumber
|
|
10
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-INCFGVH3.js";
|
|
11
13
|
import {
|
|
12
14
|
buildMessages,
|
|
13
15
|
citations,
|
|
@@ -25,11 +27,12 @@ import {
|
|
|
25
27
|
parseAppliedContext,
|
|
26
28
|
portModelRunner,
|
|
27
29
|
promptVars,
|
|
30
|
+
refCodec,
|
|
28
31
|
retrieve,
|
|
29
32
|
sessionFrom,
|
|
30
33
|
telemetry,
|
|
31
34
|
understandQuery
|
|
32
|
-
} from "../../chunk-
|
|
35
|
+
} from "../../chunk-4G5OGWXY.js";
|
|
33
36
|
import {
|
|
34
37
|
authenticate,
|
|
35
38
|
corsHeaders,
|
|
@@ -390,7 +393,7 @@ function parseVerdict(text) {
|
|
|
390
393
|
|
|
391
394
|
// workers/worker_public/src/faithfulness-context.ts
|
|
392
395
|
function buildJudgeContext(passages, machine = []) {
|
|
393
|
-
const context = passages.slice(0, 8).map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0,
|
|
396
|
+
const context = passages.slice(0, 8).map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0, 1400)}`).join("\n");
|
|
394
397
|
const machineContext = machine.length ? "\n" + machine.slice(0, 6).map((m) => `[M] ${m.replace(/\s+/g, " ").slice(0, 400)}`).join("\n") : "";
|
|
395
398
|
return context + machineContext;
|
|
396
399
|
}
|
|
@@ -989,7 +992,7 @@ async function handleMcp(env, ctx, req, tier, key) {
|
|
|
989
992
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
990
993
|
body: JSON.stringify({ ...args, stream: false })
|
|
991
994
|
});
|
|
992
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
995
|
+
const res = name === "ask" ? await (await import("../../ask-KELYM6RJ.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-4UK3RBEQ.js")).handleSearch(env, ctx, inner, tier, key);
|
|
993
996
|
return res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
994
997
|
});
|
|
995
998
|
if (out.ok && "accepted" in out) return new Response(null, { status: 202 });
|
|
@@ -1448,7 +1451,18 @@ async function verifyRoute(c) {
|
|
|
1448
1451
|
if (!answer || !query) return err(400, "invalid_input", "answer and query are required");
|
|
1449
1452
|
try {
|
|
1450
1453
|
const u = await understandQuery(env.AI, roleModel(env, "understand"), query, [], []);
|
|
1451
|
-
|
|
1454
|
+
let lexicalBoost;
|
|
1455
|
+
try {
|
|
1456
|
+
const fam = u?.doc_number ? refCodec().familyOf(u.doc_number) : null;
|
|
1457
|
+
if (fam) {
|
|
1458
|
+
const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1").bind(fam).first().catch(() => null);
|
|
1459
|
+
if (row?.edition) lexicalBoost = String(row.edition);
|
|
1460
|
+
}
|
|
1461
|
+
} catch {
|
|
1462
|
+
}
|
|
1463
|
+
const bound = await bindModelNode(env, { query, standardKeys: entitlementScope(standardKeysFrom(body)) });
|
|
1464
|
+
const modelGrounding = bound && !bound.gated ? modelGroundingBlock(bound) : null;
|
|
1465
|
+
const retrieved = await retrieve(env, query, { understanding: u, standardKeys: entitlementScope(standardKeysFrom(body)), lexicalBoost });
|
|
1452
1466
|
const passages = retrieved.hits.map((h) => h.text);
|
|
1453
1467
|
const anchors = checkQuoteAnchors(answer, passages);
|
|
1454
1468
|
const refs = [...answer.matchAll(/\[\[u:([^\]]+)\]\]/g)].map((m) => m[1]);
|
|
@@ -1459,6 +1473,7 @@ async function verifyRoute(c) {
|
|
|
1459
1473
|
{ name: "citations_present", deterministic: true, pass: new RegExp(`\\[[^\\]]*(${P().publisher.name})[^\\]]*\\]`).test(answer), detail: "normative claims should carry a passage citation" }
|
|
1460
1474
|
];
|
|
1461
1475
|
const machine = (Array.isArray(body?.blocks) ? body.blocks : []).filter((b) => b?.type === "verdict" && b?.payload).map((b) => [b.payload.check, b.payload.meaning, b.payload.definition, b.payload.violation_meaning].filter((x) => typeof x === "string" && x).join(" \u2014 ")).filter(Boolean);
|
|
1476
|
+
if (modelGrounding) machine.unshift(modelGrounding);
|
|
1462
1477
|
const faith = await scoreFaithfulness(env.AI, roleModel(env, "grader"), answer, retrieved.hits.map((h) => h.text), machine);
|
|
1463
1478
|
return json({
|
|
1464
1479
|
checks,
|
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.28",
|
|
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",
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { LIMITS, MODELS, num, sha256Hex, roleModel, answerEffort, requestEffort, effortBudget } from "./config";
|
|
7
7
|
import { portModelRunner } from "./env.ts";
|
|
8
|
+
import { refCodec } from "./codecs";
|
|
8
9
|
import { buildMessages, citations, retrieve, retrievalQuery, identityNote, splitHistory, listwiseRerank, refusalAnswer, Hit } from "./pipeline";
|
|
9
10
|
import { sessionFrom } from "./auth";
|
|
10
11
|
import { retrieveInternal } from "./internal_gateway";
|
|
@@ -858,27 +859,24 @@ async function handleAsk(
|
|
|
858
859
|
// publication's own clause — surface for a question the document's
|
|
859
860
|
// vocabulary alone would miss
|
|
860
861
|
let boundaryBoost: string | undefined;
|
|
861
|
-
// the
|
|
862
|
-
//
|
|
863
|
-
// otherwise outrank
|
|
864
|
-
//
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
// family's ACTIVE edition
|
|
872
|
-
const num = boundModel.standard.slice(prefix.length);
|
|
873
|
-
const family = `${prefix.slice(prefix.lastIndexOf("-") + 1).toUpperCase()}-${num}`;
|
|
862
|
+
// the EDITION boost: the grounding pool tilts to the publication's
|
|
863
|
+
// ACTIVE edition (the graph's own registry) — the dirty corpus's
|
|
864
|
+
// superseded editions otherwise outrank the current ones on shared
|
|
865
|
+
// vocabulary, and the answer's current-edition values then read as
|
|
866
|
+
// ungrounded against superseded passages. The family key is the
|
|
867
|
+
// profile codec's (familyOf) — no publisher grammar here.
|
|
868
|
+
let editionBoost: string | undefined;
|
|
869
|
+
try {
|
|
870
|
+
const fam = understanding?.doc ? refCodec().familyOf(understanding.doc) : null;
|
|
871
|
+
if (fam) {
|
|
874
872
|
const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1")
|
|
875
|
-
.bind(
|
|
876
|
-
if (row?.edition)
|
|
877
|
-
} else {
|
|
878
|
-
modelEditionBoost = boundModel.standard; // the doc number is embedded in the id
|
|
873
|
+
.bind(fam).first<any>().catch(() => null);
|
|
874
|
+
if (row?.edition) editionBoost = String(row.edition);
|
|
879
875
|
}
|
|
876
|
+
} catch {
|
|
877
|
+
// a registry hiccup degrades to unsteered retrieval
|
|
880
878
|
}
|
|
881
|
-
const lexicalBoost = [boundaryBoost,
|
|
879
|
+
const lexicalBoost = [boundaryBoost, editionBoost].filter(Boolean).join(" ") || undefined;
|
|
882
880
|
if (P().sources?.licensed?.length) {
|
|
883
881
|
const match = matchLicensedTopic(q.query, P().sources.licensed);
|
|
884
882
|
if (match && !(standardKeys?.has(match.entry.key) ?? false)) {
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
export function buildJudgeContext(passages: string[], machine: string[] = []): string {
|
|
8
8
|
const context = passages
|
|
9
9
|
.slice(0, 8)
|
|
10
|
-
.map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0,
|
|
10
|
+
.map((p, i) => `[${i + 1}] ${p.replace(/\s+/g, " ").slice(0, 1400)}`)
|
|
11
11
|
.join("\n");
|
|
12
12
|
const machineContext = machine.length
|
|
13
13
|
? "\n" + machine.slice(0, 6).map((m) => `[M] ${m.replace(/\s+/g, " ").slice(0, 400)}`).join("\n")
|
|
@@ -13,7 +13,8 @@ import { ftsMatchQuery } from "./lexical";
|
|
|
13
13
|
import { scoreFaithfulness } from "./faithfulness";
|
|
14
14
|
import { checkQuoteAnchors } from "./anchors";
|
|
15
15
|
import { namedDocumentIn } from "./context";
|
|
16
|
-
import { standardForDocNumber } from "./modelplane";
|
|
16
|
+
import { standardForDocNumber, bindModelNode, modelGroundingBlock } from "./modelplane";
|
|
17
|
+
import { refCodec } from "./codecs";
|
|
17
18
|
import { entitlementScope, standardKeysFrom } from "./requestScope";
|
|
18
19
|
import type { Env } from "./env";
|
|
19
20
|
export type { Env };
|
|
@@ -228,7 +229,24 @@ async function verifyRoute(c: RouteContext): Promise<Response> {
|
|
|
228
229
|
if (!answer || !query) return err(400, "invalid_input", "answer and query are required");
|
|
229
230
|
try {
|
|
230
231
|
const u = await understandQuery(env.AI, roleModel(env, "understand"), query, [], []);
|
|
231
|
-
|
|
232
|
+
// the grounding must MIRROR the ask path's: the edition boost (the
|
|
233
|
+
// publication's active edition, the codec's family) and the model
|
|
234
|
+
// grounding — a verify that grounds against different passages than
|
|
235
|
+
// the answer used judges a different answer
|
|
236
|
+
let lexicalBoost: string | undefined;
|
|
237
|
+
try {
|
|
238
|
+
const fam = u?.doc_number ? refCodec().familyOf(u.doc_number) : null;
|
|
239
|
+
if (fam) {
|
|
240
|
+
const row = await env.DB.prepare("SELECT edition FROM documents WHERE family = ?1 AND active = 1 ORDER BY edition DESC LIMIT 1")
|
|
241
|
+
.bind(fam).first().catch(() => null);
|
|
242
|
+
if (row?.edition) lexicalBoost = String(row.edition);
|
|
243
|
+
}
|
|
244
|
+
} catch {
|
|
245
|
+
// degrade to unsteered retrieval
|
|
246
|
+
}
|
|
247
|
+
const bound = await bindModelNode(env, { query, standardKeys: entitlementScope(standardKeysFrom(body)) });
|
|
248
|
+
const modelGrounding = bound && !bound.gated ? modelGroundingBlock(bound) : null;
|
|
249
|
+
const retrieved = await retrieve(env, query, { understanding: u, standardKeys: entitlementScope(standardKeysFrom(body)), lexicalBoost });
|
|
232
250
|
const passages = retrieved.hits.map((h: Hit) => h.text);
|
|
233
251
|
const anchors = checkQuoteAnchors(answer, passages);
|
|
234
252
|
const refs = [...answer.matchAll(/\[\[u:([^\]]+)\]\]/g)].map((m) => m[1]);
|
|
@@ -246,6 +264,7 @@ async function verifyRoute(c: RouteContext): Promise<Response> {
|
|
|
246
264
|
.map((b: any) => [b.payload.check, b.payload.meaning, b.payload.definition, b.payload.violation_meaning]
|
|
247
265
|
.filter((x: unknown) => typeof x === "string" && x).join(" — "))
|
|
248
266
|
.filter(Boolean);
|
|
267
|
+
if (modelGrounding) machine.unshift(modelGrounding);
|
|
249
268
|
const faith = await scoreFaithfulness(env.AI, roleModel(env, "grader"), answer, retrieved.hits.map((h: Hit) => h.text), machine);
|
|
250
269
|
return json({
|
|
251
270
|
checks,
|