@konneal/engine 0.2.188 → 0.2.190

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.
Files changed (43) hide show
  1. package/dist/ai.d.ts +7 -0
  2. package/dist/ask-6SWT3KSC.js +16 -0
  3. package/dist/{chunk-4AP763GX.js → chunk-22WB6IVC.js} +7 -9
  4. package/dist/{chunk-G435JWGV.js → chunk-5PKKAHY4.js} +5 -5
  5. package/dist/{chunk-4BQA7PJ3.js → chunk-7YMIUTPY.js} +1 -1
  6. package/dist/{chunk-L32WSANI.js → chunk-AVNHVFEB.js} +26 -3
  7. package/dist/{chunk-VT5ZHCOC.js → chunk-ECNBEZGK.js} +5 -5
  8. package/dist/{chunk-NHYYMRZC.js → chunk-GJQT4IMD.js} +1 -1
  9. package/dist/{chunk-YGQCVPX6.js → chunk-H6ZULBW2.js} +4 -1
  10. package/dist/{chunk-SLYQ6L52.js → chunk-Q7QL3457.js} +52 -38
  11. package/dist/{chunk-A2HQNENL.js → chunk-WRSUXIS7.js} +139 -28
  12. package/dist/config.d.ts +1 -2
  13. package/dist/context.d.ts +14 -0
  14. package/dist/docOverview.d.ts +35 -0
  15. package/dist/{env-BZWHCSCL.js → env-4LR6Y5CC.js} +1 -1
  16. package/dist/operations.d.ts +34 -0
  17. package/dist/prompts/understanding.md +2 -1
  18. package/dist/reflect.d.ts +1 -1
  19. package/dist/search-DE5ADCVM.js +14 -0
  20. package/dist/{tools-CYSL26HX.js → tools-7GKMDWVB.js} +5 -5
  21. package/dist/understandContract.d.ts +3 -0
  22. package/dist/worker_mcp/src/index.js +2 -2
  23. package/dist/worker_public/src/config.js +1 -1
  24. package/dist/worker_public/src/index.js +11 -11
  25. package/dist/worker_public/src/requestScope.js +2 -2
  26. package/package.json +1 -1
  27. package/workers/worker_public/prompts/understanding.md +2 -1
  28. package/workers/worker_public/src/ai.ts +30 -6
  29. package/workers/worker_public/src/ask.ts +118 -21
  30. package/workers/worker_public/src/config.ts +7 -9
  31. package/workers/worker_public/src/context.ts +14 -0
  32. package/workers/worker_public/src/docOverview.ts +77 -0
  33. package/workers/worker_public/src/faithfulness.ts +11 -1
  34. package/workers/worker_public/src/lexical.ts +21 -19
  35. package/workers/worker_public/src/operations.ts +40 -0
  36. package/workers/worker_public/src/ports/cloudflare/adapters.ts +4 -2
  37. package/workers/worker_public/src/reflect.ts +8 -7
  38. package/workers/worker_public/src/stages/dense.ts +29 -42
  39. package/workers/worker_public/src/stages/glossary.ts +1 -1
  40. package/workers/worker_public/src/stages/rerank.ts +6 -2
  41. package/workers/worker_public/src/understandContract.ts +4 -0
  42. package/dist/ask-TJK7DQ45.js +0 -16
  43. package/dist/search-FJAOGMEO.js +0 -14
package/dist/ai.d.ts CHANGED
@@ -1,6 +1,13 @@
1
1
  import type { ModelRunner } from "./ports/model.ts";
2
2
  type AnyAi = ModelRunner;
3
3
  export declare function embed(ai: ModelRunner, _model: string, text: string): Promise<number[]>;
4
+ /** The platform's per-minute inference allowance (3021) and its capacity
5
+ * signal (3040) reset with the minute: an immediate retry hits the same
6
+ * wall, so the caller waits before trying again. Measured 2026-12-03 —
7
+ * with every generation role on one model, two parallel question streams
8
+ * exhausted it and half the judging calls failed. */
9
+ export declare function isCapacityError(e: unknown): boolean;
10
+ export declare const CAPACITY_PAUSE_MS = 15000;
4
11
  export declare function rerank(ai: AnyAi, model: string, query: string, texts: string[]): Promise<number[] | null>;
