@konneal/engine 0.2.24 → 0.2.25
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-OO6UUIFF.js → ask-YE2L3Q5H.js} +2 -2
- package/dist/{chunk-HXWDVAVN.js → chunk-6MHR5JI4.js} +1 -1
- package/dist/{chunk-IM5KMIL6.js → chunk-BWSH7VBG.js} +6 -3
- package/dist/{chunk-PZLYPUYJ.js → chunk-WQ2PYIWK.js} +1 -1
- package/dist/{search-OJ776DMH.js → search-I26YUVSP.js} +2 -2
- package/dist/worker_public/src/index.js +4 -4
- package/package.json +1 -1
- package/workers/worker_public/src/ask.ts +8 -2
- package/workers/worker_public/src/pipeline.ts +1 -1
- package/workers/worker_public/src/stages/types.ts +5 -0
|
@@ -23275,7 +23275,7 @@ async function retrieve(env, query, opts = {}) {
|
|
|
23275
23275
|
let rq = opts.queryOverride?.trim() || u?.standalone_query?.trim() || folded;
|
|
23276
23276
|
if (u?.process_intent) rq += processExpansion();
|
|
23277
23277
|
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);
|
|
23278
|
-
const lexicalP = lexicalPrefilter(env, rq).catch(() => []);
|
|
23278
|
+
const lexicalP = lexicalPrefilter(env, opts.lexicalBoost ? `${rq} ${opts.lexicalBoost}` : rq).catch(() => []);
|
|
23279
23279
|
const [vector, lexicalHits0] = await Promise.all([vectorP, lexicalP]);
|
|
23280
23280
|
const lexicalHits = opts.sealScope || opts.standardKeys ? lexicalHits0.filter(
|
|
23281
23281
|
(h) => (!opts.sealScope || h.metadata.doc_number === opts.sealScope.doc_number && (!opts.sealScope.edition || h.metadata.edition === opts.sealScope.edition)) && standardKeyAllowed(h.metadata, opts.standardKeys)
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
syntheticUnderstanding,
|
|
28
28
|
telemetry,
|
|
29
29
|
understandQuery
|
|
30
|
-
} from "./chunk-
|
|
30
|
+
} from "./chunk-6MHR5JI4.js";
|
|
31
31
|
import {
|
|
32
32
|
corsHeaders,
|
|
33
33
|
err,
|
|
@@ -2013,10 +2013,12 @@ ${summary}` }] : [],
|
|
|
2013
2013
|
} : null;
|
|
2014
2014
|
if (aggregationVerdict) console.log("aggregation engine:", aggregationVerdict.operation, aggregationVerdict.table, "\u2192", aggregationVerdict.value);
|
|
2015
2015
|
let boundaryNote = null;
|
|
2016
|
+
let boundaryBoost;
|
|
2016
2017
|
if (P().sources?.licensed?.length) {
|
|
2017
2018
|
const match = matchLicensedTopic(q.query, P().sources.licensed);
|
|
2018
2019
|
if (match && !(standardKeys?.has(match.entry.key) ?? false)) {
|
|
2019
2020
|
const docNum = match.entry.doc_number ?? "";
|
|
2021
|
+
boundaryBoost = docNum || void 0;
|
|
2020
2022
|
let citing = [];
|
|
2021
2023
|
if (docNum) {
|
|
2022
2024
|
const rows = await env.DB.prepare(
|
|
@@ -2062,7 +2064,8 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2062
2064
|
optimisticHits,
|
|
2063
2065
|
optimisticVec,
|
|
2064
2066
|
datasetScope: narrowed ? corpora : null,
|
|
2065
|
-
standardKeys
|
|
2067
|
+
standardKeys,
|
|
2068
|
+
lexicalBoost: boundaryBoost
|
|
2066
2069
|
});
|
|
2067
2070
|
stageTiming["retrieve-core"] = Date.now() - tR;
|
|
2068
2071
|
console.log("stage: retrieve", Date.now() - tR, "ms");
|
|
@@ -2086,7 +2089,7 @@ Answer account questions from these records ONLY: name the record when you use i
|
|
|
2086
2089
|
if (grade === "weak" && understanding?.docidentifier) {
|
|
2087
2090
|
const broaden = `${understanding.standalone_query || q.query} ${understanding.docidentifier}`.trim();
|
|
2088
2091
|
const tc = Date.now();
|
|
2089
|
-
const second = await retrieve(env, q.query, { prev, understanding, queryOverride: broaden, federate, datasetScope: narrowed ? corpora : null, standardKeys, sealScope: declaredScoped ? docScope : null });
|
|
2092
|
+
const second = await retrieve(env, q.query, { prev, understanding, queryOverride: broaden, federate, datasetScope: narrowed ? corpora : null, standardKeys, sealScope: declaredScoped ? docScope : null, lexicalBoost: boundaryBoost });
|
|
2090
2093
|
const grade2 = await gradeRetrieval(env.AI, roleModel(env, "grader"), q.query, second.hits.map((h) => h.text));
|
|
2091
2094
|
stageTiming.corrective = Date.now() - tc;
|
|
2092
2095
|
if (grade2 === "good") retrieved = second;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
handleSearch
|
|
3
|
-
} from "../../chunk-
|
|
3
|
+
} from "../../chunk-WQ2PYIWK.js";
|
|
4
4
|
import {
|
|
5
5
|
checkQuoteAnchors,
|
|
6
6
|
handleAsk,
|
|
7
7
|
handleMemories,
|
|
8
8
|
scoreJudge,
|
|
9
9
|
standardForDocNumber
|
|
10
|
-
} from "../../chunk-
|
|
10
|
+
} from "../../chunk-BWSH7VBG.js";
|
|
11
11
|
import {
|
|
12
12
|
buildMessages,
|
|
13
13
|
citations,
|
|
@@ -29,7 +29,7 @@ import {
|
|
|
29
29
|
sessionFrom,
|
|
30
30
|
telemetry,
|
|
31
31
|
understandQuery
|
|
32
|
-
} from "../../chunk-
|
|
32
|
+
} from "../../chunk-6MHR5JI4.js";
|
|
33
33
|
import {
|
|
34
34
|
authenticate,
|
|
35
35
|
corsHeaders,
|
|
@@ -979,7 +979,7 @@ async function handleMcp(env, ctx, req, tier, key) {
|
|
|
979
979
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
980
980
|
body: JSON.stringify({ ...args, stream: false })
|
|
981
981
|
});
|
|
982
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
982
|
+
const res = name === "ask" ? await (await import("../../ask-YE2L3Q5H.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-I26YUVSP.js")).handleSearch(env, ctx, inner, tier, key);
|
|
983
983
|
return res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
984
984
|
});
|
|
985
985
|
if (out.ok && "accepted" in out) return new Response(null, { status: 202 });
|
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.25",
|
|
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",
|
|
@@ -853,10 +853,16 @@ async function handleAsk(
|
|
|
853
853
|
// reference the licensed document, and the note instructs the model
|
|
854
854
|
// to attribute, never to recite the licensed parameters.
|
|
855
855
|
let boundaryNote: string | null = null;
|
|
856
|
+
// the boost rides RETRIEVAL (the lexical lane below): chunks whose
|
|
857
|
+
// prose references the licensed document — the referencing
|
|
858
|
+
// publication's own clause — surface for a question the document's
|
|
859
|
+
// vocabulary alone would miss
|
|
860
|
+
let boundaryBoost: string | undefined;
|
|
856
861
|
if (P().sources?.licensed?.length) {
|
|
857
862
|
const match = matchLicensedTopic(q.query, P().sources.licensed);
|
|
858
863
|
if (match && !(standardKeys?.has(match.entry.key) ?? false)) {
|
|
859
864
|
const docNum = match.entry.doc_number ?? "";
|
|
865
|
+
boundaryBoost = docNum || undefined;
|
|
860
866
|
let citing: string[] = [];
|
|
861
867
|
if (docNum) {
|
|
862
868
|
const rows = await env.DB.prepare(
|
|
@@ -923,7 +929,7 @@ async function handleAsk(
|
|
|
923
929
|
// publications there).
|
|
924
930
|
retrieved = await retrieve(env, q.query, { prev, understanding, federate, warmEmbed, graphDocNumbers,
|
|
925
931
|
sealScope: declaredScoped ? docScope : null, optimisticHits, optimisticVec,
|
|
926
|
-
datasetScope: narrowed ? corpora : null, standardKeys });
|
|
932
|
+
datasetScope: narrowed ? corpora : null, standardKeys, lexicalBoost: boundaryBoost });
|
|
927
933
|
stageTiming["retrieve-core"] = Date.now() - tR;
|
|
928
934
|
console.log("stage: retrieve", Date.now() - tR, "ms");
|
|
929
935
|
// ── TTFT surgery: the two post-retrieval LLM calls run IN PARALLEL —
|
|
@@ -957,7 +963,7 @@ async function handleAsk(
|
|
|
957
963
|
if (grade === "weak" && understanding?.docidentifier) {
|
|
958
964
|
const broaden = `${understanding.standalone_query || q.query} ${understanding.docidentifier}`.trim();
|
|
959
965
|
const tc = Date.now();
|
|
960
|
-
const second = await retrieve(env, q.query, { prev, understanding, queryOverride: broaden, federate, datasetScope: narrowed ? corpora : null, standardKeys, sealScope: declaredScoped ? docScope : null });
|
|
966
|
+
const second = await retrieve(env, q.query, { prev, understanding, queryOverride: broaden, federate, datasetScope: narrowed ? corpora : null, standardKeys, sealScope: declaredScoped ? docScope : null, lexicalBoost: boundaryBoost });
|
|
961
967
|
const grade2 = await gradeRetrieval(env.AI, roleModel(env, "grader"), q.query, second.hits.map((h: Hit) => h.text));
|
|
962
968
|
stageTiming.corrective = Date.now() - tc;
|
|
963
969
|
if (grade2 === "good") retrieved = second; // corrective retry must be strictly better
|
|
@@ -120,7 +120,7 @@ export async function retrieve(
|
|
|
120
120
|
: rq === folded && opts.warmEmbed
|
|
121
121
|
? opts.warmEmbed.then((w) => w ?? embed(portModelRunner(env), MODELS.embed, rq))
|
|
122
122
|
: embed(portModelRunner(env), MODELS.embed, rq);
|
|
123
|
-
const lexicalP = lexicalPrefilter(env, rq).catch(() => [] as Hit[]);
|
|
123
|
+
const lexicalP = lexicalPrefilter(env, opts.lexicalBoost ? `${rq} ${opts.lexicalBoost}` : rq).catch(() => [] as Hit[]);
|
|
124
124
|
const [vector, lexicalHits0] = await Promise.all([vectorP, lexicalP]);
|
|
125
125
|
// The declared context's seal binds the lexical lane at the SOURCE: the
|
|
126
126
|
// RRF fusion mixes the full-corpus lexical ranking straight into the
|
|
@@ -12,6 +12,11 @@ export interface RetrieveOptions {
|
|
|
12
12
|
prev?: string;
|
|
13
13
|
understanding?: QueryUnderstanding | null;
|
|
14
14
|
queryOverride?: string;
|
|
15
|
+
/** Extra terms appended to the LEXICAL lane's query only (never the
|
|
16
|
+
* dense vector): the licensed-boundary boost — chunks whose prose
|
|
17
|
+
* references the licensed document surface for a question the
|
|
18
|
+
* document's own vocabulary would otherwise miss. */
|
|
19
|
+
lexicalBoost?: string;
|
|
15
20
|
federate?: (query: string) => Promise<Hit[]>;
|
|
16
21
|
warmEmbed?: Promise<number[] | null>;
|
|
17
22
|
graphDocNumbers?: string[];
|