@konneal/engine 0.2.188 → 0.2.189
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/ai.d.ts +7 -0
- package/dist/ask-LPNODCPM.js +16 -0
- package/dist/{chunk-4AP763GX.js → chunk-22WB6IVC.js} +7 -9
- package/dist/{chunk-G435JWGV.js → chunk-5PKKAHY4.js} +5 -5
- package/dist/{chunk-4BQA7PJ3.js → chunk-7YMIUTPY.js} +1 -1
- package/dist/{chunk-L32WSANI.js → chunk-AVNHVFEB.js} +26 -3
- package/dist/{chunk-VT5ZHCOC.js → chunk-ECNBEZGK.js} +5 -5
- package/dist/{chunk-A2HQNENL.js → chunk-FCRTWZQE.js} +121 -25
- package/dist/{chunk-NHYYMRZC.js → chunk-GJQT4IMD.js} +1 -1
- package/dist/{chunk-YGQCVPX6.js → chunk-H6ZULBW2.js} +4 -1
- package/dist/{chunk-SLYQ6L52.js → chunk-Q7QL3457.js} +52 -38
- package/dist/config.d.ts +1 -2
- package/dist/context.d.ts +14 -0
- package/dist/docOverview.d.ts +35 -0
- package/dist/{env-BZWHCSCL.js → env-4LR6Y5CC.js} +1 -1
- package/dist/prompts/understanding.md +2 -1
- package/dist/reflect.d.ts +1 -1
- package/dist/search-DE5ADCVM.js +14 -0
- package/dist/{tools-CYSL26HX.js → tools-7GKMDWVB.js} +5 -5
- package/dist/understandContract.d.ts +3 -0
- 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 +11 -11
- package/dist/worker_public/src/requestScope.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/prompts/understanding.md +2 -1
- package/workers/worker_public/src/ai.ts +30 -6
- package/workers/worker_public/src/ask.ts +83 -16
- package/workers/worker_public/src/config.ts +7 -9
- package/workers/worker_public/src/context.ts +14 -0
- package/workers/worker_public/src/docOverview.ts +77 -0
- package/workers/worker_public/src/faithfulness.ts +11 -1
- package/workers/worker_public/src/lexical.ts +21 -19
- package/workers/worker_public/src/ports/cloudflare/adapters.ts +4 -2
- package/workers/worker_public/src/reflect.ts +8 -7
- package/workers/worker_public/src/stages/dense.ts +29 -42
- package/workers/worker_public/src/stages/glossary.ts +1 -1
- package/workers/worker_public/src/stages/rerank.ts +6 -2
- package/workers/worker_public/src/understandContract.ts +4 -0
- package/dist/ask-TJK7DQ45.js +0 -16
- package/dist/search-FJAOGMEO.js +0 -14
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
embed,
|
|
3
3
|
rerank
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-AVNHVFEB.js";
|
|
5
5
|
import {
|
|
6
6
|
bubbleConfirmPage,
|
|
7
7
|
isAllowedBubbleOrigin
|
|
8
|
-
} from "./chunk-
|
|
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-
|
|
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-
|
|
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
|
-
|
|
22058
|
-
|
|
22059
|
-
|
|
22060
|
-
|
|
22061
|
-
|
|
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
|
-
|
|
22069
|
-
|
|
22070
|
-
|
|
22071
|
-
|
|
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
|
-
|
|
22164
|
-
|
|
22165
|
-
|
|
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
|
|
22171
|
-
|
|
22172
|
-
|
|
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
|
-
|
|
22179
|
-
|
|
22180
|
-
|
|
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
|
-
|
|
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,
|
package/dist/config.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export declare const MODELS: {
|
|
|
10
10
|
readonly decisionsModel: "@cf/cloudflare/clef";
|
|
11
11
|
readonly understand: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
12
12
|
readonly acts: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
13
|
-
readonly fallback: "@cf/
|
|
13
|
+
readonly fallback: "@cf/zai-org/glm-5.3";
|
|
14
14
|
readonly grader: "@cf/deepseek-ai/deepseek-v4.1-flash-1017";
|
|
15
15
|
readonly enrich: "@cf/zai-org/glm-5.3";
|
|
16
16
|
readonly listwise: "@cf/zai-org/glm-4.7-flash";
|
|
@@ -56,7 +56,6 @@ export declare const THRESHOLDS: {
|
|
|
56
56
|
* not only the source rung. Fails open (a slow or unparseable check
|
|
57
57
|
* leaves the source-rung note unchanged). */
|
|
58
58
|
readonly compressShare: 0.6;
|
|
59
|
-
readonly denseStarveK: 100;
|
|
60
59
|
readonly decisionsGateMin: 0.5;
|
|
61
60
|
readonly decisionsMetBand: 0.8;
|
|
62
61
|
readonly decisionsRefuteBand: 0.2;
|
package/dist/context.d.ts
CHANGED
|
@@ -123,6 +123,19 @@ export declare function matchesDocScope(meta: {
|
|
|
123
123
|
doc_number?: string;
|
|
124
124
|
docidentifier?: string;
|
|
125
125
|
}, scopeDocNumber: string): boolean;
|
|
126
|
+
/** The platform-side form of a doc scope. Vectorize filters return
|
|
127
|
+
* results only for the fields the index has indexed for filtering — on
|
|
128
|
+
* this index doc_number, edition, language and doctype; a filter on
|
|
129
|
+
* doc_id, clause_anchor or docidentifier returns nothing, and `$and` /
|
|
130
|
+
* `$or` arrays are rejected (measured 2026-12-03 on the production
|
|
131
|
+
* index). The scope's number is asked for as written and, for a part,
|
|
132
|
+
* as its family's base too: the index stores "60" on family grain and
|
|
133
|
+
* "60-1" on some planes. */
|
|
134
|
+
export declare function docScopeFilter(scopeDocNumber: string): {
|
|
135
|
+
doc_number: {
|
|
136
|
+
$in: string[];
|
|
137
|
+
};
|
|
138
|
+
};
|
|
126
139
|
export declare function resolveDocScope(env: any, ctx: DeclaredContext): Promise<DocScope | null>;
|
|
127
140
|
export declare function appliedContext(declared: DeclaredContext | null, scope: DocScope | null, note?: AppliedContext["note"], live?: LiveEcho): AppliedContext;
|
|
128
141
|
/** Validate a context_applied object arriving from a client (the
|
|
@@ -146,6 +159,7 @@ export declare function syntheticUnderstanding(scope: DocScope): {
|
|
|
146
159
|
edition: string | null;
|
|
147
160
|
language: null;
|
|
148
161
|
process_intent: boolean;
|
|
162
|
+
doc_overview: boolean;
|
|
149
163
|
term: null;
|
|
150
164
|
defined_terms: never[];
|
|
151
165
|
standalone_query: string;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { QueryUnderstanding } from "./understandContract.ts";
|
|
2
|
+
type PassageMeta = {
|
|
3
|
+
doc_number?: string;
|
|
4
|
+
docidentifier?: string;
|
|
5
|
+
};
|
|
6
|
+
/** "OIML R 60-1:2021" → "r 60-1": the publisher prefix and the edition
|
|
7
|
+
* drop, the series letter and the number (with any part) stay. */
|
|
8
|
+
export declare function identKey(docidentifier: string | null | undefined): string | null;
|
|
9
|
+
/** A passage is the named publication's own when its identifier names
|
|
10
|
+
* the same series and number — every part of a base-named publication
|
|
11
|
+
* ("R 60" covers R 60-1, R 60-A, the 1991 edition), only the named part
|
|
12
|
+
* when a part is named. The identifier decides whenever the passage has
|
|
13
|
+
* one: index metadata keys the number inconsistently (the base "60" on
|
|
14
|
+
* family grain, a part as "60-1" on some planes) and carries no series,
|
|
15
|
+
* so the number alone cannot tell R 60 from a B 60 or R 60-2 from the
|
|
16
|
+
* named R 60-1. A passage with no identifier falls back to the engine's
|
|
17
|
+
* own scope matcher, at the named part's grain. */
|
|
18
|
+
export declare function isNamedDocumentPassage(meta: PassageMeta, docNumber: string, docidentifier: string | null | undefined): boolean;
|
|
19
|
+
/** How many of the prompt's passages are the named publication's own. */
|
|
20
|
+
export declare function inScopePassages(used: ReadonlyArray<{
|
|
21
|
+
metadata?: PassageMeta;
|
|
22
|
+
}>, docNumber: string, docidentifier: string | null | undefined): number;
|
|
23
|
+
export declare function docOverviewRefusal(args: {
|
|
24
|
+
answer: string;
|
|
25
|
+
refusal: string;
|
|
26
|
+
understanding: QueryUnderstanding | null | undefined;
|
|
27
|
+
used: ReadonlyArray<{
|
|
28
|
+
metadata?: PassageMeta;
|
|
29
|
+
}>;
|
|
30
|
+
}): boolean;
|
|
31
|
+
/** The regeneration's ground instruction: say what the publication is
|
|
32
|
+
* from its own passages, cite them, and still admit when none of them
|
|
33
|
+
* describes the publication. */
|
|
34
|
+
export declare function docOverviewInstruction(docidentifier: string): string;
|
|
35
|
+
export {};
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
You normalize a user question for a retrieval system over {{CORPUS_KIND_PLURAL}} (English corpus).
|
|
2
2
|
Reply with ONLY a JSON object, no prose, no markdown fence:
|
|
3
|
-
{"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": []}
|
|
3
|
+
{"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": []}
|
|
4
4
|
Rules:
|
|
5
5
|
- 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) — e.g. "hi!", "who are you?", "what can you do?", "merci !", "was kannst du?". ANY question about a subject — legal metrology, other technical fields, cooking, sports, current events, ANYTHING — is "knowledge", even when the corpus cannot answer it; do NOT use "conversational" to mean off-topic.
|
|
6
6
|
- docidentifier: the publication the user names, in any spelling ({{SPELLING_EXAMPLES}}, "the nonautomatic weighing instruments recommendation" → 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.
|
|
7
7
|
- edition: only when the user pins a year.
|
|
8
8
|
- 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).
|
|
9
|
+
- doc_overview: true ONLY when the question asks what the NAMED publication is or covers as a whole — 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") — 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" → false), and false when no publication is named.
|
|
9
10
|
- 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") — 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.
|
|
10
11
|
- process_intent: true when the question is about the GOVERNING SYSTEM around publications rather than a publication's own technical content — 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.
|
|
11
12
|
- term: the defined term when the question asks what something is ("what is an accuracy class" → "accuracy class"); otherwise null.
|
package/dist/reflect.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export interface ReflectionResult {
|
|
|
2
2
|
grounded: boolean;
|
|
3
3
|
missing_info: string;
|
|
4
4
|
}
|
|
5
|
-
export declare function reflect(ai: any, model: string, question: string, answer: string, passages: string[]): Promise<ReflectionResult | null>;
|
|
5
|
+
export declare function reflect(ai: any, model: string, question: string, answer: string, passages: string[], notes?: string): Promise<ReflectionResult | null>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleSearch
|
|
3
|
+
} from "./chunk-5PKKAHY4.js";
|
|
4
|
+
import "./chunk-Q7QL3457.js";
|
|
5
|
+
import "./chunk-AVNHVFEB.js";
|
|
6
|
+
import "./chunk-GJQT4IMD.js";
|
|
7
|
+
import "./chunk-ETLSWSZ7.js";
|
|
8
|
+
import "./chunk-7YMIUTPY.js";
|
|
9
|
+
import "./chunk-22WB6IVC.js";
|
|
10
|
+
import "./chunk-3FYJM7LH.js";
|
|
11
|
+
import "./chunk-H6ZULBW2.js";
|
|
12
|
+
export {
|
|
13
|
+
handleSearch
|
|
14
|
+
};
|
|
@@ -4,12 +4,12 @@ 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-ECNBEZGK.js";
|
|
8
|
+
import "./chunk-AVNHVFEB.js";
|
|
9
|
+
import "./chunk-7YMIUTPY.js";
|
|
10
|
+
import "./chunk-22WB6IVC.js";
|
|
11
11
|
import "./chunk-3FYJM7LH.js";
|
|
12
|
-
import "./chunk-
|
|
12
|
+
import "./chunk-H6ZULBW2.js";
|
|
13
13
|
export {
|
|
14
14
|
TOOLS_REGISTRY,
|
|
15
15
|
TOOL_DECLARATION,
|
|
@@ -9,6 +9,9 @@ export interface QueryUnderstanding {
|
|
|
9
9
|
language?: string | null;
|
|
10
10
|
/** the question is about a process around publications (certify, apply…) */
|
|
11
11
|
process_intent: boolean;
|
|
12
|
+
/** the question asks what the NAMED publication is or covers as a whole
|
|
13
|
+
* (an overview of the document), not something inside it */
|
|
14
|
+
doc_overview: boolean;
|
|
12
15
|
/** definition-style question whose subject is `term` */
|
|
13
16
|
term: string | null;
|
|
14
17
|
/** corpus-terminology mapping of everyday wording (drift→creep) */
|
|
@@ -9,16 +9,16 @@ import {
|
|
|
9
9
|
listUserDocuments,
|
|
10
10
|
scoreFaithfulness,
|
|
11
11
|
scoreJudge
|
|
12
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-FCRTWZQE.js";
|
|
13
13
|
import "../../chunk-IRCDOFP4.js";
|
|
14
14
|
import {
|
|
15
15
|
TOOLS_REGISTRY,
|
|
16
16
|
bindModelNode,
|
|
17
17
|
modelGroundingBlock
|
|
18
|
-
} from "../../chunk-
|
|
18
|
+
} from "../../chunk-ECNBEZGK.js";
|
|
19
19
|
import {
|
|
20
20
|
handleSearch
|
|
21
|
-
} from "../../chunk-
|
|
21
|
+
} from "../../chunk-5PKKAHY4.js";
|
|
22
22
|
import {
|
|
23
23
|
buildMessages,
|
|
24
24
|
citations,
|
|
@@ -43,11 +43,11 @@ import {
|
|
|
43
43
|
sessionFrom,
|
|
44
44
|
telemetry,
|
|
45
45
|
understandQuery
|
|
46
|
-
} from "../../chunk-
|
|
46
|
+
} from "../../chunk-Q7QL3457.js";
|
|
47
47
|
import {
|
|
48
48
|
embed,
|
|
49
49
|
generateOnce
|
|
50
|
-
} from "../../chunk-
|
|
50
|
+
} from "../../chunk-AVNHVFEB.js";
|
|
51
51
|
import {
|
|
52
52
|
authenticate,
|
|
53
53
|
corsHeaders,
|
|
@@ -56,14 +56,14 @@ import {
|
|
|
56
56
|
readJson,
|
|
57
57
|
validateQuery,
|
|
58
58
|
withCors
|
|
59
|
-
} from "../../chunk-
|
|
59
|
+
} from "../../chunk-GJQT4IMD.js";
|
|
60
60
|
import {
|
|
61
61
|
canonicalRefusal
|
|
62
62
|
} from "../../chunk-ETLSWSZ7.js";
|
|
63
63
|
import {
|
|
64
64
|
entitlementScope,
|
|
65
65
|
standardKeysFrom
|
|
66
|
-
} from "../../chunk-
|
|
66
|
+
} from "../../chunk-7YMIUTPY.js";
|
|
67
67
|
import {
|
|
68
68
|
LIMITS,
|
|
69
69
|
MODELS,
|
|
@@ -74,7 +74,7 @@ import {
|
|
|
74
74
|
roleModel,
|
|
75
75
|
sha256Hex,
|
|
76
76
|
today
|
|
77
|
-
} from "../../chunk-
|
|
77
|
+
} from "../../chunk-22WB6IVC.js";
|
|
78
78
|
import {
|
|
79
79
|
P,
|
|
80
80
|
setProfile
|
|
@@ -85,7 +85,7 @@ import {
|
|
|
85
85
|
cfStore,
|
|
86
86
|
cfVectorIndex,
|
|
87
87
|
portModelRunner
|
|
88
|
-
} from "../../chunk-
|
|
88
|
+
} from "../../chunk-H6ZULBW2.js";
|
|
89
89
|
|
|
90
90
|
// workers/worker_public/src/conversations.ts
|
|
91
91
|
var ID_RE = /^[a-zA-Z0-9_-]{8,64}$/;
|
|
@@ -1183,13 +1183,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
1183
1183
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
1184
1184
|
body: JSON.stringify({ ...args, stream: false })
|
|
1185
1185
|
});
|
|
1186
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
1186
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-7GKMDWVB.js");
|
|
1187
1187
|
let payload;
|
|
1188
1188
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
1189
1189
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
1190
1190
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
1191
1191
|
} else {
|
|
1192
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
1192
|
+
const res = name === "ask" ? await (await import("../../ask-LPNODCPM.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-DE5ADCVM.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1193
1193
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1194
1194
|
}
|
|
1195
1195
|
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-7YMIUTPY.js";
|
|
8
|
+
import "../../chunk-22WB6IVC.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.189",
|
|
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",
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
You normalize a user question for a retrieval system over {{CORPUS_KIND_PLURAL}} (English corpus).
|
|
2
2
|
Reply with ONLY a JSON object, no prose, no markdown fence:
|
|
3
|
-
{"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": []}
|
|
3
|
+
{"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": []}
|
|
4
4
|
Rules:
|
|
5
5
|
- 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) — e.g. "hi!", "who are you?", "what can you do?", "merci !", "was kannst du?". ANY question about a subject — legal metrology, other technical fields, cooking, sports, current events, ANYTHING — is "knowledge", even when the corpus cannot answer it; do NOT use "conversational" to mean off-topic.
|
|
6
6
|
- docidentifier: the publication the user names, in any spelling ({{SPELLING_EXAMPLES}}, "the nonautomatic weighing instruments recommendation" → 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.
|
|
7
7
|
- edition: only when the user pins a year.
|
|
8
8
|
- 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).
|
|
9
|
+
- doc_overview: true ONLY when the question asks what the NAMED publication is or covers as a whole — 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") — 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" → false), and false when no publication is named.
|
|
9
10
|
- 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") — 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.
|
|
10
11
|
- process_intent: true when the question is about the GOVERNING SYSTEM around publications rather than a publication's own technical content — 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.
|
|
11
12
|
- term: the defined term when the question asks what something is ("what is an accuracy class" → "accuracy class"); otherwise null.
|
|
@@ -29,19 +29,42 @@ export async function embed(ai: ModelRunner, _model: string, text: string): Prom
|
|
|
29
29
|
|
|
30
30
|
import { answerEffort, effortBudget, generationSampling } from "./config.ts";
|
|
31
31
|
|
|
32
|
+
/** The platform's per-minute inference allowance (3021) and its capacity
|
|
33
|
+
* signal (3040) reset with the minute: an immediate retry hits the same
|
|
34
|
+
* wall, so the caller waits before trying again. Measured 2026-12-03 —
|
|
35
|
+
* with every generation role on one model, two parallel question streams
|
|
36
|
+
* exhausted it and half the judging calls failed. */
|
|
37
|
+
export function isCapacityError(e: unknown): boolean {
|
|
38
|
+
return /3021|rate limit|3040|capacity/i.test(String(e));
|
|
39
|
+
}
|
|
40
|
+
export const CAPACITY_PAUSE_MS = 15_000;
|
|
41
|
+
|
|
32
42
|
export async function rerank(
|
|
33
43
|
ai: AnyAi,
|
|
34
44
|
model: string,
|
|
35
45
|
query: string,
|
|
36
46
|
texts: string[],
|
|
37
47
|
): Promise<number[] | null> {
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
41
|
-
|
|
48
|
+
// Workers AI bge-reranker-base rejects the whole batch (400 / 5006) when any
|
|
49
|
+
// context has text length < 1; score only non-empty candidates and leave
|
|
50
|
+
// empty slots NaN so one empty vector never poisons the pool.
|
|
51
|
+
const idx: number[] = [];
|
|
52
|
+
const nonEmpty: string[] = [];
|
|
53
|
+
for (let i = 0; i < texts.length; i++) {
|
|
54
|
+
if (typeof texts[i] === "string" && texts[i].trim().length > 0) {
|
|
55
|
+
idx.push(i);
|
|
56
|
+
nonEmpty.push(texts[i]);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!nonEmpty.length) return null;
|
|
42
60
|
for (let attempt = 0; attempt < 2; attempt++) {
|
|
43
|
-
const scores = await ai.rerank(model, query,
|
|
44
|
-
if (scores && scores.some((s) => Number.isFinite(s)))
|
|
61
|
+
const scores = await ai.rerank(model, query, nonEmpty);
|
|
62
|
+
if (scores && scores.some((s) => Number.isFinite(s))) {
|
|
63
|
+
if (idx.length === texts.length) return scores;
|
|
64
|
+
const out = new Array<number>(texts.length).fill(NaN);
|
|
65
|
+
idx.forEach((orig, k) => { out[orig] = scores[k]; });
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
45
68
|
}
|
|
46
69
|
console.error("rerank failed, using vector order");
|
|
47
70
|
return null;
|
|
@@ -78,6 +101,7 @@ export async function generateOnce(env: any, model: string, messages: any[], eff
|
|
|
78
101
|
if (attempt === 0) console.error("generate returned empty:", model);
|
|
79
102
|
} catch (e) {
|
|
80
103
|
console.error("generate failed:", model, String(e).slice(0, 120));
|
|
104
|
+
if (attempt === 0 && isCapacityError(e)) await delay(CAPACITY_PAUSE_MS);
|
|
81
105
|
}
|
|
82
106
|
}
|
|
83
107
|
return null;
|