5
12
  export declare function generateOnce(env: any, model: string, messages: any[], effort?: string): Promise<string | null>;
6
13
  export {};
@@ -0,0 +1,16 @@
1
+ import {
2
+ handleAsk
3
+ } from "./chunk-WRSUXIS7.js";
4
+ import "./chunk-IRCDOFP4.js";
5
+ import "./chunk-ECNBEZGK.js";
6
+ import "./chunk-Q7QL3457.js";
7
+ import "./chunk-AVNHVFEB.js";
8
+ import "./chunk-GJQT4IMD.js";
9
+ import "./chunk-ETLSWSZ7.js";
10
+ import "./chunk-7YMIUTPY.js";
11
+ import "./chunk-22WB6IVC.js";
12
+ import "./chunk-3FYJM7LH.js";
13
+ import "./chunk-H6ZULBW2.js";
14
+ export {
15
+ handleAsk
16
+ };
@@ -33,10 +33,13 @@ var MODELS = {
33
33
  // operations deployment points ACTS_MODEL at the stronger reasoning
34
34
  // tier; the floor is the understand lane
35
35
  acts: FLASH,
36
- // generation fallback when the answer model is unavailable — the same
37
- // model as the primary while it is the only live cheap option: the
38
- // retry inside generateOnce is the only diversity this lane has
39
- fallback: FLASH,
36
+ // generation fallback when the answer model is unavailable. A fallback
37
+ // has to be ANOTHER model — as the primary's own twin (0.2.188) it added
38
+ // nothing to the retry inside generateOnce. glm-5.3 is a different
39
+ // family and fast; its flagship price only applies on the rare path
40
+ // where the primary failed. Text-only: the call sites flatten image
41
+ // parts before handing messages to it.
42
+ fallback: "@cf/zai-org/glm-5.3",
40
43
  grader: FLASH,
41
44
  // CRAG grader + judges
42
45
  // contextual enrichment is the QUALITY-FIRST lane (one-time spend over
@@ -103,11 +106,6 @@ var THRESHOLDS = {
103
106
  // the extractive compression arm (TODO.sota/02 row 5): when ablated
104
107
  // on, each passage body is compressed to this share of its budget
105
108
  compressShare: 0.6,
106
- // the dense scope's starvation fallback (the R 134-2 figure question):
107
- // when the in-code doc scope cuts the vector-level top-K to zero, the
108
- // re-query runs at this depth and scopes in code (the native filter is
109
- // dead — measured 2026-10-05)
110
- denseStarveK: 100,
111
109
  // the decision pass (TODO.decisions): the gate fires at decisionsGateMin
112
110
  // noul; the bands assemble met / not clearly stated / not met
113
111
  decisionsGateMin: 0.5,
@@ -6,27 +6,27 @@ import {
6
6
  sessionFrom,
7
7
  telemetry,
8
8
  understandQuery
9
- } from "./chunk-SLYQ6L52.js";
9
+ } from "./chunk-Q7QL3457.js";
10
10
  import {
11
11
  corsHeaders,
12
12
  err,
13
13
  json,
14
14
  readJson,
15
15
  validateQuery
16
- } from "./chunk-NHYYMRZC.js";
16
+ } from "./chunk-GJQT4IMD.js";
17
17
  import {
18
18
  entitlementScope,
19
19
  standardKeysFrom
20
- } from "./chunk-4BQA7PJ3.js";
20
+ } from "./chunk-7YMIUTPY.js";
21
21
  import {
22
22
  LIMITS,
23
23
  MODELS,
24
24
  num,
25
25
  sha256Hex
26
- } from "./chunk-4AP763GX.js";
26
+ } from "./chunk-22WB6IVC.js";
27
27
  import {
28
28
  portModelRunner
29
- } from "./chunk-YGQCVPX6.js";
29
+ } from "./chunk-H6ZULBW2.js";
30
30
 
31
31
  // workers/worker_public/src/search.ts
32
32
  async function handleSearch(env, ctx, req, tier, key) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  DATASETS,
3
3
  datasetAllowed
4
- } from "./chunk-4AP763GX.js";
4
+ } from "./chunk-22WB6IVC.js";
5
5
  import {
6
6
  P
7
7
  } from "./chunk-3FYJM7LH.js";
