@chunktrace/core 0.0.0-stage → 0.9.0
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/LICENSE +21 -0
- package/README.md +24 -2
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +22 -0
- package/dist/cli.js.map +1 -0
- package/dist/diagnose.d.ts +8 -0
- package/dist/diagnose.d.ts.map +1 -0
- package/dist/diagnose.js +242 -0
- package/dist/diagnose.js.map +1 -0
- package/dist/filter.d.ts +18 -0
- package/dist/filter.d.ts.map +1 -0
- package/dist/filter.js +52 -0
- package/dist/filter.js.map +1 -0
- package/dist/format.d.ts +4 -0
- package/dist/format.d.ts.map +1 -0
- package/dist/format.js +43 -0
- package/dist/format.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/schema.d.ts +17 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +82 -0
- package/dist/schema.js.map +1 -0
- package/dist/timeline.d.ts +42 -0
- package/dist/timeline.d.ts.map +1 -0
- package/dist/timeline.js +153 -0
- package/dist/timeline.js.map +1 -0
- package/dist/types.d.ts +127 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/version.d.ts +7 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +7 -0
- package/dist/version.js.map +1 -0
- package/package.json +32 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hathor Software, LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @chunktrace/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The trace schema and the deterministic diagnostic engine behind [ChunkTrace](https://chunktrace.com), which diagnoses RAG retrieval failures from a single query trace. Most applications want [`@chunktrace/sdk`](https://www.npmjs.com/package/@chunktrace/sdk), which records traces and re-exports everything here.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
npm install @chunktrace/core
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { diagnose, formatReport, validateTrace } from "@chunktrace/core";
|
|
11
|
+
|
|
12
|
+
const checked = validateTrace(JSON.parse(traceJson));
|
|
13
|
+
if (checked.ok) console.log(formatReport(checked.trace, diagnose(checked.trace)));
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Or from a shell:
|
|
17
|
+
|
|
18
|
+
```
|
|
19
|
+
npx @chunktrace/core diagnose trace.json
|
|
20
|
+
npx @chunktrace/core diagnose trace.json --json
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
A diagnosis lists findings, each with a code (for example `TOPK_CUT`, `FILTER_REMOVED`, `RERANK_DROPPED`), the field values from the trace that prove it, and a next step. Exactly one finding is `primary`: the earliest stage that lost a chunk the answer needed. The analysis makes no LLM or network calls, and `ENGINE_VERSION` changes whenever a rule does.
|
|
24
|
+
|
|
25
|
+
Requires Node.js 22 or later. MIT licensed. Copyright © 2026 Hathor Software, LLC.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import { diagnose } from "./diagnose.js";
|
|
4
|
+
import { formatReport } from "./format.js";
|
|
5
|
+
const [cmd, file, ...rest] = process.argv.slice(2);
|
|
6
|
+
if (cmd !== "diagnose" || !file) {
|
|
7
|
+
console.error("usage: chunktrace diagnose <trace.json> [--json]");
|
|
8
|
+
process.exit(2);
|
|
9
|
+
}
|
|
10
|
+
const trace = JSON.parse(readFileSync(file, "utf8"));
|
|
11
|
+
if (trace.schema_version !== "0") {
|
|
12
|
+
console.error(`unsupported schema_version: ${String(trace.schema_version)}`);
|
|
13
|
+
process.exit(2);
|
|
14
|
+
}
|
|
15
|
+
const report = diagnose(trace);
|
|
16
|
+
if (rest.includes("--json")) {
|
|
17
|
+
console.log(JSON.stringify(report, null, 2));
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
console.log(formatReport(trace, report));
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAG3C,MAAM,CAAC,GAAG,EAAE,IAAI,EAAE,GAAG,IAAI,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAEnD,IAAI,GAAG,KAAK,UAAU,IAAI,CAAC,IAAI,EAAE,CAAC;IAChC,OAAO,CAAC,KAAK,CAAC,kDAAkD,CAAC,CAAC;IAClE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAU,CAAC;AAC9D,IAAI,KAAK,CAAC,cAAc,KAAK,GAAG,EAAE,CAAC;IACjC,OAAO,CAAC,KAAK,CAAC,+BAA+B,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC;IAC7E,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC;AAED,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC/B,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;IAC5B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC/C,CAAC;KAAM,CAAC;IACN,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DiagnosisReport, Trace } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* Deterministic rule engine. Every finding's message is fully determined by
|
|
4
|
+
* the values placed in `evidence`; nothing is inferred from outside the trace.
|
|
5
|
+
*/
|
|
6
|
+
export declare function diagnose(trace: Trace): DiagnosisReport;
|
|
7
|
+
export declare function labeledChunkIds(trace: Trace): Set<string>;
|
|
8
|
+
//# sourceMappingURL=diagnose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"diagnose.d.ts","sourceRoot":"","sources":["../src/diagnose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,eAAe,EAIf,KAAK,EACN,MAAM,YAAY,CAAC;AAKpB;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,eAAe,CA8DtD;AAgID,wBAAgB,eAAe,CAAC,KAAK,EAAE,KAAK,GAAG,GAAG,CAAC,MAAM,CAAC,CAoBzD"}
|
package/dist/diagnose.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
import { describeClause, evaluateFilter } from "./filter.js";
|
|
2
|
+
const STAGE_ORDER = ["index", "filter", "threshold", "top_k", "rerank", "context", "generation", "meta"];
|
|
3
|
+
/**
|
|
4
|
+
* Deterministic rule engine. Every finding's message is fully determined by
|
|
5
|
+
* the values placed in `evidence`; nothing is inferred from outside the trace.
|
|
6
|
+
*/
|
|
7
|
+
export function diagnose(trace) {
|
|
8
|
+
const labeled = labeledChunkIds(trace);
|
|
9
|
+
const findings = [];
|
|
10
|
+
const summary = buildSummary(trace, labeled);
|
|
11
|
+
if (!trace.label) {
|
|
12
|
+
findings.push({
|
|
13
|
+
code: "NO_LABEL",
|
|
14
|
+
stage: "meta",
|
|
15
|
+
primary: true,
|
|
16
|
+
chunk_ids: [],
|
|
17
|
+
message: "No expected evidence supplied; showing timeline only.",
|
|
18
|
+
evidence: {},
|
|
19
|
+
next_step: "Add a keyword, document or chunk label to this query and re-run.",
|
|
20
|
+
});
|
|
21
|
+
return { trace_id: trace.trace_id, findings, summary };
|
|
22
|
+
}
|
|
23
|
+
const shadow = trace.retrieval.shadow;
|
|
24
|
+
const candidates = trace.retrieval.candidates;
|
|
25
|
+
const candidateIds = new Set(candidates.map((c) => c.chunk_id));
|
|
26
|
+
if (!shadow) {
|
|
27
|
+
const missing = [...labeled].filter((id) => !candidateIds.has(id));
|
|
28
|
+
findings.push({
|
|
29
|
+
code: "SHADOW_MISSING",
|
|
30
|
+
stage: "meta",
|
|
31
|
+
primary: false, // promoted below if nothing else explains the failure
|
|
32
|
+
chunk_ids: missing,
|
|
33
|
+
message: missing.length > 0
|
|
34
|
+
? `Labeled chunk(s) ${fmtIds(missing)} were not in the returned candidates; filter, threshold and top_k effects are not observable without a shadow query.`
|
|
35
|
+
: labeled.size === 0
|
|
36
|
+
? `No returned candidate matches ${describeLabel(trace)}; filter, threshold and top_k effects are not observable without a shadow query.`
|
|
37
|
+
: "Filter, threshold and top_k effects are not observable without a shadow query.",
|
|
38
|
+
evidence: { labeled_chunk_ids: [...labeled], returned_chunk_ids: [...candidateIds] },
|
|
39
|
+
next_step: "Enable diagnose mode in the SDK or supply retrieval.shadow.candidates in the trace.",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
else if (![...labeled].some((id) => shadow.candidates.some((c) => c.chunk_id === id))) {
|
|
43
|
+
findings.push({
|
|
44
|
+
code: "NOT_RETRIEVABLE",
|
|
45
|
+
stage: "index",
|
|
46
|
+
primary: false,
|
|
47
|
+
chunk_ids: [],
|
|
48
|
+
message: `No chunk matching ${describeLabel(trace)} appeared in the top ${shadow.top_k} unfiltered results.`,
|
|
49
|
+
evidence: { label: trace.label, shadow_top_k: shadow.top_k, shadow_size: shadow.candidates.length },
|
|
50
|
+
next_step: "Check that the source document is indexed and that chunking keeps the expected phrase intact.",
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Per labeled chunk: find the first stage where it was lost.
|
|
54
|
+
for (const id of labeled) {
|
|
55
|
+
const f = traceChunk(trace, id);
|
|
56
|
+
if (f)
|
|
57
|
+
findings.push(f);
|
|
58
|
+
}
|
|
59
|
+
// Exactly one primary: earliest stage. Ties broken by labeled-chunk order (stable sort).
|
|
60
|
+
const ranked = [...findings].sort((a, b) => STAGE_ORDER.indexOf(a.stage) - STAGE_ORDER.indexOf(b.stage));
|
|
61
|
+
const primary = ranked.find((f) => f.code !== "SHADOW_MISSING") ?? ranked[0];
|
|
62
|
+
for (const f of findings)
|
|
63
|
+
f.primary = f === primary;
|
|
64
|
+
return { trace_id: trace.trace_id, findings: ranked, summary };
|
|
65
|
+
}
|
|
66
|
+
/* ---------- per-chunk stage walk ---------- */
|
|
67
|
+
function traceChunk(trace, id) {
|
|
68
|
+
const { retrieval, rerank, context } = trace;
|
|
69
|
+
const { params, candidates, shadow } = retrieval;
|
|
70
|
+
const inCandidates = candidates.find((c) => c.chunk_id === id);
|
|
71
|
+
if (!inCandidates) {
|
|
72
|
+
if (!shadow)
|
|
73
|
+
return null; // covered by SHADOW_MISSING
|
|
74
|
+
const s = shadow.candidates.find((c) => c.chunk_id === id);
|
|
75
|
+
if (!s)
|
|
76
|
+
return null; // covered by NOT_RETRIEVABLE (or this chunk simply isn't in shadow)
|
|
77
|
+
const fr = evaluateFilter(params.metadata_filter, s.metadata);
|
|
78
|
+
if (!fr.passes) {
|
|
79
|
+
const f = fr.failures[0];
|
|
80
|
+
return {
|
|
81
|
+
code: "FILTER_REMOVED",
|
|
82
|
+
stage: "filter",
|
|
83
|
+
primary: false,
|
|
84
|
+
chunk_ids: [id],
|
|
85
|
+
message: `Filter ${f.key} ${describeClause(f.expected)} removed chunk ${id} (its ${f.key} is ${JSON.stringify(f.actual ?? null)}).`,
|
|
86
|
+
evidence: { chunk_id: id, shadow_rank: s.rank, score: s.score, failures: fr.failures, metadata: s.metadata ?? {} },
|
|
87
|
+
next_step: `Loosen or correct the ${f.key} filter, or fix this chunk's metadata at index time.`,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
if (params.similarity_threshold !== undefined && s.score < params.similarity_threshold) {
|
|
91
|
+
return {
|
|
92
|
+
code: "THRESHOLD_REMOVED",
|
|
93
|
+
stage: "threshold",
|
|
94
|
+
primary: false,
|
|
95
|
+
chunk_ids: [id],
|
|
96
|
+
message: `Chunk ${id} scored ${s.score}, below similarity_threshold=${params.similarity_threshold}.`,
|
|
97
|
+
evidence: { chunk_id: id, score: s.score, similarity_threshold: params.similarity_threshold, shadow_rank: s.rank },
|
|
98
|
+
next_step: "Lower the threshold, or improve the query/embedding so this chunk scores higher.",
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const eligible = eligibleShadow(trace);
|
|
102
|
+
const effRank = eligible.findIndex((c) => c.chunk_id === id) + 1;
|
|
103
|
+
if (effRank > params.top_k) {
|
|
104
|
+
return {
|
|
105
|
+
code: "TOPK_CUT",
|
|
106
|
+
stage: "top_k",
|
|
107
|
+
primary: false,
|
|
108
|
+
chunk_ids: [id],
|
|
109
|
+
message: `Chunk ${id} ranked ${effRank} among eligible results; top_k=${params.top_k} cut it.`,
|
|
110
|
+
evidence: { chunk_id: id, effective_rank: effRank, shadow_rank: s.rank, score: s.score, top_k: params.top_k, eligible_count: eligible.length },
|
|
111
|
+
next_step: "Raise top_k, or add a reranker so a larger candidate pool can be narrowed by relevance.",
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
code: "UNEXPLAINED_EXCLUSION",
|
|
116
|
+
stage: "top_k",
|
|
117
|
+
primary: false,
|
|
118
|
+
chunk_ids: [id],
|
|
119
|
+
message: `Chunk ${id} passes the filter and threshold and ranks ${effRank} (within top_k=${params.top_k}) in the shadow query, yet was not returned.`,
|
|
120
|
+
evidence: { chunk_id: id, effective_rank: effRank, top_k: params.top_k, score: s.score },
|
|
121
|
+
next_step: "Likely approximate-NN nondeterminism or a filter the SDK did not capture. Re-run the query and compare.",
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
if (rerank) {
|
|
125
|
+
const r = rerank.results.find((x) => x.chunk_id === id);
|
|
126
|
+
if (r && !r.kept) {
|
|
127
|
+
const rule = rerank.top_n !== undefined && r.rank_after > rerank.top_n
|
|
128
|
+
? `top_n=${rerank.top_n}`
|
|
129
|
+
: rerank.score_threshold !== undefined
|
|
130
|
+
? `score_threshold=${rerank.score_threshold}`
|
|
131
|
+
: "the reranker's inclusion rule";
|
|
132
|
+
return {
|
|
133
|
+
code: "RERANK_DROPPED",
|
|
134
|
+
stage: "rerank",
|
|
135
|
+
primary: false,
|
|
136
|
+
chunk_ids: [id],
|
|
137
|
+
message: `Reranker moved chunk ${id} from rank ${r.rank_before} to ${r.rank_after}; cut by ${rule}.`,
|
|
138
|
+
evidence: { chunk_id: id, rank_before: r.rank_before, rank_after: r.rank_after, rerank_score: r.score, top_n: rerank.top_n, score_threshold: rerank.score_threshold, model: rerank.model },
|
|
139
|
+
next_step: "Raise top_n or lower the reranker threshold, and inspect why the reranker scored this chunk low.",
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
const inc = context.included.find((x) => x.chunk_id === id);
|
|
144
|
+
if (inc) {
|
|
145
|
+
return {
|
|
146
|
+
code: "EVIDENCE_IN_CONTEXT",
|
|
147
|
+
stage: "generation",
|
|
148
|
+
primary: false,
|
|
149
|
+
chunk_ids: [id],
|
|
150
|
+
message: `Chunk ${id} reached the prompt at position ${inc.order}.`,
|
|
151
|
+
evidence: { chunk_id: id, order: inc.order, token_count: inc.token_count, answer_correct: trace.generation?.answer_correct },
|
|
152
|
+
next_step: "Retrieval is fine for this chunk; inspect prompt construction and the model's output.",
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
const exc = context.excluded.find((x) => x.chunk_id === id);
|
|
156
|
+
const reason = exc?.reason ?? "custom";
|
|
157
|
+
const detail = exc?.detail ?? (exc ? undefined : "not listed in context.included or context.excluded");
|
|
158
|
+
return {
|
|
159
|
+
code: "CONTEXT_DROPPED",
|
|
160
|
+
stage: "context",
|
|
161
|
+
primary: false,
|
|
162
|
+
chunk_ids: [id],
|
|
163
|
+
message: `Chunk ${id} was selected but excluded from the prompt: ${reason}${detail ? ` (${detail})` : ""}.`,
|
|
164
|
+
evidence: { chunk_id: id, reason, detail, token_budget: context.token_budget, included_count: context.included.length },
|
|
165
|
+
next_step: reason === "token_budget"
|
|
166
|
+
? "Raise token_budget, shorten chunks, or order by relevance before truncating."
|
|
167
|
+
: "Check the context-assembly step that excluded this chunk.",
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
/* ---------- helpers ---------- */
|
|
171
|
+
/** Shadow candidates that pass both filter and threshold, in score order: the list top_k was applied to. */
|
|
172
|
+
function eligibleShadow(trace) {
|
|
173
|
+
const { params, shadow } = trace.retrieval;
|
|
174
|
+
if (!shadow)
|
|
175
|
+
return [];
|
|
176
|
+
return [...shadow.candidates]
|
|
177
|
+
.filter((c) => evaluateFilter(params.metadata_filter, c.metadata).passes)
|
|
178
|
+
.filter((c) => params.similarity_threshold === undefined || c.score >= params.similarity_threshold)
|
|
179
|
+
.sort((a, b) => b.score - a.score || a.rank - b.rank);
|
|
180
|
+
}
|
|
181
|
+
export function labeledChunkIds(trace) {
|
|
182
|
+
const out = new Set();
|
|
183
|
+
const label = trace.label;
|
|
184
|
+
if (!label)
|
|
185
|
+
return out;
|
|
186
|
+
const all = [...trace.retrieval.candidates, ...(trace.retrieval.shadow?.candidates ?? [])];
|
|
187
|
+
if (label.type === "chunk") {
|
|
188
|
+
for (const id of label.chunk_ids)
|
|
189
|
+
out.add(id);
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
for (const c of all) {
|
|
193
|
+
if (c.matches_label === true)
|
|
194
|
+
out.add(c.chunk_id);
|
|
195
|
+
else if (c.matches_label === undefined) {
|
|
196
|
+
if (label.type === "document" && c.document_id && label.document_ids.includes(c.document_id))
|
|
197
|
+
out.add(c.chunk_id);
|
|
198
|
+
if (label.type === "keyword" && c.text) {
|
|
199
|
+
const t = c.text.toLowerCase();
|
|
200
|
+
if (label.values.some((v) => t.includes(v.toLowerCase())))
|
|
201
|
+
out.add(c.chunk_id);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return out;
|
|
206
|
+
}
|
|
207
|
+
function buildSummary(trace, labeled) {
|
|
208
|
+
const { params, candidates, shadow } = trace.retrieval;
|
|
209
|
+
const s = {
|
|
210
|
+
labeled_chunk_ids: [...labeled],
|
|
211
|
+
shadow_present: !!shadow,
|
|
212
|
+
context_included_count: trace.context.included.length,
|
|
213
|
+
context_excluded_count: trace.context.excluded.length,
|
|
214
|
+
context_token_budget: trace.context.token_budget,
|
|
215
|
+
};
|
|
216
|
+
const used = trace.context.included.reduce((n, c) => n + (c.token_count ?? 0), 0);
|
|
217
|
+
if (trace.context.included.some((c) => c.token_count !== undefined))
|
|
218
|
+
s.context_tokens_used = used;
|
|
219
|
+
if (shadow) {
|
|
220
|
+
const afterFilter = shadow.candidates.filter((c) => evaluateFilter(params.metadata_filter, c.metadata).passes);
|
|
221
|
+
s.filter_removed_count = shadow.candidates.length - afterFilter.length;
|
|
222
|
+
const afterThreshold = params.similarity_threshold === undefined ? afterFilter : afterFilter.filter((c) => c.score >= params.similarity_threshold);
|
|
223
|
+
s.threshold_removed_count = afterFilter.length - afterThreshold.length;
|
|
224
|
+
s.topk_cut_count = Math.max(0, afterThreshold.length - params.top_k);
|
|
225
|
+
}
|
|
226
|
+
if (trace.rerank)
|
|
227
|
+
s.rerank_dropped_count = trace.rerank.results.filter((r) => !r.kept).length;
|
|
228
|
+
void candidates;
|
|
229
|
+
return s;
|
|
230
|
+
}
|
|
231
|
+
function describeLabel(trace) {
|
|
232
|
+
const l = trace.label;
|
|
233
|
+
if (l.type === "keyword")
|
|
234
|
+
return `keyword ${l.values.map((v) => JSON.stringify(v)).join(" or ")}`;
|
|
235
|
+
if (l.type === "document")
|
|
236
|
+
return `document ${fmtIds(l.document_ids)}`;
|
|
237
|
+
return `chunk ${fmtIds(l.chunk_ids)}`;
|
|
238
|
+
}
|
|
239
|
+
function fmt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,cAAc,CAAC,MAAM,CAAC;QACvE,CAAC,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,cAAc,CAAC,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,CAAC;IACD,IAAI,KAAK,CAAC,MAAM;QAAE,CAAC,CAAC,oBAAoB,GAAG,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC;IAC9F,KAAK,UAAU,CAAC;IAChB,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,aAAa,CAAC,KAAY;IACjC,MAAM,CAAC,GAAG,KAAK,CAAC,KAAM,CAAC;IACvB,IAAI,CAAC,CAAC,IAAI,KAAK,SAAS;QAAE,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;IAClG,IAAI,CAAC,CAAC,IAAI,KAAK,UAAU;QAAE,OAAO,YAAY,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC;IACvE,OAAO,SAAS,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;AACxC,CAAC;AAED,SAAS,MAAM,CAAC,GAAa;IAC3B,OAAO,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACxB,CAAC"}
|
package/dist/filter.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { FilterClause, MetadataFilter, MetadataValue } from "./types.js";
|
|
2
|
+
export type FilterFailure = {
|
|
3
|
+
key: string;
|
|
4
|
+
expected: FilterClause;
|
|
5
|
+
actual: MetadataValue | undefined;
|
|
6
|
+
};
|
|
7
|
+
export type FilterResult = {
|
|
8
|
+
passes: boolean;
|
|
9
|
+
failures: FilterFailure[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Re-evaluates a conjunctive metadata filter against a chunk's metadata.
|
|
13
|
+
* This is how we *prove* "the filter removed this chunk" rather than infer it.
|
|
14
|
+
* A missing key never matches an equality/$in/range clause; it does match $ne.
|
|
15
|
+
*/
|
|
16
|
+
export declare function evaluateFilter(filter: MetadataFilter | undefined, metadata: Record<string, MetadataValue> | undefined): FilterResult;
|
|
17
|
+
export declare function describeClause(clause: FilterClause): string;
|
|
18
|
+
//# sourceMappingURL=filter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.d.ts","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAE9E,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,EAAE,YAAY,CAAC;IACvB,MAAM,EAAE,aAAa,GAAG,SAAS,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IAAE,MAAM,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,EAAE,CAAA;CAAE,CAAC;AAE1E;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,cAAc,GAAG,SAAS,EAClC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,GAAG,SAAS,GAClD,YAAY,CAQd;AAeD,wBAAgB,cAAc,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAU3D"}
|
package/dist/filter.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Re-evaluates a conjunctive metadata filter against a chunk's metadata.
|
|
3
|
+
* This is how we *prove* "the filter removed this chunk" rather than infer it.
|
|
4
|
+
* A missing key never matches an equality/$in/range clause; it does match $ne.
|
|
5
|
+
*/
|
|
6
|
+
export function evaluateFilter(filter, metadata) {
|
|
7
|
+
if (!filter)
|
|
8
|
+
return { passes: true, failures: [] };
|
|
9
|
+
const failures = [];
|
|
10
|
+
for (const [key, clause] of Object.entries(filter)) {
|
|
11
|
+
const actual = metadata?.[key];
|
|
12
|
+
if (!clauseMatches(clause, actual))
|
|
13
|
+
failures.push({ key, expected: clause, actual });
|
|
14
|
+
}
|
|
15
|
+
return { passes: failures.length === 0, failures };
|
|
16
|
+
}
|
|
17
|
+
function clauseMatches(clause, actual) {
|
|
18
|
+
if (clause === null || typeof clause !== "object")
|
|
19
|
+
return actual === clause;
|
|
20
|
+
if ("$in" in clause)
|
|
21
|
+
return actual !== undefined && actual !== null && clause.$in.includes(actual);
|
|
22
|
+
if ("$ne" in clause)
|
|
23
|
+
return actual !== clause.$ne;
|
|
24
|
+
if (typeof actual !== "number")
|
|
25
|
+
return false;
|
|
26
|
+
const r = clause;
|
|
27
|
+
if (r.$gt !== undefined && !(actual > r.$gt))
|
|
28
|
+
return false;
|
|
29
|
+
if (r.$gte !== undefined && !(actual >= r.$gte))
|
|
30
|
+
return false;
|
|
31
|
+
if (r.$lt !== undefined && !(actual < r.$lt))
|
|
32
|
+
return false;
|
|
33
|
+
if (r.$lte !== undefined && !(actual <= r.$lte))
|
|
34
|
+
return false;
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
export function describeClause(clause) {
|
|
38
|
+
if (clause === null || typeof clause !== "object")
|
|
39
|
+
return JSON.stringify(clause);
|
|
40
|
+
if ("$in" in clause)
|
|
41
|
+
return `in [${clause.$in.map((v) => JSON.stringify(v)).join(", ")}]`;
|
|
42
|
+
if ("$ne" in clause)
|
|
43
|
+
return `!= ${JSON.stringify(clause.$ne)}`;
|
|
44
|
+
const parts = [];
|
|
45
|
+
const r = clause;
|
|
46
|
+
for (const [op, sym] of [["$gt", ">"], ["$gte", ">="], ["$lt", "<"], ["$lte", "<="]]) {
|
|
47
|
+
if (r[op] !== undefined)
|
|
48
|
+
parts.push(`${sym} ${r[op]}`);
|
|
49
|
+
}
|
|
50
|
+
return parts.join(" and ");
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=filter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter.js","sourceRoot":"","sources":["../src/filter.ts"],"names":[],"mappings":"AAUA;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAC5B,MAAkC,EAClC,QAAmD;IAEnD,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACnD,MAAM,QAAQ,GAAoB,EAAE,CAAC;IACrC,KAAK,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnD,MAAM,MAAM,GAAG,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC;QAC/B,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC;YAAE,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACvF,CAAC;IACD,OAAO,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,QAAQ,EAAE,CAAC;AACrD,CAAC;AAED,SAAS,aAAa,CAAC,MAAoB,EAAE,MAAiC;IAC5E,IAAI,MAAM,KAAK,IAAI,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,KAAK,MAAM,CAAC;IAC5E,IAAI,KAAK,IAAI,MAAM;QAAE,OAAO,MAAM,KAAK,SAAS,IAAI,MAAM,KAAK,IAAI,IAAI,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,MAAyB,CAAC,CAAC;IACtH,IAAI,KAAK,IAAI,MAAM;QAAE,OAAO,MAAM,KAAK,MAAM,CAAC,GAAG,CAAC;IAClD,IAAI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AC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,CAAU,EAAE,CAAC;QAC9F,IAAI,CAAC,CAAC,EAAE,CAAC,KAAK,SAAS;YAAE,KAAK,CAAC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;IACzD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAC7B,CAAC"}
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.d.ts","sourceRoot":"","sources":["../src/format.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEzD,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,GAAG,MAAM,CAmD1E"}
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/** Plain-text report for the CLI. Timeline first, then findings, primary on top. */
|
|
2
|
+
export function formatReport(trace, report) {
|
|
3
|
+
const lines = [];
|
|
4
|
+
const { retrieval, rerank, context } = trace;
|
|
5
|
+
const p = retrieval.params;
|
|
6
|
+
lines.push(`Trace ${trace.trace_id}`);
|
|
7
|
+
lines.push(`Query: ${JSON.stringify(trace.query.text)}`);
|
|
8
|
+
lines.push(`Label: ${trace.label ? JSON.stringify(trace.label) : "(none)"}`);
|
|
9
|
+
lines.push("");
|
|
10
|
+
lines.push("Timeline");
|
|
11
|
+
lines.push(` retrieve index=${retrieval.index.name} top_k=${p.top_k}` +
|
|
12
|
+
(p.similarity_threshold !== undefined ? ` threshold=${p.similarity_threshold}` : "") +
|
|
13
|
+
(p.metadata_filter ? ` filter=${JSON.stringify(p.metadata_filter)}` : "") +
|
|
14
|
+
` -> ${retrieval.candidates.length} candidates` +
|
|
15
|
+
(retrieval.shadow ? ` (shadow: ${retrieval.shadow.candidates.length} unfiltered, k=${retrieval.shadow.top_k})` : " (no shadow)"));
|
|
16
|
+
if (rerank) {
|
|
17
|
+
const kept = rerank.results.filter((r) => r.kept).length;
|
|
18
|
+
lines.push(` rerank ${rerank.model ?? "reranker"}` +
|
|
19
|
+
(rerank.top_n !== undefined ? ` top_n=${rerank.top_n}` : "") +
|
|
20
|
+
(rerank.score_threshold !== undefined ? ` threshold=${rerank.score_threshold}` : "") +
|
|
21
|
+
` -> kept ${kept}/${rerank.results.length}`);
|
|
22
|
+
}
|
|
23
|
+
lines.push(` context included ${context.included.length}, excluded ${context.excluded.length}` +
|
|
24
|
+
(context.token_budget !== undefined ? `, budget ${context.token_budget}` : "") +
|
|
25
|
+
(report.summary.context_tokens_used !== undefined ? `, used ${report.summary.context_tokens_used}` : ""));
|
|
26
|
+
if (trace.generation?.answer_correct !== undefined) {
|
|
27
|
+
lines.push(` generate answer_correct=${trace.generation.answer_correct}`);
|
|
28
|
+
}
|
|
29
|
+
const s = report.summary;
|
|
30
|
+
if (s.shadow_present) {
|
|
31
|
+
lines.push("");
|
|
32
|
+
lines.push(`Shadow diff: filter removed ${s.filter_removed_count}, threshold removed ${s.threshold_removed_count}, top_k cut ${s.topk_cut_count}` +
|
|
33
|
+
(s.rerank_dropped_count !== undefined ? `, reranker dropped ${s.rerank_dropped_count}` : ""));
|
|
34
|
+
}
|
|
35
|
+
lines.push("");
|
|
36
|
+
lines.push("Findings");
|
|
37
|
+
for (const f of report.findings) {
|
|
38
|
+
lines.push(` ${f.primary ? "PRIMARY " : " "}[${f.code}] ${f.message}`);
|
|
39
|
+
lines.push(` next: ${f.next_step}`);
|
|
40
|
+
}
|
|
41
|
+
return lines.join("\n");
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","sourceRoot":"","sources":["../src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CAAC,CAAC,cAAc,EAAE,CAAC;QACrB,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACf,KAAK,CAAC,IAAI,CACR,+BAA+B,CAAC,CAAC,oBAAoB,uBAAuB,CAAC,CAAC,uBAAuB,eAAe,CAAC,CAAC,cAAc,EAAE;YACpI,CAAC,CAAC,CAAC,oBAAoB,KAAK,SAAS,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,oBAAoB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAC/F,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACf,KAAK,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IACvB,KAAK,MAAM,CAAC,IAAI,MAAM,CAAC,QAAQ,EAAE,CAAC;QAChC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,IAAI,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC;QAC/E,KAAK,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC;IAChD,CAAC;IACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { diagnose, labeledChunkIds } from "./diagnose.js";
|
|
2
|
+
export { evaluateFilter, describeClause } from "./filter.js";
|
|
3
|
+
export type { FilterFailure, FilterResult } from "./filter.js";
|
|
4
|
+
export { formatReport } from "./format.js";
|
|
5
|
+
export { traceSchema, validateTrace } from "./schema.js";
|
|
6
|
+
export type { TraceIssue, ValidationResult } from "./schema.js";
|
|
7
|
+
export { ENGINE_VERSION } from "./version.js";
|
|
8
|
+
export type * from "./types.js";
|
|
9
|
+
export { timeline } from "./timeline.js";
|
|
10
|
+
export type { Timeline, TimelineStage, TimelineChunk } from "./timeline.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACzD,YAAY,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAC9C,mBAAmB,YAAY,CAAC;AAChC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,YAAY,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { diagnose, labeledChunkIds } from "./diagnose.js";
|
|
2
|
+
export { evaluateFilter, describeClause } from "./filter.js";
|
|
3
|
+
export { formatReport } from "./format.js";
|
|
4
|
+
export { traceSchema, validateTrace } from "./schema.js";
|
|
5
|
+
export { ENGINE_VERSION } from "./version.js";
|
|
6
|
+
export { timeline } from "./timeline.js";
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC"}
|
package/dist/schema.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { Trace } from "./types.js";
|
|
3
|
+
export declare const traceSchema: z.ZodType<Trace>;
|
|
4
|
+
export type TraceIssue = {
|
|
5
|
+
path: (string | number)[];
|
|
6
|
+
message: string;
|
|
7
|
+
};
|
|
8
|
+
export type ValidationResult = {
|
|
9
|
+
ok: true;
|
|
10
|
+
trace: Trace;
|
|
11
|
+
} | {
|
|
12
|
+
ok: false;
|
|
13
|
+
issues: TraceIssue[];
|
|
14
|
+
};
|
|
15
|
+
/** Validates an unknown value as a Trace. Unknown keys are stripped so stored traces match the schema exactly. */
|
|
16
|
+
export declare function validateTrace(input: unknown): ValidationResult;
|
|
17
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AA4ExC,eAAO,MAAM,WAAW,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,CAWvC,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG;IAAE,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,MAAM,MAAM,gBAAgB,GAAG;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,KAAK,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,UAAU,EAAE,CAAA;CAAE,CAAC;AAEhG,kHAAkH;AAClH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAI9D"}
|
package/dist/schema.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
/** Runtime validator for Trace Schema v0. Mirrors types.ts field for field. */
|
|
3
|
+
const metadataValue = z.union([z.string(), z.number(), z.boolean(), z.null()]);
|
|
4
|
+
const filterClause = z.union([
|
|
5
|
+
z.string(),
|
|
6
|
+
z.number(),
|
|
7
|
+
z.boolean(),
|
|
8
|
+
z.strictObject({ $in: z.array(z.union([z.string(), z.number()])) }),
|
|
9
|
+
z.strictObject({ $ne: z.union([z.string(), z.number(), z.boolean()]) }),
|
|
10
|
+
z.strictObject({ $gt: z.number().optional(), $gte: z.number().optional(), $lt: z.number().optional(), $lte: z.number().optional() }),
|
|
11
|
+
]);
|
|
12
|
+
const label = z.discriminatedUnion("type", [
|
|
13
|
+
z.object({ type: z.literal("keyword"), values: z.array(z.string().min(1)).min(1) }),
|
|
14
|
+
z.object({ type: z.literal("document"), document_ids: z.array(z.string().min(1)).min(1) }),
|
|
15
|
+
z.object({ type: z.literal("chunk"), chunk_ids: z.array(z.string().min(1)).min(1) }),
|
|
16
|
+
]);
|
|
17
|
+
const candidate = z.object({
|
|
18
|
+
chunk_id: z.string().min(1),
|
|
19
|
+
document_id: z.string().optional(),
|
|
20
|
+
rank: z.number().int().positive(),
|
|
21
|
+
score: z.number(),
|
|
22
|
+
token_count: z.number().int().nonnegative().optional(),
|
|
23
|
+
metadata: z.record(z.string(), metadataValue).optional(),
|
|
24
|
+
matches_label: z.boolean().optional(),
|
|
25
|
+
text: z.string().optional(),
|
|
26
|
+
});
|
|
27
|
+
const retrieval = z.object({
|
|
28
|
+
index: z.object({ name: z.string().min(1), provider: z.string().optional() }),
|
|
29
|
+
params: z.object({
|
|
30
|
+
top_k: z.number().int().positive(),
|
|
31
|
+
similarity_threshold: z.number().optional(),
|
|
32
|
+
metadata_filter: z.record(z.string(), filterClause).optional(),
|
|
33
|
+
}),
|
|
34
|
+
candidates: z.array(candidate),
|
|
35
|
+
shadow: z.object({ top_k: z.number().int().positive(), candidates: z.array(candidate) }).optional(),
|
|
36
|
+
});
|
|
37
|
+
const rerank = z.object({
|
|
38
|
+
model: z.string().optional(),
|
|
39
|
+
top_n: z.number().int().positive().optional(),
|
|
40
|
+
score_threshold: z.number().optional(),
|
|
41
|
+
results: z.array(z.object({
|
|
42
|
+
chunk_id: z.string().min(1),
|
|
43
|
+
rank_before: z.number().int().positive(),
|
|
44
|
+
rank_after: z.number().int().positive(),
|
|
45
|
+
score: z.number(),
|
|
46
|
+
kept: z.boolean(),
|
|
47
|
+
})),
|
|
48
|
+
});
|
|
49
|
+
const context = z.object({
|
|
50
|
+
token_budget: z.number().int().nonnegative().optional(),
|
|
51
|
+
included: z.array(z.object({ chunk_id: z.string().min(1), order: z.number().int().positive(), token_count: z.number().int().nonnegative().optional() })),
|
|
52
|
+
excluded: z.array(z.object({
|
|
53
|
+
chunk_id: z.string().min(1),
|
|
54
|
+
reason: z.enum(["token_budget", "dedupe", "max_chunks", "custom"]),
|
|
55
|
+
detail: z.string().optional(),
|
|
56
|
+
})),
|
|
57
|
+
});
|
|
58
|
+
const generation = z.object({
|
|
59
|
+
model: z.string().optional(),
|
|
60
|
+
answer: z.string().optional(),
|
|
61
|
+
answer_correct: z.boolean().optional(),
|
|
62
|
+
});
|
|
63
|
+
export const traceSchema = z.object({
|
|
64
|
+
schema_version: z.literal("0"),
|
|
65
|
+
trace_id: z.string().min(1).max(256),
|
|
66
|
+
timestamp: z.iso.datetime({ offset: true }),
|
|
67
|
+
app: z.object({ name: z.string().optional(), env: z.string().optional(), version: z.string().optional() }).optional(),
|
|
68
|
+
query: z.object({ text: z.string() }),
|
|
69
|
+
label: label.optional(),
|
|
70
|
+
retrieval,
|
|
71
|
+
rerank: rerank.optional(),
|
|
72
|
+
context,
|
|
73
|
+
generation: generation.optional(),
|
|
74
|
+
});
|
|
75
|
+
/** Validates an unknown value as a Trace. Unknown keys are stripped so stored traces match the schema exactly. */
|
|
76
|
+
export function validateTrace(input) {
|
|
77
|
+
const r = traceSchema.safeParse(input);
|
|
78
|
+
if (r.success)
|
|
79
|
+
return { ok: true, trace: r.data };
|
|
80
|
+
return { ok: false, issues: r.error.issues.map((i) => ({ path: i.path.map((p) => (typeof p === "symbol" ? String(p) : p)), message: i.message })) };
|
|
81
|
+
}
|
|
82
|
+
//# sourceMappingURL=schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,+EAA+E;AAE/E,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC;AAE/E,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC;IAC3B,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,OAAO,EAAE;IACX,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACnE,CAAC,CAAC,YAAY,CAAC,EAAE,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE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AC,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC;IACrC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE;IACvB,SAAS;IACT,MAAM,EAAE,MAAM,CAAC,QAAQ,EAAE;IACzB,OAAO;IACP,UAAU,EAAE,UAAU,CAAC,QAAQ,EAAE;CAClC,CAAC,CAAC;AAMH,kHAAkH;AAClH,MAAM,UAAU,aAAa,CAAC,KAAc;IAC1C,MAAM,CAAC,GAAG,WAAW,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACvC,IAAI,CAAC,CAAC,OAAO;QAAE,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC;AACtJ,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { DiagnosisReport, FindingCode, Stage, Trace } from "./types.js";
|
|
2
|
+
/**
|
|
3
|
+
* A stage-by-stage view of one trace for the timeline UI and the CLI. Pure function of
|
|
4
|
+
* the trace and its report: every number here is a count over trace fields, and every
|
|
5
|
+
* dropped chunk carries the field values that explain the drop.
|
|
6
|
+
*/
|
|
7
|
+
export type TimelineChunk = {
|
|
8
|
+
chunk_id: string;
|
|
9
|
+
document_id?: string;
|
|
10
|
+
/** True when this chunk is in the labeled (expected evidence) set. */
|
|
11
|
+
labeled: boolean;
|
|
12
|
+
score?: number;
|
|
13
|
+
rank?: number;
|
|
14
|
+
/** Why it left at this stage (only on `dropped`). */
|
|
15
|
+
reason?: string;
|
|
16
|
+
};
|
|
17
|
+
export type TimelineStage = {
|
|
18
|
+
stage: Exclude<Stage, "meta">;
|
|
19
|
+
/** Short human label, e.g. "filter tenant=\"acme\"". */
|
|
20
|
+
label: string;
|
|
21
|
+
/** False when the trace lacks the data to observe this stage (no shadow query). */
|
|
22
|
+
observable: boolean;
|
|
23
|
+
in: number;
|
|
24
|
+
out: number;
|
|
25
|
+
kept: TimelineChunk[];
|
|
26
|
+
dropped: TimelineChunk[];
|
|
27
|
+
/** Codes of findings the rule engine attached to this stage. */
|
|
28
|
+
findings: FindingCode[];
|
|
29
|
+
};
|
|
30
|
+
export type Timeline = {
|
|
31
|
+
trace_id: string;
|
|
32
|
+
labeled_chunk_ids: string[];
|
|
33
|
+
primary: {
|
|
34
|
+
code: FindingCode;
|
|
35
|
+
stage: Stage;
|
|
36
|
+
chunk_ids: string[];
|
|
37
|
+
message: string;
|
|
38
|
+
} | null;
|
|
39
|
+
stages: TimelineStage[];
|
|
40
|
+
};
|
|
41
|
+
export declare function timeline(trace: Trace, report: DiagnosisReport): Timeline;
|
|
42
|
+
//# sourceMappingURL=timeline.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.d.ts","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,eAAe,EAAE,WAAW,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAIxF;;;;GAIG;AAEH,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC9B,wDAAwD;IACxD,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,UAAU,EAAE,OAAO,CAAC;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,aAAa,EAAE,CAAC;IACtB,OAAO,EAAE,aAAa,EAAE,CAAC;IACzB,gEAAgE;IAChE,QAAQ,EAAE,WAAW,EAAE,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,QAAQ,GAAG;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,OAAO,EAAE;QAAE,IAAI,EAAE,WAAW,CAAC;QAAC,KAAK,EAAE,KAAK,CAAC;QAAC,SAAS,EAAE,MAAM,EAAE,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1F,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,eAAe,GAAG,QAAQ,CAqJxE"}
|
package/dist/timeline.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { evaluateFilter, describeClause } from "./filter.js";
|
|
2
|
+
import { labeledChunkIds } from "./diagnose.js";
|
|
3
|
+
export function timeline(trace, report) {
|
|
4
|
+
const labeled = labeledChunkIds(trace);
|
|
5
|
+
const { retrieval, rerank, context, generation } = trace;
|
|
6
|
+
const { params, candidates, shadow } = retrieval;
|
|
7
|
+
const isLabeled = (id) => labeled.has(id);
|
|
8
|
+
const findingsAt = (stage) => report.findings.filter((f) => f.stage === stage).map((f) => f.code);
|
|
9
|
+
const chunk = (c, reason) => ({
|
|
10
|
+
chunk_id: c.chunk_id,
|
|
11
|
+
...(c.document_id ? { document_id: c.document_id } : {}),
|
|
12
|
+
labeled: isLabeled(c.chunk_id),
|
|
13
|
+
score: c.score,
|
|
14
|
+
rank: c.rank,
|
|
15
|
+
...(reason ? { reason } : {}),
|
|
16
|
+
});
|
|
17
|
+
const stages = [];
|
|
18
|
+
/* index: the unfiltered pool the vector store can see (shadow), or the returned set when no shadow. */
|
|
19
|
+
const pool = shadow ? [...shadow.candidates].sort((a, b) => a.rank - b.rank) : [...candidates].sort((a, b) => a.rank - b.rank);
|
|
20
|
+
const poolIds = new Set(pool.map((c) => c.chunk_id));
|
|
21
|
+
const notInPool = [...labeled].filter((id) => !poolIds.has(id)).map((id) => ({ chunk_id: id, labeled: true, reason: "not in the retrievable set" }));
|
|
22
|
+
stages.push({
|
|
23
|
+
stage: "index",
|
|
24
|
+
label: shadow ? `index ${retrieval.index.name}, shadow k=${shadow.top_k}` : `index ${retrieval.index.name} (no shadow query)`,
|
|
25
|
+
observable: true,
|
|
26
|
+
in: pool.length + notInPool.length,
|
|
27
|
+
out: pool.length,
|
|
28
|
+
kept: pool.map((c) => chunk(c)),
|
|
29
|
+
dropped: notInPool,
|
|
30
|
+
findings: findingsAt("index"),
|
|
31
|
+
});
|
|
32
|
+
/* filter → threshold → top_k, observable only with a shadow query. */
|
|
33
|
+
let current = pool;
|
|
34
|
+
const filterLabel = params.metadata_filter
|
|
35
|
+
? Object.entries(params.metadata_filter)
|
|
36
|
+
.map(([k, v]) => `${k} ${describeClause(v)}`)
|
|
37
|
+
.join(", ")
|
|
38
|
+
: "none";
|
|
39
|
+
if (shadow) {
|
|
40
|
+
const keptF = [];
|
|
41
|
+
const droppedF = [];
|
|
42
|
+
for (const c of current) {
|
|
43
|
+
const r = evaluateFilter(params.metadata_filter, c.metadata);
|
|
44
|
+
if (r.passes)
|
|
45
|
+
keptF.push(c);
|
|
46
|
+
else
|
|
47
|
+
droppedF.push(chunk(c, r.failures.map((f) => `${f.key} is ${JSON.stringify(f.actual ?? null)}, needs ${describeClause(f.expected)}`).join("; ")));
|
|
48
|
+
}
|
|
49
|
+
stages.push(stageOf("filter", `filter ${filterLabel}`, current, keptF, droppedF, findingsAt("filter")));
|
|
50
|
+
current = keptF;
|
|
51
|
+
const keptT = [];
|
|
52
|
+
const droppedT = [];
|
|
53
|
+
for (const c of current) {
|
|
54
|
+
if (params.similarity_threshold !== undefined && c.score < params.similarity_threshold)
|
|
55
|
+
droppedT.push(chunk(c, `score ${c.score} < ${params.similarity_threshold}`));
|
|
56
|
+
else
|
|
57
|
+
keptT.push(c);
|
|
58
|
+
}
|
|
59
|
+
stages.push(stageOf("threshold", params.similarity_threshold !== undefined ? `threshold ≥ ${params.similarity_threshold}` : "threshold none", current, keptT, droppedT, findingsAt("threshold")));
|
|
60
|
+
current = keptT;
|
|
61
|
+
const eligible = [...current].sort((a, b) => b.score - a.score || a.rank - b.rank);
|
|
62
|
+
const keptK = [];
|
|
63
|
+
const droppedK = [];
|
|
64
|
+
eligible.forEach((c, i) => {
|
|
65
|
+
const effRank = i + 1;
|
|
66
|
+
if (effRank > params.top_k)
|
|
67
|
+
droppedK.push({ ...chunk(c, `eligible rank ${effRank} > top_k ${params.top_k}`), rank: effRank });
|
|
68
|
+
else
|
|
69
|
+
keptK.push({ ...c, rank: effRank });
|
|
70
|
+
});
|
|
71
|
+
stages.push(stageOf("top_k", `top_k ${params.top_k}`, eligible, keptK, droppedK, findingsAt("top_k")));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
for (const [stage, label] of [
|
|
75
|
+
["filter", `filter ${filterLabel}`],
|
|
76
|
+
["threshold", params.similarity_threshold !== undefined ? `threshold ≥ ${params.similarity_threshold}` : "threshold none"],
|
|
77
|
+
["top_k", `top_k ${params.top_k}`],
|
|
78
|
+
]) {
|
|
79
|
+
stages.push({ stage, label, observable: false, in: 0, out: 0, kept: [], dropped: [], findings: findingsAt(stage) });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/* rerank: over what the store actually returned. */
|
|
83
|
+
const returned = [...candidates].sort((a, b) => a.rank - b.rank);
|
|
84
|
+
let afterRerank = returned.map((c) => chunk(c));
|
|
85
|
+
if (rerank) {
|
|
86
|
+
const byId = new Map(returned.map((c) => [c.chunk_id, c]));
|
|
87
|
+
const kept = [];
|
|
88
|
+
const dropped = [];
|
|
89
|
+
for (const r of [...rerank.results].sort((a, b) => a.rank_after - b.rank_after)) {
|
|
90
|
+
const base = byId.get(r.chunk_id);
|
|
91
|
+
const entry = { chunk_id: r.chunk_id, ...(base?.document_id ? { document_id: base.document_id } : {}), labeled: isLabeled(r.chunk_id), score: r.score, rank: r.rank_after };
|
|
92
|
+
if (r.kept)
|
|
93
|
+
kept.push(entry);
|
|
94
|
+
else {
|
|
95
|
+
const rule = rerank.top_n !== undefined && r.rank_after > rerank.top_n ? `rank ${r.rank_after} > top_n ${rerank.top_n}` : rerank.score_threshold !== undefined ? `score ${r.score} < ${rerank.score_threshold}` : "not kept by the reranker";
|
|
96
|
+
dropped.push({ ...entry, reason: `moved ${r.rank_before} → ${r.rank_after}; ${rule}` });
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
const label = `rerank ${rerank.model ?? ""}${rerank.top_n !== undefined ? ` top_n ${rerank.top_n}` : ""}${rerank.score_threshold !== undefined ? ` threshold ${rerank.score_threshold}` : ""}`.replace(/\s+/g, " ").trim();
|
|
100
|
+
stages.push({ stage: "rerank", label, observable: true, in: rerank.results.length, out: kept.length, kept, dropped, findings: findingsAt("rerank") });
|
|
101
|
+
afterRerank = kept;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
stages.push({ stage: "rerank", label: "rerank none", observable: true, in: returned.length, out: returned.length, kept: afterRerank, dropped: [], findings: findingsAt("rerank") });
|
|
105
|
+
}
|
|
106
|
+
/* context */
|
|
107
|
+
const inContext = [...context.included].sort((a, b) => a.order - b.order);
|
|
108
|
+
const byIdAll = new Map([...pool, ...returned].map((c) => [c.chunk_id, c]));
|
|
109
|
+
const docOf = (id) => byIdAll.get(id)?.document_id;
|
|
110
|
+
const keptC = inContext.map((c) => ({ chunk_id: c.chunk_id, ...(docOf(c.chunk_id) ? { document_id: docOf(c.chunk_id) } : {}), labeled: isLabeled(c.chunk_id), rank: c.order, ...(c.token_count !== undefined ? { score: c.token_count } : {}) }));
|
|
111
|
+
const droppedC = context.excluded.map((e) => ({
|
|
112
|
+
chunk_id: e.chunk_id,
|
|
113
|
+
...(docOf(e.chunk_id) ? { document_id: docOf(e.chunk_id) } : {}),
|
|
114
|
+
labeled: isLabeled(e.chunk_id),
|
|
115
|
+
reason: e.detail ? `${e.reason}: ${e.detail}` : e.reason,
|
|
116
|
+
}));
|
|
117
|
+
const used = report.summary.context_tokens_used;
|
|
118
|
+
stages.push({
|
|
119
|
+
stage: "context",
|
|
120
|
+
label: `context${context.token_budget !== undefined ? ` budget ${context.token_budget}` : ""}${used !== undefined ? `, used ${used}` : ""}`,
|
|
121
|
+
observable: true,
|
|
122
|
+
in: afterRerank.length,
|
|
123
|
+
out: keptC.length,
|
|
124
|
+
kept: keptC,
|
|
125
|
+
dropped: droppedC,
|
|
126
|
+
findings: findingsAt("context"),
|
|
127
|
+
});
|
|
128
|
+
/* generation: not a filter, but when the answer is wrong with evidence in the prompt, that is where the labeled chunk was lost. */
|
|
129
|
+
const wrong = generation?.answer_correct === false;
|
|
130
|
+
const droppedG = wrong ? keptC.filter((c) => c.labeled).map((c) => ({ ...c, reason: "evidence was in the prompt but the answer was wrong" })) : [];
|
|
131
|
+
const keptG = keptC.filter((c) => !droppedG.some((d) => d.chunk_id === c.chunk_id));
|
|
132
|
+
stages.push({
|
|
133
|
+
stage: "generation",
|
|
134
|
+
label: generation ? `generate ${generation.model ?? ""}${generation.answer_correct !== undefined ? ` answer_correct=${generation.answer_correct}` : ""}`.replace(/\s+/g, " ").trim() : "generate (not recorded)",
|
|
135
|
+
observable: !!generation,
|
|
136
|
+
in: keptC.length,
|
|
137
|
+
out: keptG.length,
|
|
138
|
+
kept: keptG,
|
|
139
|
+
dropped: droppedG,
|
|
140
|
+
findings: findingsAt("generation"),
|
|
141
|
+
});
|
|
142
|
+
const primary = report.findings.find((f) => f.primary);
|
|
143
|
+
return {
|
|
144
|
+
trace_id: trace.trace_id,
|
|
145
|
+
labeled_chunk_ids: [...labeled],
|
|
146
|
+
primary: primary ? { code: primary.code, stage: primary.stage, chunk_ids: primary.chunk_ids, message: primary.message } : null,
|
|
147
|
+
stages,
|
|
148
|
+
};
|
|
149
|
+
function stageOf(stage, label, input, kept, dropped, findings) {
|
|
150
|
+
return { stage, label, observable: true, in: input.length, out: kept.length, kept: kept.map((c) => chunk(c)), dropped, findings };
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=timeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline.js","sourceRoot":"","sources":["../src/timeline.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAwChD,MAAM,UAAU,QAAQ,CAAC,KAAY,EAAE,MAAuB;IAC5D,MAAM,OAAO,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;IACvC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,KAAK,CAAC;IACzD,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IACjD,MAAM,SAAS,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAClD,MAAM,UAAU,GAAG,CAAC,KAAY,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,K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AE,EAAE,KAAK,CAAC,MAAM;QAChB,GAAG,EAAE,KAAK,CAAC,MAAM;QACjB,IAAI,EAAE,KAAK;QACX,OAAO,EAAE,QAAQ;QACjB,QAAQ,EAAE,UAAU,CAAC,YAAY,CAAC;KACnC,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;IACvD,OAAO;QACL,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,iBAAiB,EAAE,CAAC,GAAG,OAAO,CAAC;QAC/B,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI;QAC9H,MAAM;KACP,CAAC;IAEF,SAAS,OAAO,CAAC,KAA6B,EAAE,KAAa,EAAE,KAAkB,EAAE,IAAiB,EAAE,OAAwB,EAAE,QAAuB;QACrJ,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC;IACpI,CAAC;AACH,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
/** Trace Schema v0. One trace = one query. See "Trace Schema v0 and Diagnostic Rules". */
|
|
2
|
+
export type Trace = {
|
|
3
|
+
schema_version: "0";
|
|
4
|
+
trace_id: string;
|
|
5
|
+
timestamp: string;
|
|
6
|
+
app?: {
|
|
7
|
+
name?: string;
|
|
8
|
+
env?: string;
|
|
9
|
+
version?: string;
|
|
10
|
+
};
|
|
11
|
+
query: {
|
|
12
|
+
text: string;
|
|
13
|
+
};
|
|
14
|
+
label?: Label;
|
|
15
|
+
retrieval: Retrieval;
|
|
16
|
+
rerank?: Rerank;
|
|
17
|
+
context: Context;
|
|
18
|
+
generation?: Generation;
|
|
19
|
+
};
|
|
20
|
+
export type Label = {
|
|
21
|
+
type: "keyword";
|
|
22
|
+
values: string[];
|
|
23
|
+
} | {
|
|
24
|
+
type: "document";
|
|
25
|
+
document_ids: string[];
|
|
26
|
+
} | {
|
|
27
|
+
type: "chunk";
|
|
28
|
+
chunk_ids: string[];
|
|
29
|
+
};
|
|
30
|
+
export type MetadataValue = string | number | boolean | null;
|
|
31
|
+
export type Candidate = {
|
|
32
|
+
chunk_id: string;
|
|
33
|
+
document_id?: string;
|
|
34
|
+
rank: number;
|
|
35
|
+
score: number;
|
|
36
|
+
token_count?: number;
|
|
37
|
+
metadata?: Record<string, MetadataValue>;
|
|
38
|
+
matches_label?: boolean;
|
|
39
|
+
text?: string;
|
|
40
|
+
};
|
|
41
|
+
export type Retrieval = {
|
|
42
|
+
index: {
|
|
43
|
+
name: string;
|
|
44
|
+
provider?: string;
|
|
45
|
+
};
|
|
46
|
+
params: {
|
|
47
|
+
top_k: number;
|
|
48
|
+
similarity_threshold?: number;
|
|
49
|
+
metadata_filter?: MetadataFilter;
|
|
50
|
+
};
|
|
51
|
+
candidates: Candidate[];
|
|
52
|
+
shadow?: {
|
|
53
|
+
top_k: number;
|
|
54
|
+
candidates: Candidate[];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
export type FilterClause = string | number | boolean | {
|
|
58
|
+
$in: (string | number)[];
|
|
59
|
+
} | {
|
|
60
|
+
$ne: string | number | boolean;
|
|
61
|
+
} | {
|
|
62
|
+
$gt?: number;
|
|
63
|
+
$gte?: number;
|
|
64
|
+
$lt?: number;
|
|
65
|
+
$lte?: number;
|
|
66
|
+
};
|
|
67
|
+
export type MetadataFilter = Record<string, FilterClause>;
|
|
68
|
+
export type Rerank = {
|
|
69
|
+
model?: string;
|
|
70
|
+
top_n?: number;
|
|
71
|
+
score_threshold?: number;
|
|
72
|
+
results: Array<{
|
|
73
|
+
chunk_id: string;
|
|
74
|
+
rank_before: number;
|
|
75
|
+
rank_after: number;
|
|
76
|
+
score: number;
|
|
77
|
+
kept: boolean;
|
|
78
|
+
}>;
|
|
79
|
+
};
|
|
80
|
+
export type Context = {
|
|
81
|
+
token_budget?: number;
|
|
82
|
+
included: Array<{
|
|
83
|
+
chunk_id: string;
|
|
84
|
+
order: number;
|
|
85
|
+
token_count?: number;
|
|
86
|
+
}>;
|
|
87
|
+
excluded: Array<{
|
|
88
|
+
chunk_id: string;
|
|
89
|
+
reason: "token_budget" | "dedupe" | "max_chunks" | "custom";
|
|
90
|
+
detail?: string;
|
|
91
|
+
}>;
|
|
92
|
+
};
|
|
93
|
+
export type Generation = {
|
|
94
|
+
model?: string;
|
|
95
|
+
answer?: string;
|
|
96
|
+
answer_correct?: boolean;
|
|
97
|
+
};
|
|
98
|
+
export type Stage = "index" | "filter" | "threshold" | "top_k" | "rerank" | "context" | "generation" | "meta";
|
|
99
|
+
export type FindingCode = "NOT_RETRIEVABLE" | "FILTER_REMOVED" | "THRESHOLD_REMOVED" | "TOPK_CUT" | "UNEXPLAINED_EXCLUSION" | "RERANK_DROPPED" | "CONTEXT_DROPPED" | "EVIDENCE_IN_CONTEXT" | "NO_LABEL" | "SHADOW_MISSING";
|
|
100
|
+
export type Finding = {
|
|
101
|
+
code: FindingCode;
|
|
102
|
+
stage: Stage;
|
|
103
|
+
primary: boolean;
|
|
104
|
+
chunk_ids: string[];
|
|
105
|
+
message: string;
|
|
106
|
+
evidence: Record<string, unknown>;
|
|
107
|
+
next_step: string;
|
|
108
|
+
};
|
|
109
|
+
/** Label-independent counts, always reported when observable. */
|
|
110
|
+
export type Summary = {
|
|
111
|
+
labeled_chunk_ids: string[];
|
|
112
|
+
shadow_present: boolean;
|
|
113
|
+
filter_removed_count?: number;
|
|
114
|
+
threshold_removed_count?: number;
|
|
115
|
+
topk_cut_count?: number;
|
|
116
|
+
rerank_dropped_count?: number;
|
|
117
|
+
context_included_count: number;
|
|
118
|
+
context_excluded_count: number;
|
|
119
|
+
context_tokens_used?: number;
|
|
120
|
+
context_token_budget?: number;
|
|
121
|
+
};
|
|
122
|
+
export type DiagnosisReport = {
|
|
123
|
+
trace_id: string;
|
|
124
|
+
findings: Finding[];
|
|
125
|
+
summary: Summary;
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,MAAM,MAAM,KAAK,GAAG;IAClB,cAAc,EAAE,GAAG,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;IAClB,GAAG,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,OAAO,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,OAAO,CAAC;IACjB,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,KAAK,GACb;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GACrC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,YAAY,EAAE,MAAM,EAAE,CAAA;CAAE,GAC5C;IAAE,IAAI,E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,GAChB,iBAAiB,GACjB,qBAAqB,GACrB,UAAU,GACV,gBAAgB,CAAC;AAErB,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,WAAW,CAAC;IAClB,KAAK,EAAE,KAAK,CAAC;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,iEAAiE;AACjE,MAAM,MAAM,OAAO,GAAG;IACpB,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,cAAc,EAAE,OAAO,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,sBAAsB,EAAE,MAAM,CAAC;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,0FAA0F"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version of the diagnostic rule set. Bump when a change to diagnose.ts or filter.ts
|
|
3
|
+
* can alter a finding for an unchanged trace, so stored diagnoses can be told apart
|
|
4
|
+
* from fresh ones. `scripts/release.mjs` does this automatically when those files changed.
|
|
5
|
+
*/
|
|
6
|
+
export declare const ENGINE_VERSION = 1;
|
|
7
|
+
//# sourceMappingURL=version.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,cAAc,IAAI,CAAC"}
|
package/dist/version.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version of the diagnostic rule set. Bump when a change to diagnose.ts or filter.ts
|
|
3
|
+
* can alter a finding for an unchanged trace, so stored diagnoses can be told apart
|
|
4
|
+
* from fresh ones. `scripts/release.mjs` does this automatically when those files changed.
|
|
5
|
+
*/
|
|
6
|
+
export const ENGINE_VERSION = 1;
|
|
7
|
+
//# sourceMappingURL=version.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chunktrace/core",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.9.0",
|
|
4
|
+
"description": "Trace Schema v0, the deterministic diagnostic rule engine and the text report.",
|
|
5
|
+
"author": "Hathor Software, LLC",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/chunktrace/chunktrace.git",
|
|
9
|
+
"directory": "packages/core"
|
|
10
|
+
},
|
|
11
|
+
"homepage": "https://chunktrace.com/docs/",
|
|
12
|
+
"type": "module",
|
|
13
|
+
"main": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts",
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"bin": {
|
|
22
|
+
"chunktrace": "dist/cli.js"
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"zod": "^4.6.7"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public"
|
|
32
|
+
},
|
|
33
|
+
"license": "MIT"
|
|
34
|
+
}
|