pi-mega-compact 0.21.9 → 0.21.11
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/dedup/degenerate.js +68 -0
- package/dist/extensions/dashboard-server/routes-dedup-attribution.js +8 -1
- package/dist/extensions/dashboard-server/routes-rag-settings-helpers.js +3 -0
- package/dist/extensions/mega-events/context-handler/headroom.js +58 -3
- package/dist/extensions/mega-events/context-handler/liveTrim.js +6 -2
- package/dist/extensions/mega-events/context-handler.js +7 -1
- package/dist/extensions/mega-pipeline/compact/run.js +14 -3
- package/dist/src/config/dedup.js +3 -0
- package/dist/src/dedup/degenerate.js +68 -0
- package/dist/src/extractive-salvage.js +195 -0
- package/dist/src/extractive.js +63 -72
- package/dist/src/vector-cortex/dedup-attr/rollup.js +5 -0
- package/dist/src/vectorStore/add-degenerate.js +25 -0
- package/dist/src/vectorStore/add.js +28 -5
- package/dist/src/vectorStore/dedup-audit.js +8 -0
- package/dist/vector-cortex/dedup-attr/rollup.js +5 -0
- package/dist/vectorStore/dedup-audit.js +8 -0
- package/extensions/dashboard-server/routes-dedup-attribution.ts +11 -1
- package/extensions/dashboard-server/routes-rag-settings-helpers.ts +8 -0
- package/extensions/mega-events/context-handler/headroom.ts +50 -3
- package/extensions/mega-events/context-handler/liveTrim.ts +6 -2
- package/extensions/mega-events/context-handler.ts +7 -1
- package/extensions/mega-pipeline/compact/run.ts +14 -4
- package/package.json +1 -1
- package/src/config/dedup.ts +15 -0
- package/src/dedup/degenerate.ts +125 -0
- package/src/extractive-salvage.ts +212 -0
- package/src/extractive.ts +70 -75
- package/src/vector-cortex/dedup-attr/rollup.ts +4 -0
- package/src/vectorStore/add-degenerate.ts +64 -0
- package/src/vectorStore/add.ts +29 -5
- package/src/vectorStore/dedup-audit.ts +25 -2
package/src/vectorStore/add.ts
CHANGED
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
bumpDedupStats,
|
|
39
39
|
} from "../store/sqlite.js";
|
|
40
40
|
import { computeRegionHash } from "./hash.js";
|
|
41
|
+
import { degenerateDecliner } from "./add-degenerate.js";
|
|
41
42
|
import { runL0Tier, computeSummaryHash } from "./add-l0.js";
|
|
42
43
|
import { findL1Duplicate } from "./add-l1.js";
|
|
43
44
|
import { dedupAuditRecorder } from "./dedup-audit.js";
|
|
@@ -86,9 +87,23 @@ export function addCheckpoint(store: VectorStore, input: AddInput): AddResult {
|
|
|
86
87
|
// Tracks whether a tier matched while in MARK_ONLY (record-but-don't-collapse),
|
|
87
88
|
// and which tier.
|
|
88
89
|
let markOnly: "L0" | "L1" | "L2" | null = null;
|
|
90
|
+
// Content digest for this candidate (also consumed by the L0 tier below).
|
|
91
|
+
const digest = computeContentDigest(input.regionText);
|
|
92
|
+
// Degenerate-match guard (incident 2026-08-19): declines a fuzzy-tier collapse
|
|
93
|
+
// onto a content-free skeleton when the incoming region is richer, so the
|
|
94
|
+
// skeleton stops absorbing every future compaction. Returns true (having
|
|
95
|
+
// already recorded the decision) ⇒ the caller treats the match as a non-match.
|
|
96
|
+
// Flag-off ⇒ always false ⇒ byte-identical predecessor. See add-degenerate.ts.
|
|
97
|
+
const declineDegenerate = degenerateDecliner({
|
|
98
|
+
store,
|
|
99
|
+
input,
|
|
100
|
+
contentHash: digest.contentHash,
|
|
101
|
+
cfg,
|
|
102
|
+
audit,
|
|
103
|
+
t0,
|
|
104
|
+
});
|
|
89
105
|
|
|
90
106
|
// L0 exact-match tier (contentHash / regionHash / summaryHash) — see add-l0.ts.
|
|
91
|
-
const digest = computeContentDigest(input.regionText);
|
|
92
107
|
const bloom = openBloom(store.stateDir);
|
|
93
108
|
const summaryHash = computeSummaryHash(input.topicSummary);
|
|
94
109
|
const l0 = runL0Tier({
|
|
@@ -113,7 +128,10 @@ export function addCheckpoint(store: VectorStore, input: AddInput): AddResult {
|
|
|
113
128
|
onTier?.({ tier: "L1", status: "scanning" });
|
|
114
129
|
if (cfg.L1_ENABLED) {
|
|
115
130
|
const l1 = findL1Duplicate(store, sessionId, input.regionText, all);
|
|
116
|
-
|
|
131
|
+
// Guard first: a declined match must not collapse and must not be recorded
|
|
132
|
+
// as a MARK_ONLY hit either — it is a non-match for the rest of the cascade.
|
|
133
|
+
const l1Declined = l1 !== undefined && declineDegenerate("L1", l1);
|
|
134
|
+
if (l1 && !l1Declined && !cfg.MARK_ONLY_L1) {
|
|
117
135
|
l1.timestamp = input.timestamp;
|
|
118
136
|
upsertCheckpoint(l1, store.stateDir);
|
|
119
137
|
bumpDedupStats(true, store.stateDir);
|
|
@@ -124,7 +142,7 @@ export function addCheckpoint(store: VectorStore, input: AddInput): AddResult {
|
|
|
124
142
|
onTier?.({ tier: "L1", status: "deduped", detail: "l1MinHash" });
|
|
125
143
|
return r;
|
|
126
144
|
}
|
|
127
|
-
if (l1 && cfg.MARK_ONLY_L1) markOnly = "L1";
|
|
145
|
+
if (l1 && !l1Declined && cfg.MARK_ONLY_L1) markOnly = "L1";
|
|
128
146
|
}
|
|
129
147
|
onTier?.({ tier: "L1", status: "passed" });
|
|
130
148
|
|
|
@@ -152,7 +170,13 @@ export function addCheckpoint(store: VectorStore, input: AddInput): AddResult {
|
|
|
152
170
|
},
|
|
153
171
|
{ checkpoint: all[0], sim: -1 },
|
|
154
172
|
);
|
|
155
|
-
|
|
173
|
+
// A declined match falls through to the "store a fresh checkpoint" path; the
|
|
174
|
+
// guard already audited the decision, so the near-miss emit below is skipped.
|
|
175
|
+
const l2Declined =
|
|
176
|
+
!timedOut &&
|
|
177
|
+
nearest.sim >= simThreshold &&
|
|
178
|
+
declineDegenerate("L2", nearest.checkpoint, nearest.sim);
|
|
179
|
+
if (!timedOut && !l2Declined && nearest.sim >= simThreshold) {
|
|
156
180
|
if (!cfg.MARK_ONLY_L2) {
|
|
157
181
|
// Near-identical — update timestamp on existing checkpoint
|
|
158
182
|
nearest.checkpoint.timestamp = input.timestamp;
|
|
@@ -190,7 +214,7 @@ export function addCheckpoint(store: VectorStore, input: AddInput): AddResult {
|
|
|
190
214
|
// Near-miss: how close did we come to collapsing? Only emitted when the
|
|
191
215
|
// scan actually completed and scored a candidate — a timed-out scan has no
|
|
192
216
|
// honest best to report.
|
|
193
|
-
if (!timedOut && nearest.sim >= 0) {
|
|
217
|
+
if (!timedOut && !l2Declined && nearest.sim >= 0) {
|
|
194
218
|
audit.passed("L2", nearest.checkpoint.checkpointId, nearest.sim);
|
|
195
219
|
}
|
|
196
220
|
}
|
|
@@ -51,8 +51,8 @@ export interface DedupAuditEvent {
|
|
|
51
51
|
sessionId: string;
|
|
52
52
|
/** Which layer produced the decision ("new" = nothing collapsed). */
|
|
53
53
|
tier: "L0" | "L1" | "L2" | "new";
|
|
54
|
-
/** What the layer decided. */
|
|
55
|
-
status: "deduped" | "passed" | "stored";
|
|
54
|
+
/** What the layer decided. `skipped` = matched but policy declined to collapse. */
|
|
55
|
+
status: "deduped" | "passed" | "stored" | "skipped";
|
|
56
56
|
/** Checkpoint the region collapsed onto, or the nearest one scored. */
|
|
57
57
|
matchedEntry?: string;
|
|
58
58
|
/** Checkpoint created, when the outcome was a new write. */
|
|
@@ -129,6 +129,20 @@ export interface DedupAuditRecorder {
|
|
|
129
129
|
matchedEntry: string,
|
|
130
130
|
similarity: number,
|
|
131
131
|
): void;
|
|
132
|
+
/**
|
|
133
|
+
* A tier MATCHED but policy declined the collapse (degenerate-match guard).
|
|
134
|
+
*
|
|
135
|
+
* Distinct from `passed`: the threshold WAS cleared, so this line is how an
|
|
136
|
+
* operator sees that a skeleton checkpoint was prevented from absorbing richer
|
|
137
|
+
* content — the signal for "the store is healing". `similarity` is carried only
|
|
138
|
+
* where the tier scored one (L2 does, L1 does not).
|
|
139
|
+
*/
|
|
140
|
+
skipped(
|
|
141
|
+
tier: "L0" | "L1" | "L2",
|
|
142
|
+
matchedEntry: string,
|
|
143
|
+
dedupReason: string,
|
|
144
|
+
similarity?: number,
|
|
145
|
+
): void;
|
|
132
146
|
/** Final outcome: nothing collapsed, a new checkpoint was written. */
|
|
133
147
|
stored(storedEntry: string, dedupReason: string, tokenEstimate: number): void;
|
|
134
148
|
}
|
|
@@ -161,6 +175,15 @@ export function dedupAuditRecorder(
|
|
|
161
175
|
matchedEntry,
|
|
162
176
|
similarity,
|
|
163
177
|
}),
|
|
178
|
+
skipped: (tier, matchedEntry, dedupReason, similarity) =>
|
|
179
|
+
emitDedupAudit(ctx, {
|
|
180
|
+
...base,
|
|
181
|
+
tier,
|
|
182
|
+
status: "skipped",
|
|
183
|
+
matchedEntry,
|
|
184
|
+
dedupReason,
|
|
185
|
+
...(similarity === undefined ? {} : { similarity }),
|
|
186
|
+
}),
|
|
164
187
|
stored: (storedEntry, dedupReason, tokenEstimate) =>
|
|
165
188
|
emitDedupAudit(ctx, {
|
|
166
189
|
...base,
|