@cortexkit/pi-magic-context 0.49.19 → 0.49.20
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/auto-search-worker.js +48 -9
- package/dist/chunk-embedding-write-worker.js +29 -22
- package/dist/{compaction-marker-candidates-wjzqbspm.js → compaction-marker-candidates-fnm47jat.js} +3 -3
- package/dist/compaction-marker-candidates-worker.js +2 -2
- package/dist/compartment-chunk-embedding-81qesfjs.js +64 -0
- package/dist/embedding-backfill-56e871c6.js +24 -0
- package/dist/embedding-worker-process.js +2 -2
- package/dist/embedding-worker.js +5 -5
- package/dist/historian-calibration-extension.js +1 -1
- package/dist/index-54wmg4rj.js +82 -0
- package/dist/{index-xnch62s6.js → index-5n5zxs8e.js} +314 -127
- package/dist/{index-msqrs4nf.js → index-5vgt1zeh.js} +5 -5
- package/dist/{index-qpq6w67c.js → index-6kb2xpw7.js} +2 -2
- package/dist/{index-58mj0dzc.js → index-af9t637y.js} +68 -16
- package/dist/{index-z2rkv0mb.js → index-b8am7tns.js} +4 -4
- package/dist/{index-rhprywn6.js → index-bttctq07.js} +23 -5
- package/dist/{index-e1rza8gp.js → index-dzem6gn9.js} +1 -1
- package/dist/{index-2mmy81qt.js → index-e19qtjj0.js} +468 -18
- package/dist/{index-7bqrfyny.js → index-fgs78jyd.js} +12 -15
- package/dist/{index-d4dt19md.js → index-hqw0rt9k.js} +1 -1
- package/dist/{index-rrwv9y2k.js → index-hws5f0z9.js} +1 -1
- package/dist/{index-f18ec69t.js → index-jn44h81p.js} +1 -1
- package/dist/{index-ek9zvs4f.js → index-jt0g3hn0.js} +37 -25
- package/dist/{index-d8gc0112.js → index-jxjr7kz9.js} +3 -3
- package/dist/{index-rc1dez8m.js → index-kqb3d8bs.js} +9 -5
- package/dist/{index-sqt2haap.js → index-mtvvhcw4.js} +10 -10
- package/dist/{index-1kcfwk9c.js → index-my0dn413.js} +1 -1
- package/dist/{index-apgwdby5.js → index-n4wyxcgr.js} +1 -1
- package/dist/{index-g7p75667.js → index-p63nwn5v.js} +2 -2
- package/dist/{index-svgkv4g2.js → index-qerzchrs.js} +2 -2
- package/dist/{index-vktahpdj.js → index-rfyvax95.js} +9 -3
- package/dist/{index-yygsh681.js → index-rgfb753z.js} +3 -3
- package/dist/{index-dtp1efvf.js → index-tb3d9trm.js} +2 -2
- package/dist/{index-vmcgew7x.js → index-v2epyzbm.js} +75 -57
- package/dist/{index-ym6nh2gk.js → index-vdy273xw.js} +107 -20
- package/dist/{index-jrap43gc.js → index-w1avzkdt.js} +1 -1
- package/dist/{index-wveb51es.js → index-zhwwp8zz.js} +63 -8
- package/dist/index.js +978 -235
- package/dist/{logger-dygt96rn.js → logger-shetp43v.js} +1 -1
- package/dist/{message-fts-rowid-map-cvpy2dmb.js → message-fts-rowid-map-bpexnsdj.js} +6 -5
- package/dist/{message-index-bounded-66saeq5j.js → message-index-bounded-d4r3weh0.js} +14 -13
- package/dist/{message-index-rc2x41k4.js → message-index-mvag9crh.js} +14 -13
- package/dist/{message-time-backfill-ssshbdy8.js → message-time-backfill-kc10yrcj.js} +3 -3
- package/dist/migration-worker.js +12 -11
- package/dist/{project-embedding-registry-vf1ncptn.js → project-embedding-registry-cfrg952x.js} +13 -12
- package/dist/raw-ordinal-warmup-worker.js +136 -101
- package/dist/{read-session-chunk-h5bzj91r.js → read-session-chunk-7g4zvpd8.js} +9 -8
- package/dist/{read-session-raw-9s3xn7fc.js → read-session-raw-0fsjh10f.js} +4 -3
- package/dist/{safe-notification-target-2rkvkmw8.js → safe-notification-target-zcpchea6.js} +2 -2
- package/dist/search-archive-qbhp7e89.js +21 -0
- package/dist/{search-wh7b9zht.js → search-hp4g3g9v.js} +22 -21
- package/dist/{sqlite-fsp0sf3r.js → sqlite-d67n6dtr.js} +1 -1
- package/dist/{storage-memory-yxxc5v4n.js → storage-memory-9g882j7a.js} +2 -2
- package/dist/{storage-tags-1kets0q8.js → storage-tags-m2qcp1g2.js} +7 -5
- package/dist/subagent-entry.js +26 -25
- package/dist/tag-snapshot-worker-pi.js +22 -14
- package/package.json +1 -1
- package/dist/embedding-backfill-vwag34t0.js +0 -23
- package/dist/search-archive-4817pqev.js +0 -20
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getTokenEstimatorFingerprint,
|
|
3
3
|
estimateTokens
|
|
4
|
-
} from "./index-
|
|
4
|
+
} from "./index-my0dn413.js";
|
|
5
5
|
import {
|
|
6
6
|
getHarness2
|
|
7
7
|
} from "./index-0h2mkab2.js";
|
|
8
8
|
import {
|
|
9
9
|
log2
|
|
10
|
-
} from "./index-
|
|
10
|
+
} from "./index-fgs78jyd.js";
|
|
11
11
|
import {
|
|
12
12
|
isSynapseEmbeddingTruncated
|
|
13
|
-
} from "./index-
|
|
13
|
+
} from "./index-jxjr7kz9.js";
|
|
14
14
|
import {
|
|
15
15
|
messageFtsOrdinalRangeIsMapped2
|
|
16
|
-
} from "./index-
|
|
16
|
+
} from "./index-rgfb753z.js";
|
|
17
17
|
|
|
18
18
|
// ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
|
|
19
19
|
import { createHash } from "node:crypto";
|
|
@@ -104,8 +104,8 @@ function recursiveCharacterSplit(text, options) {
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
// ../plugin/src/features/magic-context/compartment-chunk-embedding.ts
|
|
107
|
-
var
|
|
108
|
-
var
|
|
107
|
+
var DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2 = 512;
|
|
108
|
+
var CHUNK_WINDOW_SAFETY_RATIO2 = 0.9;
|
|
109
109
|
var SEARCH_SCOPE_METADATA_FIELDS = [
|
|
110
110
|
"rowId",
|
|
111
111
|
"compartmentId",
|
|
@@ -142,9 +142,11 @@ var existingHashByProjectStatements = new WeakMap;
|
|
|
142
142
|
var deleteByCompartmentStatements = new WeakMap;
|
|
143
143
|
var insertEmbeddingStatements = new WeakMap;
|
|
144
144
|
var renumberEmbeddingWindowStatements = new WeakMap;
|
|
145
|
-
var
|
|
146
|
-
var searchRowsByModelStatements = new WeakMap;
|
|
145
|
+
var searchRowsByIdStatements = new WeakMap;
|
|
147
146
|
var searchPoolProbeStatements = new WeakMap;
|
|
147
|
+
var sessionSignatureStatements = new WeakMap;
|
|
148
|
+
var sessionPrefixStatements = new WeakMap;
|
|
149
|
+
var revisionStatements = new WeakMap;
|
|
148
150
|
var pendingSearchPools = new WeakMap;
|
|
149
151
|
var backfillCandidateStatements = new WeakMap;
|
|
150
152
|
var shadowBackfillCandidateStatements = new WeakMap;
|
|
@@ -152,7 +154,17 @@ var DECODED_SEARCH_POOL_CACHE_MAX_BYTES = 256 * 1024 * 1024;
|
|
|
152
154
|
var decodedSearchPools = new WeakMap;
|
|
153
155
|
var decodedSearchPoolLru = new Map;
|
|
154
156
|
var decodedSearchPoolBytes = 0;
|
|
155
|
-
var searchPoolStats = {
|
|
157
|
+
var searchPoolStats = {
|
|
158
|
+
fullRebuilds: 0,
|
|
159
|
+
appends: 0,
|
|
160
|
+
partialRefreshes: 0,
|
|
161
|
+
rowsDecoded: 0,
|
|
162
|
+
probes: 0,
|
|
163
|
+
tailProbes: 0,
|
|
164
|
+
endProbes: 0,
|
|
165
|
+
probeMs: 0,
|
|
166
|
+
probePages: 0
|
|
167
|
+
};
|
|
156
168
|
function getLoadFtsRowsStatement(db) {
|
|
157
169
|
let stmt = loadFtsRowsStatements.get(db);
|
|
158
170
|
if (!stmt) {
|
|
@@ -239,18 +251,22 @@ function sameScopeMetadata(left, right) {
|
|
|
239
251
|
}
|
|
240
252
|
return true;
|
|
241
253
|
}
|
|
242
|
-
async function probeSearchScope(db, sessionId, projectPath, modelId, previous) {
|
|
254
|
+
async function probeSearchScope(db, sessionId, projectPath, modelId, previous, options = {}) {
|
|
243
255
|
const started = performance.now();
|
|
244
|
-
|
|
256
|
+
const tailOnly = options.tailOnly === true && previous !== undefined;
|
|
257
|
+
if (tailOnly)
|
|
258
|
+
searchPoolStats.tailProbes++;
|
|
259
|
+
else
|
|
260
|
+
searchPoolStats.probes++;
|
|
245
261
|
const probe = {
|
|
246
|
-
rowCount: 0,
|
|
247
|
-
maxRowId: 0,
|
|
248
|
-
rowIdSum: 0,
|
|
262
|
+
rowCount: tailOnly ? previous.rowCount : 0,
|
|
263
|
+
maxRowId: tailOnly ? previous.maxRowId : 0,
|
|
264
|
+
rowIdSum: tailOnly ? previous.rowIdSum : 0,
|
|
249
265
|
metadata: previous?.metadata ?? new Map,
|
|
250
266
|
ids: previous?.ids ?? []
|
|
251
267
|
};
|
|
252
268
|
let copied = previous === undefined;
|
|
253
|
-
let oldIndex = 0;
|
|
269
|
+
let oldIndex = tailOnly ? previous.ids.length : 0;
|
|
254
270
|
const writable = () => {
|
|
255
271
|
if (!copied) {
|
|
256
272
|
probe.metadata = new Map(probe.metadata);
|
|
@@ -260,6 +276,7 @@ async function probeSearchScope(db, sessionId, projectPath, modelId, previous) {
|
|
|
260
276
|
};
|
|
261
277
|
await yieldSearchPool();
|
|
262
278
|
for (;; ) {
|
|
279
|
+
options.signal?.throwIfAborted();
|
|
263
280
|
const rows = getSearchPoolProbeStatement(db).all(sessionId, projectPath, modelId, probe.maxRowId);
|
|
264
281
|
searchPoolStats.probePages++;
|
|
265
282
|
if (rows.length === 0) {
|
|
@@ -293,22 +310,54 @@ async function probeSearchScope(db, sessionId, projectPath, modelId, previous) {
|
|
|
293
310
|
await yieldSearchPool();
|
|
294
311
|
}
|
|
295
312
|
}
|
|
296
|
-
function
|
|
297
|
-
|
|
313
|
+
function getSessionSignatureStatement(db) {
|
|
314
|
+
let stmt = sessionSignatureStatements.get(db);
|
|
315
|
+
if (!stmt) {
|
|
316
|
+
stmt = db.prepare(`SELECT COUNT(*) AS rowCount, COALESCE(MAX(id), 0) AS maxRowId,
|
|
317
|
+
COALESCE(SUM(id), 0) AS rowIdSum
|
|
318
|
+
FROM compartment_chunk_embeddings WHERE session_id = ?`);
|
|
319
|
+
sessionSignatureStatements.set(db, stmt);
|
|
320
|
+
}
|
|
321
|
+
return stmt;
|
|
298
322
|
}
|
|
299
|
-
function
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
323
|
+
function readSessionChunkSignature(db, sessionId) {
|
|
324
|
+
const row = getSessionSignatureStatement(db).get(sessionId);
|
|
325
|
+
return {
|
|
326
|
+
rowCount: Number(row?.rowCount ?? 0),
|
|
327
|
+
maxRowId: Number(row?.maxRowId ?? 0),
|
|
328
|
+
rowIdSum: Number(row?.rowIdSum ?? 0)
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
function sameSessionSignature(left, right) {
|
|
332
|
+
return left.rowCount === right.rowCount && left.maxRowId === right.maxRowId && left.rowIdSum === right.rowIdSum;
|
|
333
|
+
}
|
|
334
|
+
function sessionPrefixUnchanged(db, sessionId, signature) {
|
|
335
|
+
let stmt = sessionPrefixStatements.get(db);
|
|
336
|
+
if (!stmt) {
|
|
337
|
+
stmt = db.prepare(`SELECT COUNT(*) AS rowCount, COALESCE(SUM(id), 0) AS rowIdSum
|
|
338
|
+
FROM compartment_chunk_embeddings WHERE session_id = ? AND id <= ?`);
|
|
339
|
+
sessionPrefixStatements.set(db, stmt);
|
|
340
|
+
}
|
|
341
|
+
const row = stmt.get(sessionId, signature.maxRowId);
|
|
342
|
+
return Number(row?.rowCount ?? 0) === signature.rowCount && Number(row?.rowIdSum ?? 0) === signature.rowIdSum;
|
|
343
|
+
}
|
|
344
|
+
function readDatabaseRevision(db) {
|
|
345
|
+
let statements = revisionStatements.get(db);
|
|
346
|
+
if (!statements) {
|
|
347
|
+
statements = {
|
|
348
|
+
version: db.prepare("PRAGMA data_version"),
|
|
349
|
+
changes: db.prepare("SELECT total_changes() AS changes")
|
|
350
|
+
};
|
|
351
|
+
revisionStatements.set(db, statements);
|
|
310
352
|
}
|
|
311
|
-
|
|
353
|
+
const version = statements.version.get();
|
|
354
|
+
const changes = statements.changes.get();
|
|
355
|
+
if (typeof version?.data_version !== "number" || typeof changes?.changes !== "number")
|
|
356
|
+
return null;
|
|
357
|
+
return `${version.data_version}:${changes.changes}`;
|
|
358
|
+
}
|
|
359
|
+
function sameSearchScope(left, right) {
|
|
360
|
+
return left.rowCount === right.rowCount && left.maxRowId === right.maxRowId && left.rowIdSum === right.rowIdSum && (left.metadata === right.metadata || [...left.metadata].every(([id, value]) => right.metadata.get(id) === value));
|
|
312
361
|
}
|
|
313
362
|
function filterSearchPoolDates(rows, dateRange) {
|
|
314
363
|
if (dateRange === null)
|
|
@@ -318,9 +367,9 @@ function filterSearchPoolDates(rows, dateRange) {
|
|
|
318
367
|
return compartment !== undefined && compartment.startTime !== null && compartment.endTime !== null && compartment.startTime <= dateRange.to && compartment.endTime >= dateRange.from;
|
|
319
368
|
});
|
|
320
369
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
let stmt =
|
|
370
|
+
var SEARCH_READ_BATCH = 16;
|
|
371
|
+
function getSearchRowsByIdStatement(db) {
|
|
372
|
+
let stmt = searchRowsByIdStatements.get(db);
|
|
324
373
|
if (!stmt) {
|
|
325
374
|
stmt = db.prepare(`SELECT e.id AS rowId, e.compartment_id AS compartmentId,
|
|
326
375
|
start_map.message_time_ms AS startTime, end_map.message_time_ms AS endTime,
|
|
@@ -343,10 +392,10 @@ function getSearchRowsStatement(db, withModel) {
|
|
|
343
392
|
ON end_map.session_id = c.session_id AND end_map.message_ordinal = c.end_message
|
|
344
393
|
WHERE e.session_id = ?
|
|
345
394
|
AND e.project_path = ?
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
395
|
+
AND e.model_id = ?
|
|
396
|
+
AND e.id IN (${Array.from({ length: SEARCH_READ_BATCH }, () => "?").join(", ")})
|
|
397
|
+
ORDER BY e.id ASC`);
|
|
398
|
+
searchRowsByIdStatements.set(db, stmt);
|
|
350
399
|
}
|
|
351
400
|
return stmt;
|
|
352
401
|
}
|
|
@@ -427,7 +476,7 @@ function estimateDecodedSearchPoolBytes(rows) {
|
|
|
427
476
|
}
|
|
428
477
|
return bytes;
|
|
429
478
|
}
|
|
430
|
-
function cacheDecodedSearchPool(pool, key, probe, rows) {
|
|
479
|
+
function cacheDecodedSearchPool(pool, key, probe, rows, decodedById, sessionSignature, fullProbeAt) {
|
|
431
480
|
const existing = pool.get(key);
|
|
432
481
|
if (existing)
|
|
433
482
|
removeDecodedSearchPoolEntry(existing);
|
|
@@ -436,9 +485,12 @@ function cacheDecodedSearchPool(pool, key, probe, rows) {
|
|
|
436
485
|
key,
|
|
437
486
|
...probe,
|
|
438
487
|
rows,
|
|
488
|
+
decodedById,
|
|
489
|
+
sessionSignature,
|
|
490
|
+
fullProbeAt,
|
|
439
491
|
byteSize: estimateDecodedSearchPoolBytes(rows)
|
|
440
492
|
};
|
|
441
|
-
entry.byteSize += probe.ids.length *
|
|
493
|
+
entry.byteSize += probe.ids.length * 24;
|
|
442
494
|
for (const metadata of probe.metadata.values()) {
|
|
443
495
|
entry.byteSize += 320;
|
|
444
496
|
for (const key of SEARCH_SCOPE_METADATA_FIELDS) {
|
|
@@ -460,9 +512,9 @@ function cacheDecodedSearchPool(pool, key, probe, rows) {
|
|
|
460
512
|
function isFinitePositiveInteger(value) {
|
|
461
513
|
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
462
514
|
}
|
|
463
|
-
function
|
|
515
|
+
function normalizeCompartmentChunkMaxInputTokens2(value) {
|
|
464
516
|
if (!isFinitePositiveInteger(value)) {
|
|
465
|
-
return
|
|
517
|
+
return DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2;
|
|
466
518
|
}
|
|
467
519
|
return Math.max(1, Math.floor(value));
|
|
468
520
|
}
|
|
@@ -511,7 +563,7 @@ function toFloat32Array(blob) {
|
|
|
511
563
|
}
|
|
512
564
|
return new Float32Array(blob.slice(0));
|
|
513
565
|
}
|
|
514
|
-
function
|
|
566
|
+
function buildCanonicalChunkTextFromFts2(db, sessionId, startOrdinal, endOrdinal) {
|
|
515
567
|
if (endOrdinal < startOrdinal)
|
|
516
568
|
return "";
|
|
517
569
|
if (!messageFtsOrdinalRangeIsMapped2(db, sessionId, startOrdinal, endOrdinal))
|
|
@@ -543,7 +595,7 @@ function buildCanonicalChunkTextFromFts(db, sessionId, startOrdinal, endOrdinal)
|
|
|
543
595
|
return lines.join(`
|
|
544
596
|
`);
|
|
545
597
|
}
|
|
546
|
-
function
|
|
598
|
+
function buildCompartmentSummaryFallbackText2(db, compartmentId) {
|
|
547
599
|
const row = db.prepare("SELECT title, p1, content FROM compartments WHERE id = ?").get(compartmentId);
|
|
548
600
|
if (!row)
|
|
549
601
|
return "";
|
|
@@ -553,7 +605,7 @@ function buildCompartmentSummaryFallbackText(db, compartmentId) {
|
|
|
553
605
|
return [title, body].filter((s) => s.length > 0).join(`
|
|
554
606
|
`);
|
|
555
607
|
}
|
|
556
|
-
function
|
|
608
|
+
function canonicalizeInMemoryChunkTextForEmbedding2(chunkText, startOrdinal, endOrdinal) {
|
|
557
609
|
const lines = [];
|
|
558
610
|
for (const rawLine of chunkText.split(/\r?\n/)) {
|
|
559
611
|
const line = rawLine.trim();
|
|
@@ -598,7 +650,7 @@ function canonicalizeInMemoryChunkTextForEmbedding(chunkText, startOrdinal, endO
|
|
|
598
650
|
return lines.join(`
|
|
599
651
|
`);
|
|
600
652
|
}
|
|
601
|
-
function
|
|
653
|
+
function chunkCanonicalText2(canonicalText, startOrdinal, endOrdinal, maxInputTokens) {
|
|
602
654
|
const lines = canonicalText.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
603
655
|
if (lines.length === 0 || endOrdinal < startOrdinal)
|
|
604
656
|
return [];
|
|
@@ -608,8 +660,8 @@ function chunkCanonicalText(canonicalText, startOrdinal, endOrdinal, maxInputTok
|
|
|
608
660
|
assertOrdinalRangeWithinCompartment(range.start, range.end, startOrdinal, endOrdinal);
|
|
609
661
|
}
|
|
610
662
|
}
|
|
611
|
-
const normalizedMax =
|
|
612
|
-
const effectiveMax = Math.max(1, Math.floor(normalizedMax *
|
|
663
|
+
const normalizedMax = normalizeCompartmentChunkMaxInputTokens2(maxInputTokens);
|
|
664
|
+
const effectiveMax = Math.max(1, Math.floor(normalizedMax * CHUNK_WINDOW_SAFETY_RATIO2));
|
|
613
665
|
const fullText = lines.join(`
|
|
614
666
|
`);
|
|
615
667
|
if (estimateTokens(fullText) <= effectiveMax) {
|
|
@@ -733,13 +785,13 @@ function getExistingChunkHashes(db, compartmentId, modelId, projectPath) {
|
|
|
733
785
|
const rows = scoped ? getExistingHashStatement(db, true).all(compartmentId, modelId, projectPath) : getExistingHashStatement(db, false).all(compartmentId, modelId);
|
|
734
786
|
return new Map(rows.filter((row) => typeof row.windowIndex === "number" && typeof row.chunkHash === "string").map((row) => [row.windowIndex, row.chunkHash]));
|
|
735
787
|
}
|
|
736
|
-
function
|
|
788
|
+
function chunkEmbeddingWindowsAreCurrent2(db, compartmentId, modelId, windows, projectPath) {
|
|
737
789
|
const existing = getExistingChunkHashes(db, compartmentId, modelId, projectPath);
|
|
738
790
|
if (existing.size !== windows.length)
|
|
739
791
|
return false;
|
|
740
792
|
return windows.every((window) => existing.get(window.windowIndex) === window.chunkHash);
|
|
741
793
|
}
|
|
742
|
-
function
|
|
794
|
+
function replaceCompartmentChunkEmbeddings2(db, rows, windowSourceKey) {
|
|
743
795
|
if (rows.length === 0 || rows.some((row) => isSynapseEmbeddingTruncated(row.vector)))
|
|
744
796
|
return;
|
|
745
797
|
const compartmentId = rows[0].compartmentId;
|
|
@@ -761,104 +813,239 @@ function searchPoolInTransaction(db) {
|
|
|
761
813
|
const connection = db;
|
|
762
814
|
return connection.inTransaction === true || connection.isTransaction === true;
|
|
763
815
|
}
|
|
764
|
-
|
|
816
|
+
function emptyRefreshTimings() {
|
|
817
|
+
return { probeMs: 0, readMs: 0, decodeMs: 0, probedRows: 0, decodedRows: 0, attempts: 0 };
|
|
818
|
+
}
|
|
819
|
+
function decodeSearchRow(row) {
|
|
820
|
+
if (typeof row.compartmentId !== "number" || typeof row.sessionId !== "string" || typeof row.title !== "string" || typeof row.compartmentStart !== "number" || typeof row.compartmentEnd !== "number" || typeof row.windowIndex !== "number" || typeof row.windowStart !== "number" || typeof row.windowEnd !== "number" || typeof row.chunkHash !== "string" || typeof row.modelId !== "string" || typeof row.dims !== "number" || !(row.vector instanceof Uint8Array || row.vector instanceof ArrayBuffer))
|
|
821
|
+
return null;
|
|
822
|
+
const decoded = {
|
|
823
|
+
compartmentId: row.compartmentId,
|
|
824
|
+
sessionId: row.sessionId,
|
|
825
|
+
title: row.title,
|
|
826
|
+
startOrdinal: row.compartmentStart,
|
|
827
|
+
endOrdinal: row.compartmentEnd,
|
|
828
|
+
windowIndex: row.windowIndex,
|
|
829
|
+
windowStartOrdinal: row.windowStart,
|
|
830
|
+
windowEndOrdinal: row.windowEnd,
|
|
831
|
+
chunkHash: row.chunkHash,
|
|
832
|
+
modelId: row.modelId,
|
|
833
|
+
dims: row.dims,
|
|
834
|
+
vector: toFloat32Array(row.vector)
|
|
835
|
+
};
|
|
836
|
+
searchPoolDates.set(decoded, { startTime: row.startTime, endTime: row.endTime });
|
|
837
|
+
return decoded;
|
|
838
|
+
}
|
|
839
|
+
async function refreshDecodedSearchPool(db, sessionId, projectPath, modelId, options = {}) {
|
|
765
840
|
const key = searchPoolKey(sessionId, projectPath, modelId);
|
|
766
841
|
const pool = getDecodedSearchPool(db);
|
|
842
|
+
const timings = options.timings ?? emptyRefreshTimings();
|
|
843
|
+
const { signal } = options;
|
|
767
844
|
for (;; ) {
|
|
845
|
+
signal?.throwIfAborted();
|
|
846
|
+
timings.attempts++;
|
|
768
847
|
const inTransaction = searchPoolInTransaction(db);
|
|
848
|
+
const revision = readDatabaseRevision(db);
|
|
849
|
+
const sessionSignature = readSessionChunkSignature(db, sessionId);
|
|
769
850
|
const previous = pool.get(key);
|
|
770
|
-
const
|
|
771
|
-
const
|
|
772
|
-
const
|
|
851
|
+
const tailOnly = options.background === true && !inTransaction && previous !== undefined && sessionPrefixUnchanged(db, sessionId, previous.sessionSignature);
|
|
852
|
+
const probeStarted = performance.now();
|
|
853
|
+
const probe = await probeSearchScope(db, sessionId, projectPath, modelId, previous, {
|
|
854
|
+
tailOnly,
|
|
855
|
+
signal
|
|
856
|
+
});
|
|
857
|
+
timings.probeMs += performance.now() - probeStarted;
|
|
858
|
+
timings.probedRows = probe.rowCount;
|
|
859
|
+
const fullProbeAt = tailOnly && previous ? previous.fullProbeAt : probeStarted;
|
|
773
860
|
const cached = pool.get(key);
|
|
774
861
|
if (!inTransaction && cached && sameSearchScope(cached, probe)) {
|
|
862
|
+
cached.sessionSignature = sessionSignature;
|
|
863
|
+
cached.fullProbeAt = Math.max(cached.fullProbeAt, fullProbeAt);
|
|
775
864
|
touchDecodedSearchPoolEntry(cached);
|
|
776
865
|
return cached.rows;
|
|
777
866
|
}
|
|
778
|
-
const
|
|
779
|
-
|
|
867
|
+
const reusable = inTransaction ? undefined : previous;
|
|
868
|
+
const decodedById = new Map;
|
|
869
|
+
const missing = [];
|
|
870
|
+
for (const id of probe.ids) {
|
|
871
|
+
const prior = reusable !== undefined && reusable.metadata.get(id) === probe.metadata.get(id) ? reusable.decodedById.get(id) : undefined;
|
|
872
|
+
if (prior === undefined)
|
|
873
|
+
missing.push(id);
|
|
874
|
+
else
|
|
875
|
+
decodedById.set(id, prior);
|
|
876
|
+
}
|
|
877
|
+
if (!reusable || missing.length === probe.ids.length)
|
|
878
|
+
searchPoolStats.fullRebuilds++;
|
|
879
|
+
else if (probe.ids.length - missing.length === reusable.ids.length && missing.every((id) => id > reusable.maxRowId))
|
|
780
880
|
searchPoolStats.appends++;
|
|
781
881
|
else
|
|
782
|
-
searchPoolStats.
|
|
783
|
-
let afterId = append ? cached.maxRowId : 0;
|
|
784
|
-
const added = [];
|
|
785
|
-
let appendedCount = 0;
|
|
882
|
+
searchPoolStats.partialRefreshes++;
|
|
786
883
|
await yieldSearchPool();
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
windowStartOrdinal: row.windowStart,
|
|
804
|
-
windowEndOrdinal: row.windowEnd,
|
|
805
|
-
chunkHash: row.chunkHash,
|
|
806
|
-
modelId: row.modelId,
|
|
807
|
-
dims: row.dims,
|
|
808
|
-
vector: toFloat32Array(row.vector)
|
|
809
|
-
});
|
|
810
|
-
searchPoolDates.set(added[added.length - 1], {
|
|
811
|
-
startTime: row.startTime,
|
|
812
|
-
endTime: row.endTime
|
|
813
|
-
});
|
|
814
|
-
}
|
|
884
|
+
const read = getSearchRowsByIdStatement(db);
|
|
885
|
+
for (let start = 0;start < missing.length; start += SEARCH_READ_BATCH) {
|
|
886
|
+
signal?.throwIfAborted();
|
|
887
|
+
const batch = missing.slice(start, start + SEARCH_READ_BATCH);
|
|
888
|
+
const ids = batch.concat(Array(SEARCH_READ_BATCH - batch.length).fill(-1));
|
|
889
|
+
const readStarted = performance.now();
|
|
890
|
+
const rows = read.all(sessionId, projectPath, modelId, ...ids);
|
|
891
|
+
const decodeStarted = performance.now();
|
|
892
|
+
timings.readMs += decodeStarted - readStarted;
|
|
893
|
+
for (const id of batch)
|
|
894
|
+
decodedById.set(id, null);
|
|
895
|
+
for (const row of rows)
|
|
896
|
+
decodedById.set(row.rowId, decodeSearchRow(row));
|
|
897
|
+
timings.decodeMs += performance.now() - decodeStarted;
|
|
898
|
+
timings.decodedRows += rows.length;
|
|
899
|
+
searchPoolStats.rowsDecoded += rows.length;
|
|
815
900
|
await yieldSearchPool();
|
|
816
901
|
}
|
|
817
|
-
|
|
818
|
-
if (
|
|
819
|
-
|
|
902
|
+
let unchanged;
|
|
903
|
+
if (options.background) {
|
|
904
|
+
unchanged = sameSessionSignature(readSessionChunkSignature(db, sessionId), sessionSignature);
|
|
905
|
+
} else if (revision !== null && readDatabaseRevision(db) === revision) {
|
|
906
|
+
unchanged = true;
|
|
907
|
+
} else {
|
|
908
|
+
searchPoolStats.endProbes++;
|
|
909
|
+
unchanged = sameSearchScope(probe, await probeSearchScope(db, sessionId, projectPath, modelId, probe, { signal }));
|
|
820
910
|
}
|
|
821
|
-
if (
|
|
822
|
-
removeDecodedSearchPoolEntry(cached);
|
|
911
|
+
if (!unchanged || searchPoolInTransaction(db) !== inTransaction)
|
|
823
912
|
continue;
|
|
913
|
+
const decoded = [];
|
|
914
|
+
for (const id of probe.ids) {
|
|
915
|
+
const row = decodedById.get(id);
|
|
916
|
+
if (row)
|
|
917
|
+
decoded.push(row);
|
|
824
918
|
}
|
|
825
|
-
const decoded = append ? cached.rows.concat(added) : added;
|
|
826
919
|
decoded.sort((a, b) => a.compartmentId - b.compartmentId || a.windowIndex - b.windowIndex);
|
|
827
920
|
if (!inTransaction)
|
|
828
|
-
cacheDecodedSearchPool(pool, key, probe, decoded);
|
|
921
|
+
cacheDecodedSearchPool(pool, key, probe, decoded, decodedById, sessionSignature, fullProbeAt);
|
|
829
922
|
return decoded;
|
|
830
923
|
}
|
|
831
924
|
}
|
|
832
|
-
async function
|
|
833
|
-
if (!modelId) {
|
|
834
|
-
throw new Error("loadCompartmentChunkEmbeddingsForSearch requires a current model id");
|
|
835
|
-
}
|
|
925
|
+
async function refreshSearchPoolOnce(db, sessionId, projectPath, modelId, options) {
|
|
836
926
|
const key = searchPoolKey(sessionId, projectPath, modelId);
|
|
837
927
|
let pending = pendingSearchPools.get(db);
|
|
838
928
|
if (!pending) {
|
|
839
929
|
pending = new Map;
|
|
840
930
|
pendingSearchPools.set(db, pending);
|
|
841
931
|
}
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
} finally {
|
|
932
|
+
while (pending.has(key))
|
|
933
|
+
await pending.get(key);
|
|
934
|
+
const operation = refreshDecodedSearchPool(db, sessionId, projectPath, modelId, options);
|
|
935
|
+
const completion = operation.then(() => {}, () => {});
|
|
936
|
+
pending.set(key, completion);
|
|
937
|
+
try {
|
|
938
|
+
return await operation;
|
|
939
|
+
} finally {
|
|
940
|
+
if (pending.get(key) === completion)
|
|
852
941
|
pending.delete(key);
|
|
853
|
-
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
async function loadCompartmentChunkEmbeddingsForSearch2(db, sessionId, projectPath, modelId, dateRange = null, signal) {
|
|
945
|
+
if (!modelId) {
|
|
946
|
+
throw new Error("loadCompartmentChunkEmbeddingsForSearch requires a current model id");
|
|
947
|
+
}
|
|
948
|
+
const rows = await refreshSearchPoolOnce(db, sessionId, projectPath, modelId, { signal });
|
|
949
|
+
return filterSearchPoolDates(rows, dateRange);
|
|
950
|
+
}
|
|
951
|
+
var CHUNK_POOL_FULL_PROBE_INTERVAL_MS = 60000;
|
|
952
|
+
var TRACKED_SEARCH_POOL_LIMIT = 8;
|
|
953
|
+
var trackedSearchPools = new WeakMap;
|
|
954
|
+
function trackSearchPool(db, sessionId, projectPath, modelId) {
|
|
955
|
+
let tracked = trackedSearchPools.get(db);
|
|
956
|
+
if (!tracked) {
|
|
957
|
+
tracked = new Map;
|
|
958
|
+
trackedSearchPools.set(db, tracked);
|
|
959
|
+
}
|
|
960
|
+
const key = searchPoolKey(sessionId, projectPath, modelId);
|
|
961
|
+
tracked.delete(key);
|
|
962
|
+
tracked.set(key, { sessionId, projectPath, modelId });
|
|
963
|
+
while (tracked.size > TRACKED_SEARCH_POOL_LIMIT) {
|
|
964
|
+
const oldest = tracked.keys().next().value;
|
|
965
|
+
if (oldest === undefined)
|
|
966
|
+
break;
|
|
967
|
+
tracked.delete(oldest);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
var lastChunkPoolWarm = null;
|
|
971
|
+
var unretainedSearchPools = new WeakMap;
|
|
972
|
+
function getLastCompartmentChunkPoolWarm2() {
|
|
973
|
+
return lastChunkPoolWarm;
|
|
974
|
+
}
|
|
975
|
+
function peekCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId, dateRange = null) {
|
|
976
|
+
if (!modelId)
|
|
977
|
+
return null;
|
|
978
|
+
trackSearchPool(db, sessionId, projectPath, modelId);
|
|
979
|
+
const entry = getDecodedSearchPool(db).get(searchPoolKey(sessionId, projectPath, modelId));
|
|
980
|
+
if (!entry || searchPoolInTransaction(db))
|
|
981
|
+
return null;
|
|
982
|
+
if (!sameSessionSignature(readSessionChunkSignature(db, sessionId), entry.sessionSignature))
|
|
983
|
+
return null;
|
|
984
|
+
touchDecodedSearchPoolEntry(entry);
|
|
985
|
+
return filterSearchPoolDates(entry.rows, dateRange);
|
|
986
|
+
}
|
|
987
|
+
async function warmCompartmentChunkSearchPool2(db, sessionId, projectPath, modelId) {
|
|
988
|
+
const started = performance.now();
|
|
989
|
+
const timings = emptyRefreshTimings();
|
|
990
|
+
const report = (outcome) => ({
|
|
991
|
+
...timings,
|
|
992
|
+
outcome,
|
|
993
|
+
totalMs: performance.now() - started,
|
|
994
|
+
finishedAtUnixMs: Date.now()
|
|
995
|
+
});
|
|
996
|
+
if (!modelId)
|
|
997
|
+
return report("current");
|
|
998
|
+
trackSearchPool(db, sessionId, projectPath, modelId);
|
|
999
|
+
const key = searchPoolKey(sessionId, projectPath, modelId);
|
|
1000
|
+
try {
|
|
1001
|
+
if (pendingSearchPools.get(db)?.has(key))
|
|
1002
|
+
return report("in-progress");
|
|
1003
|
+
const unretained = unretainedSearchPools.get(db)?.get(key);
|
|
1004
|
+
if (unretained && sameSessionSignature(readSessionChunkSignature(db, sessionId), unretained))
|
|
1005
|
+
return report("too-large");
|
|
1006
|
+
const entry = getDecodedSearchPool(db).get(key);
|
|
1007
|
+
const fullProbeDue = entry !== undefined && performance.now() - entry.fullProbeAt >= CHUNK_POOL_FULL_PROBE_INTERVAL_MS;
|
|
1008
|
+
if (entry && !fullProbeDue && !searchPoolInTransaction(db) && sameSessionSignature(readSessionChunkSignature(db, sessionId), entry.sessionSignature))
|
|
1009
|
+
return report("current");
|
|
1010
|
+
const signature = readSessionChunkSignature(db, sessionId);
|
|
1011
|
+
await refreshSearchPoolOnce(db, sessionId, projectPath, modelId, {
|
|
1012
|
+
background: !fullProbeDue,
|
|
1013
|
+
timings
|
|
1014
|
+
});
|
|
1015
|
+
let unretainedPools = unretainedSearchPools.get(db);
|
|
1016
|
+
if (!getDecodedSearchPool(db).has(key)) {
|
|
1017
|
+
if (!unretainedPools) {
|
|
1018
|
+
unretainedPools = new Map;
|
|
1019
|
+
unretainedSearchPools.set(db, unretainedPools);
|
|
1020
|
+
}
|
|
1021
|
+
unretainedPools.set(key, signature);
|
|
1022
|
+
const tooLarge = report("too-large");
|
|
1023
|
+
lastChunkPoolWarm = tooLarge;
|
|
1024
|
+
return tooLarge;
|
|
854
1025
|
}
|
|
1026
|
+
unretainedPools?.delete(key);
|
|
1027
|
+
const refreshed = report("refreshed");
|
|
1028
|
+
lastChunkPoolWarm = refreshed;
|
|
1029
|
+
return refreshed;
|
|
1030
|
+
} catch {
|
|
1031
|
+
const failed = report("failed");
|
|
1032
|
+
lastChunkPoolWarm = failed;
|
|
1033
|
+
return failed;
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
async function maintainCompartmentChunkSearchPools2(db) {
|
|
1037
|
+
const tracked = trackedSearchPools.get(db);
|
|
1038
|
+
if (!tracked)
|
|
1039
|
+
return;
|
|
1040
|
+
for (const scope of [...tracked.values()]) {
|
|
1041
|
+
await warmCompartmentChunkSearchPool2(db, scope.sessionId, scope.projectPath, scope.modelId);
|
|
855
1042
|
}
|
|
856
1043
|
}
|
|
857
|
-
function
|
|
1044
|
+
function loadUnembeddedShadowChunkCandidates2(db, projectPath, primaryModelId, shadowModelId, limit, shadowMaxInputTokens) {
|
|
858
1045
|
const rows = getShadowBackfillCandidateStatement(db).all(projectPath, projectPath, primaryModelId);
|
|
859
1046
|
return selectHashIncompleteChunkCandidates(db, projectPath, shadowModelId, mapBackfillCandidateRows(rows), Math.max(1, limit), shadowMaxInputTokens);
|
|
860
1047
|
}
|
|
861
|
-
async function
|
|
1048
|
+
async function loadUnembeddedCompartmentChunkCandidatesPolite2(db, projectPath, modelId, limit, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2, leaseHeldRenumber = false, isEligible) {
|
|
862
1049
|
const rows = getBackfillCandidateStatement(db).all(projectPath);
|
|
863
1050
|
const candidates = mapBackfillCandidateRows(rows);
|
|
864
1051
|
const missing = [];
|
|
@@ -900,7 +1087,7 @@ var BACKOFF_PREFIX = "chunk_embed_backoff:";
|
|
|
900
1087
|
function backoffKey(compartmentId) {
|
|
901
1088
|
return `${BACKOFF_PREFIX}${compartmentId}`;
|
|
902
1089
|
}
|
|
903
|
-
function
|
|
1090
|
+
function deleteChunkEmbedBackoffForSession2(db, sessionId, limit) {
|
|
904
1091
|
if (limit !== undefined)
|
|
905
1092
|
return db.prepare(`DELETE FROM schema_migrations_meta WHERE key IN (
|
|
906
1093
|
SELECT key FROM schema_migrations_meta JOIN compartments
|
|
@@ -913,11 +1100,11 @@ function deleteChunkEmbedBackoffForSession(db, sessionId, limit) {
|
|
|
913
1100
|
SELECT ? || id FROM compartments WHERE session_id = ?
|
|
914
1101
|
)`).run(BACKOFF_PREFIX, sessionId, WINDOW_SOURCE_PREFIX, sessionId).changes;
|
|
915
1102
|
}
|
|
916
|
-
function
|
|
917
|
-
const mapped =
|
|
1103
|
+
function recordChunkEmbedBackoff2(db, candidate, projectPath, modelId) {
|
|
1104
|
+
const mapped = buildCanonicalChunkTextFromFts2(db, candidate.sessionId, candidate.startMessage, candidate.endMessage);
|
|
918
1105
|
if (mapped === null)
|
|
919
1106
|
return;
|
|
920
|
-
const text = mapped ||
|
|
1107
|
+
const text = mapped || buildCompartmentSummaryFallbackText2(db, candidate.id);
|
|
921
1108
|
const hash = createHash("sha256").update(text).digest("hex");
|
|
922
1109
|
const key = backoffKey(candidate.id);
|
|
923
1110
|
const prior = db.prepare("SELECT value FROM schema_migrations_meta WHERE key = ?").get(key);
|
|
@@ -959,13 +1146,13 @@ function windowSourceKeyFromTextHash(textHash, startOrdinal, endOrdinal, maxInpu
|
|
|
959
1146
|
return hashChunkText(JSON.stringify([
|
|
960
1147
|
CHUNKER_VERSION,
|
|
961
1148
|
getTokenEstimatorFingerprint(),
|
|
962
|
-
|
|
1149
|
+
normalizeCompartmentChunkMaxInputTokens2(maxInputTokens),
|
|
963
1150
|
startOrdinal,
|
|
964
1151
|
endOrdinal,
|
|
965
1152
|
textHash
|
|
966
1153
|
]));
|
|
967
1154
|
}
|
|
968
|
-
function
|
|
1155
|
+
function chunkWindowSourceKey2(canonicalText, startOrdinal, endOrdinal, maxInputTokens) {
|
|
969
1156
|
return windowSourceKeyFromTextHash(hashChunkText(canonicalText), startOrdinal, endOrdinal, maxInputTokens);
|
|
970
1157
|
}
|
|
971
1158
|
function windowSetDigest(windows) {
|
|
@@ -1019,7 +1206,7 @@ function memoizedCoverageWindows(candidate, canonicalText, sourceKey, modelId, m
|
|
|
1019
1206
|
cachedCoverageWindows.set(key, cached);
|
|
1020
1207
|
return cached;
|
|
1021
1208
|
}
|
|
1022
|
-
const windows =
|
|
1209
|
+
const windows = chunkCanonicalText2(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens);
|
|
1023
1210
|
cachedCoverageWindows.set(key, windows);
|
|
1024
1211
|
if (cachedCoverageWindows.size > COVERAGE_MEMO_LIMIT) {
|
|
1025
1212
|
const oldest = cachedCoverageWindows.keys().next().value;
|
|
@@ -1049,14 +1236,14 @@ function renumberOneBasedChunkWindows(db, candidate, projectPath, modelId, windo
|
|
|
1049
1236
|
}).immediate();
|
|
1050
1237
|
}
|
|
1051
1238
|
function classifyChunkCoverageDefect(db, projectPath, modelId, candidate, maxInputTokens) {
|
|
1052
|
-
const mappedText =
|
|
1239
|
+
const mappedText = buildCanonicalChunkTextFromFts2(db, candidate.sessionId, candidate.startMessage, candidate.endMessage);
|
|
1053
1240
|
if (mappedText === null)
|
|
1054
1241
|
return { defect: "deferred", windows: [] };
|
|
1055
|
-
const canonicalText = mappedText ||
|
|
1242
|
+
const canonicalText = mappedText || buildCompartmentSummaryFallbackText2(db, candidate.id);
|
|
1056
1243
|
if (!canonicalText || chunkEmbedBackoffActive(db, candidate, projectPath, modelId, canonicalText)) {
|
|
1057
1244
|
return { defect: "deferred", windows: [] };
|
|
1058
1245
|
}
|
|
1059
|
-
const sourceKey =
|
|
1246
|
+
const sourceKey = chunkWindowSourceKey2(canonicalText, candidate.startMessage, candidate.endMessage, maxInputTokens);
|
|
1060
1247
|
const existing = getExistingChunkHashes(db, candidate.id, modelId, projectPath);
|
|
1061
1248
|
if (storedWindowsMatchRecordedSource(db, candidate.id, sourceKey, existing)) {
|
|
1062
1249
|
return { defect: null, windows: [], sourceKey, confirmedByRecord: true };
|
|
@@ -1103,7 +1290,7 @@ function selectHashIncompleteChunkCandidates(db, projectPath, modelId, candidate
|
|
|
1103
1290
|
return [...missing, ...stale].slice(0, limit);
|
|
1104
1291
|
}
|
|
1105
1292
|
var sessionBackfillCandidateStatements = new WeakMap;
|
|
1106
|
-
function
|
|
1293
|
+
function loadUnembeddedSessionChunkCandidates2(db, projectPath, sessionId, modelId, limit, excludeIds, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2, leaseHeldRenumber = false) {
|
|
1107
1294
|
const exclusions = excludeIds && excludeIds.length > 0 ? excludeIds : [];
|
|
1108
1295
|
const exclusionSql = exclusions.length > 0 ? `AND c.id NOT IN (${exclusions.map(() => "?").join(", ")})` : "";
|
|
1109
1296
|
const stmt = exclusions.length > 0 ? db.prepare(`SELECT c.id AS id,
|
|
@@ -1144,7 +1331,7 @@ function loadUnembeddedSessionChunkCandidates(db, projectPath, sessionId, modelI
|
|
|
1144
1331
|
const rows = stmt.all(projectPath, sessionId, ...exclusions);
|
|
1145
1332
|
return selectHashIncompleteChunkCandidates(db, projectPath, modelId, mapBackfillCandidateRows(rows), Math.max(1, limit), maxInputTokens, leaseHeldRenumber);
|
|
1146
1333
|
}
|
|
1147
|
-
async function
|
|
1334
|
+
async function loadUnembeddedSessionChunkCandidatesPolite2(db, projectPath, sessionId, modelId, limit, excludeIds = [], maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2, leaseHeldRenumber = false) {
|
|
1148
1335
|
const excluded = new Set(excludeIds);
|
|
1149
1336
|
const missing = [];
|
|
1150
1337
|
const stale = [];
|
|
@@ -1166,7 +1353,7 @@ async function loadUnembeddedSessionChunkCandidatesPolite(db, projectPath, sessi
|
|
|
1166
1353
|
}
|
|
1167
1354
|
return [...missing, ...stale].slice(0, Math.max(1, limit));
|
|
1168
1355
|
}
|
|
1169
|
-
function
|
|
1356
|
+
function countUnembeddedSessionCompartments2(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2) {
|
|
1170
1357
|
const rows = getSessionBackfillRows(db, projectPath, sessionId);
|
|
1171
1358
|
let count = 0;
|
|
1172
1359
|
for (const candidate of rows) {
|
|
@@ -1176,7 +1363,7 @@ function countUnembeddedSessionCompartments(db, projectPath, sessionId, modelId,
|
|
|
1176
1363
|
}
|
|
1177
1364
|
return count;
|
|
1178
1365
|
}
|
|
1179
|
-
function
|
|
1366
|
+
function countSessionCompartmentEmbedCoverage2(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2) {
|
|
1180
1367
|
const candidates = getSessionBackfillRows(db, projectPath, sessionId);
|
|
1181
1368
|
let embedded = 0;
|
|
1182
1369
|
for (const candidate of candidates) {
|
|
@@ -1203,7 +1390,7 @@ function getSessionBackfillRows(db, projectPath, sessionId) {
|
|
|
1203
1390
|
ORDER BY c.start_message ASC, c.id ASC`).all(projectPath, sessionId);
|
|
1204
1391
|
return mapBackfillCandidateRows(rows);
|
|
1205
1392
|
}
|
|
1206
|
-
async function
|
|
1393
|
+
async function countSessionCompartmentEmbedCoveragePolite2(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2) {
|
|
1207
1394
|
const candidates = getSessionBackfillRows(db, projectPath, sessionId);
|
|
1208
1395
|
let embedded = 0;
|
|
1209
1396
|
let started = performance.now();
|
|
@@ -1215,7 +1402,7 @@ async function countSessionCompartmentEmbedCoveragePolite(db, projectPath, sessi
|
|
|
1215
1402
|
}
|
|
1216
1403
|
return { embedded, total: candidates.length };
|
|
1217
1404
|
}
|
|
1218
|
-
async function
|
|
1405
|
+
async function countUnembeddedSessionCompartmentsPolite2(db, projectPath, sessionId, modelId, maxInputTokens = DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2) {
|
|
1219
1406
|
const candidates = getSessionBackfillRows(db, projectPath, sessionId);
|
|
1220
1407
|
let count = 0;
|
|
1221
1408
|
let started = performance.now();
|
|
@@ -1228,4 +1415,4 @@ async function countUnembeddedSessionCompartmentsPolite(db, projectPath, session
|
|
|
1228
1415
|
return count;
|
|
1229
1416
|
}
|
|
1230
1417
|
|
|
1231
|
-
export {
|
|
1418
|
+
export { DEFAULT_COMPARTMENT_CHUNK_MAX_INPUT_TOKENS2, CHUNK_WINDOW_SAFETY_RATIO2, normalizeCompartmentChunkMaxInputTokens2, buildCanonicalChunkTextFromFts2, buildCompartmentSummaryFallbackText2, canonicalizeInMemoryChunkTextForEmbedding2, chunkCanonicalText2, chunkEmbeddingWindowsAreCurrent2, replaceCompartmentChunkEmbeddings2, loadCompartmentChunkEmbeddingsForSearch2, getLastCompartmentChunkPoolWarm2, peekCompartmentChunkSearchPool2, warmCompartmentChunkSearchPool2, maintainCompartmentChunkSearchPools2, loadUnembeddedShadowChunkCandidates2, loadUnembeddedCompartmentChunkCandidatesPolite2, deleteChunkEmbedBackoffForSession2, recordChunkEmbedBackoff2, chunkWindowSourceKey2, loadUnembeddedSessionChunkCandidates2, loadUnembeddedSessionChunkCandidatesPolite2, countUnembeddedSessionCompartments2, countSessionCompartmentEmbedCoverage2, countSessionCompartmentEmbedCoveragePolite2, countUnembeddedSessionCompartmentsPolite2 };
|