-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKnowledgeGapDetector.ts
More file actions
66 lines (60 loc) · 1.87 KB
/
KnowledgeGapDetector.ts
File metadata and controls
66 lines (60 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import type { Hash } from "../core/types";
import type { ModelProfile } from "../core/ModelProfile";
import { hashText } from "../core/crypto/hash";
import type { Metroid } from "./MetroidBuilder";
export interface KnowledgeGap {
queryText: string;
queryEmbedding: Float32Array;
knowledgeBoundary: Hash | null;
detectedAt: string;
}
export interface CuriosityProbe {
probeId: Hash;
queryText: string;
queryEmbedding: Float32Array;
knowledgeBoundary: Hash | null;
mimeType: string;
modelUrn: string;
createdAt: string;
}
/**
* Returns a KnowledgeGap when the metroid signals that m2 could not be found
* (i.e. the engine has no antithesis for this query). Returns null when the
* metroid is complete and no gap was detected.
*/
export async function detectKnowledgeGap(
queryText: string,
queryEmbedding: Float32Array,
metroid: Metroid,
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- reserved for future model-aware gap categorisation
_modelProfile: ModelProfile,
): Promise<KnowledgeGap | null> {
if (!metroid.knowledgeGap) return null;
return {
queryText,
queryEmbedding,
knowledgeBoundary: metroid.m1 !== "" ? metroid.m1 : null,
detectedAt: new Date().toISOString(),
};
}
/**
* Builds a serialisable CuriosityProbe from a detected KnowledgeGap.
* The probeId is the SHA-256 of (queryText + detectedAt) so it is
* deterministic for the same gap inputs.
*/
export async function buildCuriosityProbe(
gap: KnowledgeGap,
modelProfile: ModelProfile,
mimeType = "text/plain",
): Promise<CuriosityProbe> {
const probeId = await hashText(gap.queryText + gap.detectedAt);
return {
probeId,
queryText: gap.queryText,
queryEmbedding: gap.queryEmbedding,
knowledgeBoundary: gap.knowledgeBoundary,
mimeType,
modelUrn: `urn:model:${modelProfile.modelId}`,
createdAt: new Date().toISOString(),
};
}