@@ -2,7 +2,7 @@ import {
2
2
  answerEffort,
3
3
  effortBudget,
4
4
  generationSampling
5
- } from "./chunk-4AP763GX.js";
5
+ } from "./chunk-22WB6IVC.js";
6
6
 
7
7
  // workers/worker_public/src/ai.ts
8
8
  var delay = (ms) => new Promise((r) => setTimeout(r, ms));
@@ -20,10 +20,30 @@ async function embed(ai, _model, text) {
20
20
  }
21
21
  throw new Error(`embed failed after retries: ${String(lastError)}`);
22
22
  }
23
+ function isCapacityError(e) {
24
+ return /3021|rate limit|3040|capacity/i.test(String(e));
25
+ }
26
+ var CAPACITY_PAUSE_MS = 15e3;
23
27
  async function rerank(ai, model, query, texts) {
28
+ const idx = [];
29
+ const nonEmpty = [];
30
+ for (let i = 0; i < texts.length; i++) {
31
+ if (typeof texts[i] === "string" && texts[i].trim().length > 0) {
32
+ idx.push(i);
33
+ nonEmpty.push(texts[i]);
34
+ }
35
+ }
36
+ if (!nonEmpty.length) return null;
24
37
  for (let attempt = 0; attempt < 2; attempt++) {
25
- const scores = await ai.rerank(model, query, texts);
26
- if (scores && scores.some((s) => Number.isFinite(s))) return scores;
38
+ const scores = await ai.rerank(model, query, nonEmpty);
39
+ if (scores && scores.some((s) => Number.isFinite(s))) {
40
+ if (idx.length === texts.length) return scores;
41
+ const out = new Array(texts.length).fill(NaN);
42
+ idx.forEach((orig, k) => {
43
+ out[orig] = scores[k];
44
+ });
45
+ return out;
46
+ }
27
47
  }
28
48
  console.error("rerank failed, using vector order");
29
49
  return null;
@@ -45,6 +65,7 @@ async function generateOnce(env, model, messages, effort) {
45
65
  if (attempt === 0) console.error("generate returned empty:", model);
46
66
  } catch (e) {
47
67
  console.error("generate failed:", model, String(e).slice(0, 120));
68
+ if (attempt === 0 && isCapacityError(e)) await delay(CAPACITY_PAUSE_MS);
48
69
  }
49
70
  }
50
71
  return null;
@@ -52,6 +73,8 @@ async function generateOnce(env, model, messages, effort) {
52
73
 
53
74
  export {
54
75
  embed,
76
+ isCapacityError,
77
+ CAPACITY_PAUSE_MS,
55
78
  rerank,
56
79
  generateOnce
57
80
  };
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  embed
3
- } from "./chunk-L32WSANI.js";
3
+ } from "./chunk-AVNHVFEB.js";
4
4
  import {
5
5
  standardKeysFrom
6
- } from "./chunk-4BQA7PJ3.js";
6
+ } from "./chunk-7YMIUTPY.js";
7
7
  import {
8
8
  THRESHOLDS
9
- } from "./chunk-4AP763GX.js";
9
+ } from "./chunk-22WB6IVC.js";
10
10
  import {
11
11
  P
12
12
  } from "./chunk-3FYJM7LH.js";
@@ -15,7 +15,7 @@ import {
15
15
  portIndex,
16
16
  portModelRunner,
17
17
  portStore
18
- } from "./chunk-YGQCVPX6.js";
18
+ } from "./chunk-H6ZULBW2.js";
19
19
 
20
20
  // workers/worker_public/src/refs.ts
21
21
  var REF = /\[\[(u:(?:u:)?[A-Za-z0-9_-]+)\]\]/g;
@@ -1509,7 +1509,7 @@ async function runFind(env, args) {
1509
1509
  };
1510
1510
  }
