@konneal/engine 0.2.114 → 0.2.116
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-53QRX3KB.js → ask-QDV37DDB.js} +2 -2
- package/dist/{chunk-4RQ4X7SA.js → chunk-PJ3ET5AY.js} +21 -2
- package/dist/{chunk-4J3CRJH3.js → chunk-XWT3T3T3.js} +1 -1
- package/dist/{chunk-VSZBGAEE.js → chunk-YVNY4JWP.js} +1 -1
- package/dist/{search-5HDTEMZD.js → search-AXP7F365.js} +2 -2
- package/dist/worker_public/src/index.js +4 -4
- package/package.json +1 -1
- package/workers/worker_public/src/pipeline.ts +5 -1
- package/workers/worker_public/src/stages/seal.ts +37 -1
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleAsk
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YVNY4JWP.js";
|
|
4
4
|
import "./chunk-32UDKBA2.js";
|
|
5
|
-
import "./chunk-
|
|
5
|
+
import "./chunk-PJ3ET5AY.js";
|
|
6
6
|
import "./chunk-TH5XGPD5.js";
|
|
7
7
|
import "./chunk-DJ65EF5G.js";
|
|
8
8
|
import "./chunk-A3QHHUN5.js";
|
|
@@ -22694,15 +22694,34 @@ var federate = {
|
|
|
22694
22694
|
};
|
|
22695
22695
|
|
|
22696
22696
|
// workers/worker_public/src/stages/seal.ts
|
|
22697
|
+
async function familyChunks(env, familyNumber, query, keep) {
|
|
22698
|
+
const rows = await portStore(env).prepare(
|
|
22699
|
+
"SELECT id, doc_id, docidentifier, doctype, doc_number, edition, language, clause_anchor, clause_title, status, superseded_by, corpus, tier, text, unit_id, block, bm25(chunks_fts) AS rank FROM chunks_fts JOIN chunks c ON c.rowid = chunks_fts.rowid WHERE chunks_fts MATCH ?1 AND c.doc_number = ?2 ORDER BY rank LIMIT ?3"
|
|
22700
|
+
).bind(query.replace(/["'^]/g, " ").trim() || familyNumber, familyNumber, keep).all().catch(() => ({ results: [] }));
|
|
22701
|
+
return (rows.results ?? []).map((r) => ({
|
|
22702
|
+
id: String(r.id),
|
|
22703
|
+
score: 0,
|
|
22704
|
+
metadata: r,
|
|
22705
|
+
text: String(r.text ?? "")
|
|
22706
|
+
}));
|
|
22707
|
+
}
|
|
22697
22708
|
var seal = {
|
|
22698
22709
|
name: "seal",
|
|
22699
22710
|
when: (c) => !!c.opts.sealScope || !!c.opts.editionSteer || !!c.opts.editionExclude,
|
|
22700
|
-
run: (c) => {
|
|
22711
|
+
run: async (c) => {
|
|
22701
22712
|
const before = c.hits.length;
|
|
22702
22713
|
const scope = c.opts.sealScope;
|
|
22703
22714
|
if (scope) {
|
|
22704
22715
|
c.hits = c.hits.filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition));
|
|
22705
22716
|
console.log("context seal:", before, "\u2192", c.hits.length, "candidates within", `doc#${scope.doc_number}${scope.edition ? "@" + scope.edition : ""}`);
|
|
22717
|
+
if (c.hits.length === 0) {
|
|
22718
|
+
const familyNumber = scope.doc_number.includes("-") ? scope.doc_number.split("-")[0] : scope.doc_number;
|
|
22719
|
+
const pulled = (await familyChunks(c.env, familyNumber, c.rq || c.query, 12)).filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition)).slice(0, 8).map((h) => ({ ...h, score: 0.5 }));
|
|
22720
|
+
if (pulled.length) {
|
|
22721
|
+
c.hits = pulled;
|
|
22722
|
+
console.log("context seal: pool empty \u2014 pulled", pulled.length, "family chunks from the corpus for", `doc#${scope.doc_number}`);
|
|
22723
|
+
}
|
|
22724
|
+
}
|
|
22706
22725
|
return;
|
|
22707
22726
|
}
|
|
22708
22727
|
const exclude = c.opts.editionExclude;
|
|
@@ -23474,7 +23493,7 @@ async function retrieve(env, query, opts = {}) {
|
|
|
23474
23493
|
const filter = filters ? toVectorizeFilter(filters) : null;
|
|
23475
23494
|
const folded = retrievalQuery(query, opts.prev);
|
|
23476
23495
|
let rq = opts.queryOverride?.trim() || u?.standalone_query?.trim() || folded;
|
|
23477
|
-
if (u?.process_intent) rq += processExpansion();
|
|
23496
|
+
if (u?.process_intent && !opts.sealScope) rq += processExpansion();
|
|
23478
23497
|
const vectorP = rq === folded && opts.optimisticVec ? Promise.resolve(opts.optimisticVec) : rq === folded && opts.warmEmbed ? opts.warmEmbed.then((w) => w ?? embed(portModelRunner(env), MODELS.embed, rq)) : embed(portModelRunner(env), MODELS.embed, rq);
|
|
23479
23498
|
const lexicalP = lexicalPrefilter(env, opts.lexicalBoost ? `${rq} ${opts.lexicalBoost}` : rq).catch(() => []);
|
|
23480
23499
|
const [vector, lexicalHits0] = await Promise.all([vectorP, lexicalP]);
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-YVNY4JWP.js";
|
|
8
8
|
import {
|
|
9
9
|
TOOLS_REGISTRY,
|
|
10
10
|
bindModelNode,
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from "../../chunk-32UDKBA2.js";
|
|
13
13
|
import {
|
|
14
14
|
handleSearch
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-XWT3T3T3.js";
|
|
16
16
|
import {
|
|
17
17
|
buildMessages,
|
|
18
18
|
citations,
|
|
@@ -34,7 +34,7 @@ import {
|
|
|
34
34
|
sessionFrom,
|
|
35
35
|
telemetry,
|
|
36
36
|
understandQuery
|
|
37
|
-
} from "../../chunk-
|
|
37
|
+
} from "../../chunk-PJ3ET5AY.js";
|
|
38
38
|
import {
|
|
39
39
|
cfBlobs,
|
|
40
40
|
embed,
|
|
@@ -1000,7 +1000,7 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1000
1000
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1001
1001
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1002
1002
|
} else {
|
|
1003
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1003
|
+
const res = name === "ask" ? await (await import("../../ask-QDV37DDB.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-AXP7F365.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1004
1004
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1005
1005
|
}
|
|
1006
1006
|
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.116",
|
|
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",
|
|
@@ -109,7 +109,11 @@ export async function retrieve(
|
|
|
109
109
|
const filter = filters ? toVectorizeFilter(filters) : null;
|
|
110
110
|
const folded = retrievalQuery(query, opts.prev);
|
|
111
111
|
let rq = opts.queryOverride?.trim() || u?.standalone_query?.trim() || folded;
|
|
112
|
-
|
|
112
|
+
// the process expansion widens an UNSCOPED question toward the
|
|
113
|
+
// certification corpus; under a declared seal it poisons the query
|
|
114
|
+
// against the sealed family instead (the pool empties, the refusal
|
|
115
|
+
// follows) — the chip's context note already scopes the ANSWER
|
|
116
|
+
if (u?.process_intent && !opts.sealScope) rq += processExpansion();
|
|
113
117
|
// Dense embed + full-corpus BM25 prefilter in parallel (G-ETSI-1 /
|
|
114
118
|
// arXiv:2604.09868 §II-B5). Lexical must scan the whole corpus — the
|
|
115
119
|
// old keywordRank only re-ordered dense hits and could not recover
|
|
@@ -3,17 +3,53 @@
|
|
|
3
3
|
// outside the declared family competes for the window; everything
|
|
4
4
|
// inside it does.
|
|
5
5
|
import { matchesDocScope } from "../context.ts";
|
|
6
|
+
import { portStore } from "../env.ts";
|
|
7
|
+
import type { ChunkMeta, Hit } from "../../../shared/chunk";
|
|
6
8
|
import type { Stage } from "./types.ts";
|
|
7
9
|
|
|
10
|
+
/** The sealed family's chunks, from the D1 corpus directly (the l6a
|
|
11
|
+
* law): the declared context's guarantee is that the publication CAN
|
|
12
|
+
* answer — a generic question's global ranking need not contain the
|
|
13
|
+
* family at all, so an emptied pool pulls the family's own text. */
|
|
14
|
+
async function familyChunks(env: any, familyNumber: string, query: string, keep: number): Promise<Hit[]> {
|
|
15
|
+
const rows = await portStore(env).prepare(
|
|
16
|
+
"SELECT id, doc_id, docidentifier, doctype, doc_number, edition, language, clause_anchor, clause_title, status, superseded_by, corpus, tier, text, unit_id, block, bm25(chunks_fts) AS rank FROM chunks_fts JOIN chunks c ON c.rowid = chunks_fts.rowid WHERE chunks_fts MATCH ?1 AND c.doc_number = ?2 ORDER BY rank LIMIT ?3",
|
|
17
|
+
)
|
|
18
|
+
.bind(query.replace(/["'^]/g, " ").trim() || familyNumber, familyNumber, keep)
|
|
19
|
+
.all()
|
|
20
|
+
.catch(() => ({ results: [] }));
|
|
21
|
+
return (rows.results ?? []).map((r: any) => ({
|
|
22
|
+
id: String(r.id),
|
|
23
|
+
score: 0,
|
|
24
|
+
metadata: r as unknown as ChunkMeta,
|
|
25
|
+
text: String(r.text ?? ""),
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
|
|
8
29
|
export const seal: Stage = {
|
|
9
30
|
name: "seal",
|
|
10
31
|
when: (c) => !!c.opts.sealScope || !!c.opts.editionSteer || !!c.opts.editionExclude,
|
|
11
|
-
run: (c) => {
|
|
32
|
+
run: async (c) => {
|
|
12
33
|
const before = c.hits.length;
|
|
13
34
|
const scope = c.opts.sealScope!;
|
|
14
35
|
if (scope) {
|
|
15
36
|
c.hits = c.hits.filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition));
|
|
16
37
|
console.log("context seal:", before, "→", c.hits.length, "candidates within", `doc#${scope.doc_number}${scope.edition ? "@" + scope.edition : ""}`);
|
|
38
|
+
if (c.hits.length === 0) {
|
|
39
|
+
// the declared-context guarantee: the family's own text enters
|
|
40
|
+
// even when no global ranking carried it — the FTS ranking over
|
|
41
|
+
// the family grain (the part identity steers by docidentifier
|
|
42
|
+
// downstream, the same grain law matchesDocScope enforces)
|
|
43
|
+
const familyNumber = scope.doc_number.includes("-") ? scope.doc_number.split("-")[0] : scope.doc_number;
|
|
44
|
+
const pulled = (await familyChunks(c.env, familyNumber, c.rq || c.query, 12))
|
|
45
|
+
.filter((h) => matchesDocScope(h.metadata, scope.doc_number) && (!scope.edition || h.metadata.edition === scope.edition))
|
|
46
|
+
.slice(0, 8)
|
|
47
|
+
.map((h) => ({ ...h, score: 0.5 }));
|
|
48
|
+
if (pulled.length) {
|
|
49
|
+
c.hits = pulled;
|
|
50
|
+
console.log("context seal: pool empty — pulled", pulled.length, "family chunks from the corpus for", `doc#${scope.doc_number}`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
17
53
|
return;
|
|
18
54
|
}
|
|
19
55
|
const exclude = c.opts.editionExclude!;
|