@konneal/engine 0.2.96 → 0.2.98
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-4G24T25V.js +15 -0
- package/dist/{chunk-AJU6LMY3.js → chunk-A3ELAHKF.js} +3 -3
- package/dist/{chunk-CX3OVN3V.js → chunk-BIX3SMC7.js} +6 -6
- package/dist/{chunk-2PCUAJJO.js → chunk-BOAITSVV.js} +1 -0
- package/dist/{chunk-SPKPH54J.js → chunk-DTW4UW2E.js} +1 -1
- package/dist/{chunk-ZLQMRQOV.js → chunk-GY33RTEO.js} +5 -5
- package/dist/{chunk-LOBYXEVD.js → chunk-KNCRYAX3.js} +1 -1
- package/dist/{chunk-PTCDEFI3.js → chunk-TXPWLKCI.js} +23 -16
- package/dist/{chunk-LVZTWUVJ.js → chunk-U4ERFUOK.js} +1 -1
- package/dist/config.d.ts +1 -0
- package/dist/search-EQAOPFCC.js +13 -0
- package/dist/{tools-Z4HQH3QU.js → tools-YHEXFX6V.js} +4 -4
- 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 +14 -12
- package/dist/worker_public/src/requestScope.js +2 -2
- package/package.json +1 -1
- package/workers/worker_public/src/config.ts +1 -0
- package/workers/worker_public/src/index.ts +8 -2
- package/workers/worker_public/src/stages/licensedLane.ts +39 -21
- package/dist/ask-KKOQH7HK.js +0 -15
- package/dist/search-CGQFGYTR.js +0 -13
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleAsk
|
|
3
|
+
} from "./chunk-BIX3SMC7.js";
|
|
4
|
+
import "./chunk-A3ELAHKF.js";
|
|
5
|
+
import "./chunk-TXPWLKCI.js";
|
|
6
|
+
import "./chunk-KNCRYAX3.js";
|
|
7
|
+
import "./chunk-DTW4UW2E.js";
|
|
8
|
+
import "./chunk-A3QHHUN5.js";
|
|
9
|
+
import "./chunk-U4ERFUOK.js";
|
|
10
|
+
import "./chunk-BOAITSVV.js";
|
|
11
|
+
import "./chunk-JZFXSTYX.js";
|
|
12
|
+
import "./chunk-3FYJM7LH.js";
|
|
13
|
+
export {
|
|
14
|
+
handleAsk
|
|
15
|
+
};
|
|
@@ -3,13 +3,13 @@ import {
|
|
|
3
3
|
hasLane,
|
|
4
4
|
portIndex,
|
|
5
5
|
portModelRunner
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-KNCRYAX3.js";
|
|
7
7
|
import {
|
|
8
8
|
standardKeysFrom
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-U4ERFUOK.js";
|
|
10
10
|
import {
|
|
11
11
|
THRESHOLDS
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-BOAITSVV.js";
|
|
13
13
|
import {
|
|
14
14
|
P
|
|
15
15
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
tableRetyped,
|
|
19
19
|
toolNote,
|
|
20
20
|
verdictNote
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-A3ELAHKF.js";
|
|
22
22
|
import {
|
|
23
23
|
NO_CONTEXT,
|
|
24
24
|
answerQuality,
|
|
@@ -56,20 +56,20 @@ import {
|
|
|
56
56
|
tokenBudget,
|
|
57
57
|
understandQuery,
|
|
58
58
|
usageTotal
|
|
59
|
-
} from "./chunk-
|
|
59
|
+
} from "./chunk-TXPWLKCI.js";
|
|
60
60
|
import {
|
|
61
61
|
embed,
|
|
62
62
|
generateOnce,
|
|
63
63
|
portModelRunner,
|
|
64
64
|
portStore
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-KNCRYAX3.js";
|
|
66
66
|
import {
|
|
67
67
|
corsHeaders,
|
|
68
68
|
err,
|
|
69
69
|
json,
|
|
70
70
|
readJson,
|
|
71
71
|
validateQuery
|
|
72
|
-
} from "./chunk-
|
|
72
|
+
} from "./chunk-DTW4UW2E.js";
|
|
73
73
|
import {
|
|
74
74
|
canonicalRefusal,
|
|
75
75
|
refusalAnswer
|
|
@@ -79,7 +79,7 @@ import {
|
|
|
79
79
|
requestSalt,
|
|
80
80
|
resolveRequestScope,
|
|
81
81
|
standardKeysFrom
|
|
82
|
-
} from "./chunk-
|
|
82
|
+
} from "./chunk-U4ERFUOK.js";
|
|
83
83
|
import {
|
|
84
84
|
LIMITS,
|
|
85
85
|
MODELS,
|
|
@@ -90,7 +90,7 @@ import {
|
|
|
90
90
|
requestEffort,
|
|
91
91
|
roleModel,
|
|
92
92
|
sha256Hex
|
|
93
|
-
} from "./chunk-
|
|
93
|
+
} from "./chunk-BOAITSVV.js";
|
|
94
94
|
import {
|
|
95
95
|
certificateLinks,
|
|
96
96
|
registerNote,
|
|
@@ -65,6 +65,7 @@ var THRESHOLDS = {
|
|
|
65
65
|
* pool below the primary dense lane; they must earn their window
|
|
66
66
|
* slot under the cross-encoder, not by graph membership alone. */
|
|
67
67
|
graphLaneDiscount: 0.75,
|
|
68
|
+
licensedLaneScore: 0.5,
|
|
68
69
|
/** The entailment gate (TODO.new-era/10): the faithfulness scorer
|
|
69
70
|
* promoted from eval-only onto the serving path. The confidence line
|
|
70
71
|
* then states a measurement — claim support in the cited passages —
|
|
@@ -6,27 +6,27 @@ import {
|
|
|
6
6
|
sessionFrom,
|
|
7
7
|
telemetry,
|
|
8
8
|
understandQuery
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-TXPWLKCI.js";
|
|
10
10
|
import {
|
|
11
11
|
portModelRunner
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-KNCRYAX3.js";
|
|
13
13
|
import {
|
|
14
14
|
corsHeaders,
|
|
15
15
|
err,
|
|
16
16
|
json,
|
|
17
17
|
readJson,
|
|
18
18
|
validateQuery
|
|
19
|
-
} from "./chunk-
|
|
19
|
+
} from "./chunk-DTW4UW2E.js";
|
|
20
20
|
import {
|
|
21
21
|
entitlementScope,
|
|
22
22
|
standardKeysFrom
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-U4ERFUOK.js";
|
|
24
24
|
import {
|
|
25
25
|
LIMITS,
|
|
26
26
|
MODELS,
|
|
27
27
|
num,
|
|
28
28
|
sha256Hex
|
|
29
|
-
} from "./chunk-
|
|
29
|
+
} from "./chunk-BOAITSVV.js";
|
|
30
30
|
|
|
31
31
|
// workers/worker_public/src/search.ts
|
|
32
32
|
async function handleSearch(env, ctx, req, tier, key) {
|
|
@@ -3,12 +3,13 @@ import {
|
|
|
3
3
|
hasLane,
|
|
4
4
|
portIndex,
|
|
5
5
|
portModelRunner,
|
|
6
|
+
portStore,
|
|
6
7
|
rerank
|
|
7
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-KNCRYAX3.js";
|
|
8
9
|
import {
|
|
9
10
|
bubbleConfirmPage,
|
|
10
11
|
isAllowedBubbleOrigin
|
|
11
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DTW4UW2E.js";
|
|
12
13
|
import {
|
|
13
14
|
DATASETS,
|
|
14
15
|
LIMITS,
|
|
@@ -18,7 +19,7 @@ import {
|
|
|
18
19
|
processExpansion,
|
|
19
20
|
sha256Hex,
|
|
20
21
|
today
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-BOAITSVV.js";
|
|
22
23
|
import {
|
|
23
24
|
P
|
|
24
25
|
} from "./chunk-3FYJM7LH.js";
|
|
@@ -22523,29 +22524,35 @@ var graphLane = {
|
|
|
22523
22524
|
};
|
|
22524
22525
|
|
|
22525
22526
|
// workers/worker_public/src/stages/licensedLane.ts
|
|
22527
|
+
var sha1Hex = async (s8) => {
|
|
22528
|
+
const digest = await crypto.subtle.digest("SHA-1", new TextEncoder().encode(s8));
|
|
22529
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
22530
|
+
};
|
|
22526
22531
|
var licensedLane = {
|
|
22527
22532
|
name: "licensed-lane",
|
|
22528
22533
|
failure: "additive",
|
|
22529
|
-
when: (c) => !!c.opts.licensedDocNumbers?.length
|
|
22530
|
-
prefetch: (c) => {
|
|
22531
|
-
c.lane["licensed-lane"] = portIndex(c.env, "public").query({
|
|
22532
|
-
vector: c.vector,
|
|
22533
|
-
topK: 12,
|
|
22534
|
-
filter: { standard: { $in: c.opts.licensedDocNumbers } }
|
|
22535
|
-
});
|
|
22536
|
-
},
|
|
22534
|
+
when: (c) => !!c.opts.licensedDocNumbers?.length,
|
|
22537
22535
|
run: async (c) => {
|
|
22538
|
-
const
|
|
22536
|
+
const standards = c.opts.licensedDocNumbers;
|
|
22537
|
+
const placeholders = standards.map((_, i) => `?${i + 1}`).join(",");
|
|
22538
|
+
const rows = await portStore(c.env).prepare(`SELECT standard, node_id FROM model_nodes WHERE standard IN (${placeholders}) LIMIT 40`).bind(...standards).all().catch(() => ({ results: [] }));
|
|
22539
|
+
const ids = await Promise.all(
|
|
22540
|
+
(rows.results ?? []).map(
|
|
22541
|
+
async (r) => "m" + (await sha1Hex(`${r.standard}|${r.node_id}`)).slice(0, 16)
|
|
22542
|
+
)
|
|
22543
|
+
);
|
|
22544
|
+
if (!ids.length) return;
|
|
22545
|
+
const matches = await portIndex(c.env, "public").getByIds(ids);
|
|
22539
22546
|
const seenIds = new Set(c.matches.map((m) => m.id));
|
|
22540
22547
|
let merged = 0;
|
|
22541
|
-
for (const m of
|
|
22542
|
-
if (!seenIds.has(m.id)) {
|
|
22543
|
-
c.matches.push({ id: m.id, score:
|
|
22548
|
+
for (const m of matches) {
|
|
22549
|
+
if (m.metadata && !seenIds.has(m.id)) {
|
|
22550
|
+
c.matches.push({ id: m.id, score: THRESHOLDS.licensedLaneScore, metadata: m.metadata });
|
|
22544
22551
|
seenIds.add(m.id);
|
|
22545
22552
|
merged++;
|
|
22546
22553
|
}
|
|
22547
22554
|
}
|
|
22548
|
-
console.log("licensed lane:",
|
|
22555
|
+
console.log("licensed lane:", ids.length, "units,", matches.length, "vectors,", merged, "merged");
|
|
22549
22556
|
}
|
|
22550
22557
|
};
|
|
22551
22558
|
|
package/dist/config.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export declare const THRESHOLDS: {
|
|
|
37
37
|
* pool below the primary dense lane; they must earn their window
|
|
38
38
|
* slot under the cross-encoder, not by graph membership alone. */
|
|
39
39
|
readonly graphLaneDiscount: 0.75;
|
|
40
|
+
readonly licensedLaneScore: 0.5;
|
|
40
41
|
/** The entailment gate (TODO.new-era/10): the faithfulness scorer
|
|
41
42
|
* promoted from eval-only onto the serving path. The confidence line
|
|
42
43
|
* then states a measurement — claim support in the cited passages —
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
handleSearch
|
|
3
|
+
} from "./chunk-GY33RTEO.js";
|
|
4
|
+
import "./chunk-TXPWLKCI.js";
|
|
5
|
+
import "./chunk-KNCRYAX3.js";
|
|
6
|
+
import "./chunk-DTW4UW2E.js";
|
|
7
|
+
import "./chunk-A3QHHUN5.js";
|
|
8
|
+
import "./chunk-U4ERFUOK.js";
|
|
9
|
+
import "./chunk-BOAITSVV.js";
|
|
10
|
+
import "./chunk-3FYJM7LH.js";
|
|
11
|
+
export {
|
|
12
|
+
handleSearch
|
|
13
|
+
};
|
|
@@ -4,10 +4,10 @@ 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-A3ELAHKF.js";
|
|
8
|
+
import "./chunk-KNCRYAX3.js";
|
|
9
|
+
import "./chunk-U4ERFUOK.js";
|
|
10
|
+
import "./chunk-BOAITSVV.js";
|
|
11
11
|
import "./chunk-3FYJM7LH.js";
|
|
12
12
|
export {
|
|
13
13
|
TOOLS_REGISTRY,
|
|
@@ -4,15 +4,15 @@ import {
|
|
|
4
4
|
handleMemories,
|
|
5
5
|
scoreFaithfulness,
|
|
6
6
|
scoreJudge
|
|
7
|
-
} from "../../chunk-
|
|
7
|
+
} from "../../chunk-BIX3SMC7.js";
|
|
8
8
|
import {
|
|
9
9
|
TOOLS_REGISTRY,
|
|
10
10
|
bindModelNode,
|
|
11
11
|
modelGroundingBlock
|
|
12
|
-
} from "../../chunk-
|
|
12
|
+
} from "../../chunk-A3ELAHKF.js";
|
|
13
13
|
import {
|
|
14
14
|
handleSearch
|
|
15
|
-
} from "../../chunk-
|
|
15
|
+
} from "../../chunk-GY33RTEO.js";
|
|
16
16
|
import {
|
|
17
17
|
buildMessages,
|
|
18
18
|
citations,
|
|
@@ -34,13 +34,13 @@ import {
|
|
|
34
34
|
sessionFrom,
|
|
35
35
|
telemetry,
|
|
36
36
|
understandQuery
|
|
37
|
-
} from "../../chunk-
|
|
37
|
+
} from "../../chunk-TXPWLKCI.js";
|
|
38
38
|
import {
|
|
39
39
|
cfBlobs,
|
|
40
40
|
embed,
|
|
41
41
|
generateOnce,
|
|
42
42
|
portModelRunner
|
|
43
|
-
} from "../../chunk-
|
|
43
|
+
} from "../../chunk-KNCRYAX3.js";
|
|
44
44
|
import {
|
|
45
45
|
authenticate,
|
|
46
46
|
corsHeaders,
|
|
@@ -49,14 +49,14 @@ import {
|
|
|
49
49
|
readJson,
|
|
50
50
|
validateQuery,
|
|
51
51
|
withCors
|
|
52
|
-
} from "../../chunk-
|
|
52
|
+
} from "../../chunk-DTW4UW2E.js";
|
|
53
53
|
import {
|
|
54
54
|
canonicalRefusal
|
|
55
55
|
} from "../../chunk-A3QHHUN5.js";
|
|
56
56
|
import {
|
|
57
57
|
entitlementScope,
|
|
58
58
|
standardKeysFrom
|
|
59
|
-
} from "../../chunk-
|
|
59
|
+
} from "../../chunk-U4ERFUOK.js";
|
|
60
60
|
import {
|
|
61
61
|
LIMITS,
|
|
62
62
|
MODELS,
|
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
roleModel,
|
|
68
68
|
sha256Hex,
|
|
69
69
|
today
|
|
70
|
-
} from "../../chunk-
|
|
70
|
+
} from "../../chunk-BOAITSVV.js";
|
|
71
71
|
import "../../chunk-JZFXSTYX.js";
|
|
72
72
|
import {
|
|
73
73
|
P,
|
|
@@ -990,13 +990,13 @@ async function callToolOnce(env, ctx, _req, tier, key, name, args, t0) {
|
|
|
990
990
|
// stream:false forces the JSON lane (anon defaults to SSE)
|
|
991
991
|
body: JSON.stringify({ ...args, stream: false })
|
|
992
992
|
});
|
|
993
|
-
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-
|
|
993
|
+
const { runTool, TOOLS_REGISTRY: TOOLS_REGISTRY2 } = await import("../../tools-YHEXFX6V.js");
|
|
994
994
|
let payload;
|
|
995
995
|
if (TOOLS_REGISTRY2.some((t) => t.name === name && t.audiences.includes("mcp"))) {
|
|
996
996
|
const r = await runTool({ ...env, DB: env.DB }, { name, args }, "mcp");
|
|
997
997
|
payload = r ? { tool: r.name, query: r.query, result: r.output } : { error: { message: `tool ${name} returned nothing for the given arguments` } };
|
|
998
998
|
} else {
|
|
999
|
-
const res = name === "ask" ? await (await import("../../ask-
|
|
999
|
+
const res = name === "ask" ? await (await import("../../ask-4G24T25V.js")).handleAsk(env, ctx, inner, tier, key) : await (await import("../../search-EQAOPFCC.js")).handleSearch(env, ctx, inner, tier, key);
|
|
1000
1000
|
payload = await res.json().catch(() => ({ error: { message: "tool transport failed", status: res.status } }));
|
|
1001
1001
|
}
|
|
1002
1002
|
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 });
|
|
@@ -1415,12 +1415,14 @@ async function healthRoute(c) {
|
|
|
1415
1415
|
}
|
|
1416
1416
|
async function tierFor(c) {
|
|
1417
1417
|
const isApi = c.path.startsWith("/v1/");
|
|
1418
|
+
const isMcp = c.path === "/mcp";
|
|
1419
|
+
const bearer = c.req.headers.get("authorization")?.replace(/^Bearer\s+/i, "").trim();
|
|
1418
1420
|
let key = null;
|
|
1419
|
-
if (isApi) {
|
|
1421
|
+
if (isApi || isMcp && bearer) {
|
|
1420
1422
|
key = await authenticate(c.env, c.req);
|
|
1421
1423
|
if (!key) return err(401, "unauthorized", `Provide a valid API key: Authorization: Bearer ${P().publisher.id}_...`);
|
|
1422
1424
|
}
|
|
1423
|
-
let tier =
|
|
1425
|
+
let tier = key ? "key" : "anon";
|
|
1424
1426
|
if (!isApi && await sessionFrom(c.req, c.env)) tier = "member";
|
|
1425
1427
|
else if (!isApi && await opTokenMember(c.env, opCfg(c.env), c.req)) tier = "member";
|
|
1426
1428
|
return { tier, key };
|
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
requestSalt,
|
|
5
5
|
resolveRequestScope,
|
|
6
6
|
standardKeysFrom
|
|
7
|
-
} from "../../chunk-
|
|
8
|
-
import "../../chunk-
|
|
7
|
+
} from "../../chunk-U4ERFUOK.js";
|
|
8
|
+
import "../../chunk-BOAITSVV.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.98",
|
|
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",
|
|
@@ -62,6 +62,7 @@ export const THRESHOLDS = {
|
|
|
62
62
|
* pool below the primary dense lane; they must earn their window
|
|
63
63
|
* slot under the cross-encoder, not by graph membership alone. */
|
|
64
64
|
graphLaneDiscount: 0.75,
|
|
65
|
+
licensedLaneScore: 0.5,
|
|
65
66
|
/** The entailment gate (TODO.new-era/10): the faithfulness scorer
|
|
66
67
|
* promoted from eval-only onto the serving path. The confidence line
|
|
67
68
|
* then states a measurement — claim support in the cited passages —
|
|
@@ -186,12 +186,18 @@ async function healthRoute(c: RouteContext): Promise<Response> {
|
|
|
186
186
|
* key. */
|
|
187
187
|
async function tierFor(c: RouteContext): Promise<{ tier: "anon" | "key" | "member"; key: ApiKey | null } | Response> {
|
|
188
188
|
const isApi = c.path.startsWith("/v1/");
|
|
189
|
+
// /mcp rides the same key tiering: a bearer presented to the JSON-RPC
|
|
190
|
+
// endpoint authenticates like /v1 (key tier, the caller's quota and
|
|
191
|
+
// telemetry) — but the endpoint stays open to anonymous agents, so an
|
|
192
|
+
// ABSENT bearer is not an error, only a PRESENT-but-invalid one is.
|
|
193
|
+
const isMcp = c.path === "/mcp";
|
|
194
|
+
const bearer = c.req.headers.get("authorization")?.replace(/^Bearer\s+/i, "").trim();
|
|
189
195
|
let key: ApiKey | null = null;
|
|
190
|
-
if (isApi) {
|
|
196
|
+
if (isApi || (isMcp && bearer)) {
|
|
191
197
|
key = await authenticate(c.env, c.req);
|
|
192
198
|
if (!key) return err(401, "unauthorized", `Provide a valid API key: Authorization: Bearer ${P().publisher.id}_...`);
|
|
193
199
|
}
|
|
194
|
-
let tier: "anon" | "key" | "member" =
|
|
200
|
+
let tier: "anon" | "key" | "member" = key ? "key" : "anon";
|
|
195
201
|
// No SESSION_SECRET precondition: the delegated bearer (the platform
|
|
196
202
|
// bubble's OP-minted JWT, delegated.ts) admits the member lane on its
|
|
197
203
|
// own — sessionFrom returns null honestly when neither lane applies.
|
|
@@ -1,38 +1,56 @@
|
|
|
1
1
|
// Licensed lane (additive): an entitled caller whose question is
|
|
2
2
|
// topically about a licensed standard gets that standard's typed units
|
|
3
|
-
// merged into the pool
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
8
|
-
//
|
|
9
|
-
//
|
|
3
|
+
// merged into the pool before rerank — the public restatements stop
|
|
4
|
+
// out-ranking the licensed package's own machinery (the rank-order gap
|
|
5
|
+
// the quality ledger has documented on every damp-heat run since the
|
|
6
|
+
// eleven-standard wave).
|
|
7
|
+
//
|
|
8
|
+
// Identity, not similarity: the units are resolved from the model
|
|
9
|
+
// plane's own registry (D1 model_nodes by standard) and turned into
|
|
10
|
+
// index ids with the exporter's hash — `m` + sha1(standard|node_id)
|
|
11
|
+
// truncated to 16 — then fetched by id. Vectorize metadata filtering
|
|
12
|
+
// plays no part (measured: REST and binding filters on this index
|
|
13
|
+
// return empty even for values proven present), and no similarity
|
|
14
|
+
// search is needed — the package's units are the package's units, and
|
|
15
|
+
// the pool's cross-encoder ranks them against the question like every
|
|
16
|
+
// other candidate.
|
|
10
17
|
import { THRESHOLDS } from "../config.ts";
|
|
11
|
-
import { portIndex } from "../env.ts";
|
|
18
|
+
import { portIndex, portStore } from "../env.ts";
|
|
12
19
|
import type { Stage } from "./types.ts";
|
|
13
20
|
|
|
21
|
+
const sha1Hex = async (s: string) => {
|
|
22
|
+
const digest = await crypto.subtle.digest("SHA-1", new TextEncoder().encode(s));
|
|
23
|
+
return [...new Uint8Array(digest)].map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
24
|
+
};
|
|
25
|
+
|
|
14
26
|
export const licensedLane: Stage = {
|
|
15
27
|
name: "licensed-lane",
|
|
16
28
|
failure: "additive",
|
|
17
|
-
when: (c) => !!c.opts.licensedDocNumbers?.length
|
|
18
|
-
prefetch: (c) => {
|
|
19
|
-
c.lane["licensed-lane"] = portIndex(c.env, "public").query({
|
|
20
|
-
vector: c.vector,
|
|
21
|
-
topK: 12,
|
|
22
|
-
filter: { standard: { $in: c.opts.licensedDocNumbers } },
|
|
23
|
-
});
|
|
24
|
-
},
|
|
29
|
+
when: (c) => !!c.opts.licensedDocNumbers?.length,
|
|
25
30
|
run: async (c) => {
|
|
26
|
-
const
|
|
31
|
+
const standards = c.opts.licensedDocNumbers!;
|
|
32
|
+
const placeholders = standards.map((_, i) => `?${i + 1}`).join(",");
|
|
33
|
+
const rows = await portStore(c.env)
|
|
34
|
+
.prepare(`SELECT standard, node_id FROM model_nodes WHERE standard IN (${placeholders}) LIMIT 40`)
|
|
35
|
+
.bind(...standards)
|
|
36
|
+
.all()
|
|
37
|
+
.catch(() => ({ results: [] }));
|
|
38
|
+
const ids = await Promise.all(
|
|
39
|
+
((rows.results ?? []) as { standard: string; node_id: string }[]).map(async (r) =>
|
|
40
|
+
"m" + (await sha1Hex(`${r.standard}|${r.node_id}`)).slice(0, 16),
|
|
41
|
+
),
|
|
42
|
+
);
|
|
43
|
+
if (!ids.length) return;
|
|
44
|
+
const matches = await portIndex(c.env, "public").getByIds(ids);
|
|
27
45
|
const seenIds = new Set(c.matches.map((m: any) => m.id));
|
|
28
46
|
let merged = 0;
|
|
29
|
-
for (const m of
|
|
30
|
-
if (!seenIds.has(m.id)) {
|
|
31
|
-
c.matches.push({ id: m.id, score:
|
|
47
|
+
for (const m of matches) {
|
|
48
|
+
if (m.metadata && !seenIds.has(m.id)) {
|
|
49
|
+
c.matches.push({ id: m.id, score: THRESHOLDS.licensedLaneScore, metadata: m.metadata });
|
|
32
50
|
seenIds.add(m.id);
|
|
33
51
|
merged++;
|
|
34
52
|
}
|
|
35
53
|
}
|
|
36
|
-
console.log("licensed lane:",
|
|
54
|
+
console.log("licensed lane:", ids.length, "units,", matches.length, "vectors,", merged, "merged");
|
|
37
55
|
},
|
|
38
56
|
};
|
package/dist/ask-KKOQH7HK.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleAsk
|
|
3
|
-
} from "./chunk-CX3OVN3V.js";
|
|
4
|
-
import "./chunk-AJU6LMY3.js";
|
|
5
|
-
import "./chunk-PTCDEFI3.js";
|
|
6
|
-
import "./chunk-LOBYXEVD.js";
|
|
7
|
-
import "./chunk-SPKPH54J.js";
|
|
8
|
-
import "./chunk-A3QHHUN5.js";
|
|
9
|
-
import "./chunk-LVZTWUVJ.js";
|
|
10
|
-
import "./chunk-2PCUAJJO.js";
|
|
11
|
-
import "./chunk-JZFXSTYX.js";
|
|
12
|
-
import "./chunk-3FYJM7LH.js";
|
|
13
|
-
export {
|
|
14
|
-
handleAsk
|
|
15
|
-
};
|
package/dist/search-CGQFGYTR.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
handleSearch
|
|
3
|
-
} from "./chunk-ZLQMRQOV.js";
|
|
4
|
-
import "./chunk-PTCDEFI3.js";
|
|
5
|
-
import "./chunk-LOBYXEVD.js";
|
|
6
|
-
import "./chunk-SPKPH54J.js";
|
|
7
|
-
import "./chunk-A3QHHUN5.js";
|
|
8
|
-
import "./chunk-LVZTWUVJ.js";
|
|
9
|
-
import "./chunk-2PCUAJJO.js";
|
|
10
|
-
import "./chunk-3FYJM7LH.js";
|
|
11
|
-
export {
|
|
12
|
-
handleSearch
|
|
13
|
-
};
|