1511
1511
  try {
1512
- const { portStore: portStore2 } = await import("./env-BZWHCSCL.js");
1512
+ const { portStore: portStore2 } = await import("./env-4LR6Y5CC.js");
1513
1513
  const res = await portStore2(env).prepare(compiled.sql).bind(...compiled.params).all();
1514
1514
  const rows = res?.results ?? [];
1515
1515
  const body = rows.length ? rows.map((r) => JSON.stringify(r)).join("\n") : "No rows matched. Either the predicates are too narrow or the data is absent \u2014 state which, and consider widening.";
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  LIMITS,
3
3
  sha256Hex
4
- } from "./chunk-4AP763GX.js";
4
+ } from "./chunk-22WB6IVC.js";
5
5
  import {
6
6
  P
7
7
  } from "./chunk-3FYJM7LH.js";
@@ -52,6 +52,7 @@ function cfModelRunner(ai) {
52
52
  throw new Error(`embedding failed for all request shapes (${texts.length} text(s))`);
53
53
  },
54
54
  async rerank(model, query, texts) {
55
+ let firstErr = null;
55
56
  for (const body of RERANK_SHAPES(query, texts)) {
56
57
  try {
57
58
  const res = await A.run(model, body);
@@ -68,9 +69,11 @@ function cfModelRunner(ai) {
68
69
  if (Number.isInteger(id) && id >= 0 && id < texts.length && Number.isFinite(s)) scores[id] = s;
69
70
  });
70
71
  if (scores.some((s) => Number.isFinite(s))) return scores;
71
- } catch {
72
+ } catch (e) {
73
+ if (firstErr === null) firstErr = e;
72
74
  }
73
75
  }
76
+ if (firstErr !== null) console.error("rerank adapter failed:", String(firstErr).slice(0, 180));
74
77
  return null;
75
78
  },
76
79
  async run(req) {
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  embed,
3
3
  rerank
4
- } from "./chunk-L32WSANI.js";
4
+ } from "./chunk-AVNHVFEB.js";
5
5
  import {
6
6
  bubbleConfirmPage,
7
7
  isAllowedBubbleOrigin
8
- } from "./chunk-NHYYMRZC.js";
8
+ } from "./chunk-GJQT4IMD.js";
9
9
  import {
10
10
  DATASETS,
11
11
  LIMITS,
@@ -16,7 +16,7 @@ import {
16
16
  processExpansion,
17
17
  sha256Hex,
18
18
  today
19
- } from "./chunk-4AP763GX.js";
19
+ } from "./chunk-22WB6IVC.js";
20
20
  import {
21
21
  P
22
22
  } from "./chunk-3FYJM7LH.js";
@@ -26,7 +26,7 @@ import {
26
26
  portIndex,
27
27
  portModelRunner,
28
28
  portStore
29
- } from "./chunk-YGQCVPX6.js";
29
+ } from "./chunk-H6ZULBW2.js";
30
30
 
31
31
  // node_modules/@pubid/pubid/dist/grammar/engine.js
32
32
  var ParseFailed = class extends Error {
@@ -21866,6 +21866,10 @@ function matchesDocScope(meta, scopeDocNumber) {
21866
21866
  const last = stem.split(/\s+/).pop()?.toLowerCase();
21867
21867
  return last === scopeDocNumber.toLowerCase();
21868
21868
  }
21869
+ function docScopeFilter(scopeDocNumber) {
21870
+ const base = scopeDocNumber.split("-")[0];
21871
+ return { doc_number: { $in: base === scopeDocNumber ? [scopeDocNumber] : [scopeDocNumber, base] } };
21872
+ }
21869
21873
  async function resolveDocScope(env, ctx) {
21870
21874
  if (!ctx.doc) return null;
21871
21875
  const parsed = parseDocRef(ctx.doc, ctx.edition);
@@ -21930,6 +21934,7 @@ function syntheticUnderstanding(scope) {
21930
21934
  edition: scope.edition ?? null,
21931
21935
  language: null,
21932
21936
  process_intent: false,
21937
+ doc_overview: false,
21933
21938
  term: null,
21934
21939
  defined_terms: [],
21935
21940
  standalone_query: "",
@@ -22052,26 +22057,25 @@ function rowMeta(r) {
22052
22057
  block: String(r.block ?? "") || void 0
22053
22058
  };
22054
22059
  }
22060
+ function lexicalScore(rank) {
22061
+ const bm25 = typeof rank === "number" && Number.isFinite(rank) ? rank : 0;
22062
+ const strength = Math.abs(bm25);
22063
+ return 0.5 * strength / (1 + strength);
22064
+ }
22055
22065
  function rowsToHits(rows) {
22056
- return rows.map((r) => {
22057
- const bm25 = typeof r.rank === "number" ? r.rank : 0;
22058
- return {
22059
- id: String(r.id),
22060
- score: 1 / (1 + Math.max(0, bm25)),
22061
- metadata: rowMeta(r),
22062
- text: String(r.text ?? "")
22063
- };
22064
- });
22066
+ return rows.map((r) => ({
22067
+ id: String(r.id),
22068
+ score: lexicalScore(r.rank),
22069
+ metadata: rowMeta(r),
22070
+ text: String(r.text ?? "")
22071
+ }));
22065
22072
  }
22066
22073
  function rowsToMatches(rows) {
22067
- return rows.map((r) => {
22068
- const bm25 = typeof r.rank === "number" ? Math.max(0, r.rank) : 0;
22069
- return {
22070
- id: String(r.id),
22071
- score: 1 / (1 + bm25),
22072
- metadata: { ...rowMeta(r), chunk_text: String(r.text ?? "") }
22073
- };
22074
- });
22074
+ return rows.map((r) => ({
22075
+ id: String(r.id),
22076
+ score: lexicalScore(r.rank),
22077
+ metadata: { ...rowMeta(r), chunk_text: String(r.text ?? "") }
22078
+ }));
22075
22079
  }
22076
22080
  async function lexicalWithin(env, query, docNumbers, k = 12) {
22077
22081
  const match2 = ftsMatchQuery(query);
@@ -22160,25 +22164,28 @@ var dense = {
22160
22164
  }
22161
22165
  if (filters?.doc_number) {
22162
22166
  const allMatches = (await env.VECTORIZE.query(vector, q)).matches ?? [];
22163
- let matches = allMatches;
22164
- const before = matches.length;
22165
- matches = matches.filter((m) => matchesDocScope(m.metadata ?? {}, filters.doc_number));
22166
- if (filters.edition) matches = matches.filter((m) => !m.metadata?.edition || String(m.metadata.edition) === filters.edition);
22167
- console.log("dense scope (in code):", before, "\u2192", matches.length, "in doc", filters.doc_number, filters.edition ? `@${filters.edition}` : "");
22168
- if (!matches.length) {
22167
+ const before = allMatches.length;
22168
+ let docMatches = allMatches.filter((m) => matchesDocScope(m.metadata ?? {}, filters.doc_number));
22169
+ if (docMatches.length < LIMITS.rerankKeep) {
22169
22170
  try {
22170
- const wide = await env.VECTORIZE.query(vector, { ...q, topK: THRESHOLDS.denseStarveK });
22171
- matches = (wide.matches ?? []).filter((m) => matchesDocScope(m.metadata ?? {}, filters.doc_number));
22172
- console.log("dense scope starvation \u2192 deep re-query:", matches.length, "doc members in the top", THRESHOLDS.denseStarveK);
22171
+ const own = await env.VECTORIZE.query(vector, { ...q, filter: docScopeFilter(filters.doc_number) });
22172
+ const ownMatches = (own.matches ?? []).filter((m) => matchesDocScope(m.metadata ?? {}, filters.doc_number));
22173
+ const seen = new Set(docMatches.map((m) => m.id));
22174
+ const added = ownMatches.filter((m) => !seen.has(m.id));
22175
+ if (added.length) {
22176
+ docMatches = [...docMatches, ...added];
22177
+ console.log("dense scope sparse \u2192 native doc filter:", docMatches.length, "doc members");
22178
+ }
22173
22179
  } catch (e) {
22174
22180
  console.log("dense scope starvation re-query failed:", String(e).slice(0, 120));
22175
22181
  }
22176
22182
  }
22183
+ let matches = filters.edition ? docMatches.filter((m) => !m.metadata?.edition || String(m.metadata.edition) === filters.edition) : docMatches;
22184
+ console.log("dense scope (in code):", before, "\u2192", matches.length, "in doc", filters.doc_number, filters.edition ? `@${filters.edition}` : "");
22177
22185
  if (filters && filters.edition && matches.length < 3) {
22178
- const docOnly = allMatches.filter((m) => matchesDocScope(m.metadata ?? {}, filters.doc_number));
22179
- if (docOnly.length > matches.length) {
22180
- console.log("edition pin dropped:", filters.doc_number, "@", filters.edition, "\u2192", docOnly.length, "doc-scoped hits (edition not in corpus)");
22181
- matches = docOnly;
22186
+ if (docMatches.length > matches.length) {
22187
+ console.log("edition pin dropped:", filters.doc_number, "@", filters.edition, "\u2192", docMatches.length, "doc-scoped hits (edition not in corpus)");
22188
+ matches = docMatches;
22182
22189
  filters.edition = void 0;
22183
22190
  }
22184
22191
  }
@@ -22337,7 +22344,7 @@ var glossary = {
22337
22344
  definition: String(m.metadata?.chunk_text ?? "").split(" \u2014 ").slice(1).join(" \u2014 ").slice(0, 300),
22338
22345
  docidentifier: String(m.metadata?.docidentifier ?? ""),
22339
22346
  doc_number: String(m.metadata?.doc_number ?? ""),
22340
- score: rs ? rs[i] : m.score
22347
+ score: rs && Number.isFinite(rs[i]) ? rs[i] : m.score
22341
22348
  })).filter((x) => x.term && x.definition);
22342
22349
  })();
22343
22350
  },
@@ -22927,11 +22934,15 @@ var rerankStage = {
22927
22934
  const scores = await rerank(portModelRunner(c.env), MODELS.rerank, c.query, c.hits.map((h) => h.text));
22928
22935
  console.log("stage: rerank", Date.now() - tRerank, "ms over", c.hits.length, "candidates");
22929
22936
  if (scores) {
22930
- c.hits.forEach((h, i) => h.rerank_score = scores[i]);
22937
+ const finite = scores.filter((s8) => Number.isFinite(s8));
22938
+ const minFinite = finite.length ? Math.min(...finite) : 0;
22939
+ const span = finite.length ? Math.max(...finite) - minFinite : 0;
22940
+ const floor = minFinite - Math.max(0.01, span);
22941
+ c.hits.forEach((h, i) => h.rerank_score = Number.isFinite(scores[i]) ? scores[i] : floor);
22931
22942
  c.hits.sort((a, b) => (b.rerank_score ?? -Infinity) - (a.rerank_score ?? -Infinity));
22932
22943
  if (c.filter?.doc_number) {
22933
22944
  const families = c.hits.filter((h) => h.metadata.clause_anchor === "family" && String(h.metadata.doc_number ?? "").split("-")[0] === String(c.filter.doc_number).split("-")[0]);
22934
- const own = families.length ? families : c.hits.filter((h) => String(h.metadata.doc_number ?? "") === String(c.filter.doc_number).split("-")[0] && /^(overview|)$/i.test(String(h.metadata.clause_anchor ?? "")));
22945
+ const own = families.length ? families : c.hits.filter((h) => h.text.trim().length > 0 && h.metadata.doctype !== "certificate" && String(h.metadata.doc_number ?? "") === String(c.filter.doc_number).split("-")[0] && /^(overview|)$/i.test(String(h.metadata.clause_anchor ?? "")));
22935
22946
  if (own.length) {
22936
22947
  const ownIds = new Set(own.map((h) => h.id));
22937
22948
  c.hits = [...own, ...c.hits.filter((h) => !ownIds.has(h.id))];
@@ -24790,6 +24801,7 @@ function extractJson(text) {
24790
24801
  edition: typeof raw.edition === "string" && /^\d{4}$/.test(raw.edition) ? raw.edition : null,
24791
24802
  language: typeof raw.language === "string" && /^[a-z]{2}$/.test(raw.language) ? raw.language : null,
24792
24803
  process_intent: raw.process_intent === true,
24804
+ doc_overview: raw.doc_overview === true,
24793
24805
  term: typeof raw.term === "string" && raw.term.trim() ? raw.term.trim().slice(0, 60) : null,
24794
24806
  defined_terms: Array.isArray(raw.defined_terms) ? raw.defined_terms.filter((t) => typeof t === "string" && t.trim()).map((t) => t.trim().slice(0, 60)).slice(0, 4) : [],
24795
24807
  standalone_query: typeof raw.standalone_query === "string" && raw.standalone_query.trim() ? raw.standalone_query.trim().slice(0, 400) : "",
@@ -24808,12 +24820,13 @@ function extractJson(text) {
24808
24820
  // workers/worker_public/prompts/understanding.md
24809
24821
  var understanding_default = `You normalize a user question for a retrieval system over {{CORPUS_KIND_PLURAL}} (English corpus).
24810
24822
  Reply with ONLY a JSON object, no prose, no markdown fence:
24811
- {"intent": "knowledge", "docidentifier": "{{DOCID_EXAMPLE}}" | null, "docnumber": "76" | null, "edition": "2021" | null, "language": "en" | null, "process_intent": true | false, "term": "accuracy class" | null, "defined_terms": [], "standalone_query": "...", "complexity": "simple", "query_variants": [], "sub_queries": [], "hypothetical_answer": "...", "follow_ups": []}
24823
+ {"intent": "knowledge", "docidentifier": "{{DOCID_EXAMPLE}}" | null, "docnumber": "76" | null, "edition": "2021" | null, "language": "en" | null, "process_intent": true | false, "doc_overview": true | false, "term": "accuracy class" | null, "defined_terms": [], "standalone_query": "...", "complexity": "simple", "query_variants": [], "sub_queries": [], "hypothetical_answer": "...", "follow_ups": []}
24812
24824
  Rules:
24813
24825
  - intent: "conversational" ONLY when the latest message is about the assistant or this service itself (who you are, which model you are, what you can do, how you work) or is a pure social nicety (greeting, thanks, farewell, small talk) \u2014 e.g. "hi!", "who are you?", "what can you do?", "merci !", "was kannst du?". ANY question about a subject \u2014 legal metrology, other technical fields, cooking, sports, current events, ANYTHING \u2014 is "knowledge", even when the corpus cannot answer it; do NOT use "conversational" to mean off-topic.
24814
24826
  - docidentifier: the publication the user names, in any spelling ({{SPELLING_EXAMPLES}}, "the nonautomatic weighing instruments recommendation" \u2192 resolve to the {{PUBLISHER_NAME}} identifier you can infer; include the part ("-1", "-2") only when clearly meant). docnumber is the base number without part.
24815
24827
  - edition: only when the user pins a year.
24816
24828
  - language: only when the user asks for a specific answer language; otherwise null (the corpus is English; answering in the user's language is handled elsewhere).
24829
+ - doc_overview: true ONLY when the question asks what the NAMED publication is or covers as a whole \u2014 an overview, purpose, scope or summary of the document itself ("what is R 60", "describe OIML D 11", "give me an overview of R 76-1") \u2014 and docidentifier is set. false for anything inside it (a requirement, value, term, test, table or citation question: "what is the MPE in R 76-1" \u2192 false), and false when no publication is named.
24817
24830
  - citation questions ("what does X cite/reference/list?", "which standards does X reference?"): ALWAYS include a query variant that names the document's bibliography or normative-references section explicitly, WITHOUT edition scoping (e.g. for "What ISO standards does R 60 cite?" generate BOTH "R 60 bibliography normative references" AND "R 60 2017 bibliography ISO IEC") \u2014 bibliographies embed differently than the query's phrasing, and prior editions may carry references the current edition dropped; set edition to null for these queries so retrieval covers the whole family.
24818
24831
  - process_intent: true when the question is about the GOVERNING SYSTEM around publications rather than a publication's own technical content \u2014 HOW to get certified/apply/comply, OR which framework/vocabulary/{{PROCESS_VOCAB}}. Naming a Recommendation (e.g. "R 60") inside such a question does NOT make it a technical-content question: leave process_intent true and still emit docnumber when named, but the retrieval path must NOT seal to that document alone.
24819
24832
  - term: the defined term when the question asks what something is ("what is an accuracy class" \u2192 "accuracy class"); otherwise null.
@@ -24993,6 +25006,7 @@ export {
24993
25006
  machineOffers,
24994
25007
  parseContext,
24995
25008
  namedDocumentIn,
25009
+ matchesDocScope,
24996
25010
  resolveDocScope,
24997
25011
  appliedContext,
24998
25012
  parseAppliedContext,