memorix 1.10.0 → 1.10.2
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/CHANGELOG.md +25 -0
- package/README.md +2 -0
- package/README.zh-CN.md +2 -0
- package/dist/cli/index.js +575 -196
- package/dist/index.js +375 -134
- package/dist/maintenance-runner.js +210 -46
- package/dist/media-audio-runner.js +182 -18
- package/dist/media-video-runner.js +209 -45
- package/dist/memcode-runtime/CHANGELOG.md +25 -0
- package/dist/sdk.js +426 -134
- package/dist/vector-backfill-runner.js +209 -45
- package/docs/1.2.0-EVALUATION-HARNESS.md +18 -0
- package/docs/CONFIGURATION.md +25 -0
- package/docs/DEVELOPMENT.md +3 -3
- package/docs/PERFORMANCE.md +23 -0
- package/docs/README.md +2 -2
- package/docs/ROADMAP-1.9.12-2.0.md +13 -6
- package/package.json +1 -1
- package/plugins/antigravity/memorix/plugin.json +1 -1
- package/plugins/claude/memorix/.claude-plugin/plugin.json +1 -1
- package/plugins/codebuddy/memorix/.codebuddy-plugin/plugin.json +1 -1
- package/plugins/codex/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/copilot/memorix/plugin.json +1 -1
- package/plugins/gemini/memorix/gemini-extension.json +1 -1
- package/plugins/hermes/memorix/__init__.py +1 -2
- package/plugins/hermes/memorix/plugin.yaml +1 -1
- package/plugins/omp/memorix/package.json +1 -1
- package/plugins/openclaw/memorix/.codex-plugin/plugin.json +1 -1
- package/plugins/pi/memorix/package.json +1 -1
- package/server.json +2 -2
- package/src/cli/commands/init.ts +6 -2
- package/src/cli/commands/repair.ts +17 -3
- package/src/cli/tui/ConfigureView.tsx +2 -0
- package/src/codegraph/auto-context.ts +17 -0
- package/src/codegraph/context-pack.ts +15 -0
- package/src/compact/engine.ts +11 -0
- package/src/compact/index-format.ts +1 -1
- package/src/config/dotenv-loader.ts +1 -0
- package/src/config/resolved-config.ts +5 -2
- package/src/config/yaml-loader.ts +2 -2
- package/src/dashboard/server.ts +3 -0
- package/src/knowledge/context-assembly.ts +13 -0
- package/src/knowledge/context-receipt.ts +35 -0
- package/src/knowledge/workset.ts +8 -0
- package/src/llm/provider.ts +2 -1
- package/src/memory/observations.ts +7 -5
- package/src/multimodal/image-loader.ts +2 -2
- package/src/search/derived-view-receipt.ts +62 -0
- package/src/search/semantic-index.ts +149 -1
- package/src/server.ts +18 -3
- package/src/store/orama-store.ts +80 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync } from 'node:fs';
|
|
2
3
|
import { createRequire } from 'node:module';
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import type { EmbeddingProvider } from '../embedding/provider.js';
|
|
@@ -29,6 +30,10 @@ const SEMANTIC_INDEX_DIR = 'semantic-index';
|
|
|
29
30
|
const TABLE_PREFIX = 'observations_';
|
|
30
31
|
const DEFAULT_INDEX_THRESHOLD = 10_000;
|
|
31
32
|
const MAX_INDEX_PARTITIONS = 32;
|
|
33
|
+
const DEFAULT_WRITE_BATCH_SIZE = 100;
|
|
34
|
+
const DEFAULT_WRITE_FLUSH_MS = 50;
|
|
35
|
+
const DEFAULT_OPTIMIZE_EVERY = 20;
|
|
36
|
+
const DEFAULT_VERSION_RETENTION_MS = 24 * 60 * 60 * 1000;
|
|
32
37
|
|
|
33
38
|
type SemanticIndexState = {
|
|
34
39
|
key: string;
|
|
@@ -41,6 +46,15 @@ type SemanticIndexState = {
|
|
|
41
46
|
const statePromises = new Map<string, Promise<SemanticIndexState | null>>();
|
|
42
47
|
const writeQueues = new Map<string, Promise<void>>();
|
|
43
48
|
const indexBuilds = new Map<string, Promise<boolean>>();
|
|
49
|
+
const mutationCounts = new Map<string, number>();
|
|
50
|
+
type PendingVectorBatch = {
|
|
51
|
+
dataDir: string;
|
|
52
|
+
profile: SemanticIndexProfile;
|
|
53
|
+
records: Map<string, SemanticVectorRecord>;
|
|
54
|
+
waiters: Array<{ resolve: () => void; reject: (error: unknown) => void }>;
|
|
55
|
+
timer?: ReturnType<typeof setTimeout>;
|
|
56
|
+
};
|
|
57
|
+
const pendingVectorBatches = new Map<string, PendingVectorBatch>();
|
|
44
58
|
let availability: boolean | undefined;
|
|
45
59
|
const requireFromHere = createRequire(import.meta.url);
|
|
46
60
|
|
|
@@ -176,6 +190,35 @@ function queueOperation(key: string, operation: () => Promise<void>): Promise<vo
|
|
|
176
190
|
return run;
|
|
177
191
|
}
|
|
178
192
|
|
|
193
|
+
function positiveEnvInt(name: string, fallback: number): number {
|
|
194
|
+
const value = Number.parseInt(process.env[name] ?? '', 10);
|
|
195
|
+
return Number.isSafeInteger(value) && value > 0 ? value : fallback;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function semanticWriteBatchSize(): number {
|
|
199
|
+
return positiveEnvInt('MEMORIX_SEMANTIC_WRITE_BATCH_SIZE', DEFAULT_WRITE_BATCH_SIZE);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function semanticWriteFlushMs(): number {
|
|
203
|
+
return positiveEnvInt('MEMORIX_SEMANTIC_WRITE_FLUSH_MS', DEFAULT_WRITE_FLUSH_MS);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function semanticOptimizeEvery(): number {
|
|
207
|
+
return positiveEnvInt('MEMORIX_SEMANTIC_OPTIMIZE_EVERY', DEFAULT_OPTIMIZE_EVERY);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function semanticVersionRetentionMs(): number {
|
|
211
|
+
return positiveEnvInt('MEMORIX_SEMANTIC_VERSION_RETENTION_MS', DEFAULT_VERSION_RETENTION_MS);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async function optimizeState(state: SemanticIndexState): Promise<void> {
|
|
215
|
+
if (!state.table || typeof state.table.optimize !== 'function') return;
|
|
216
|
+
await state.table.optimize({
|
|
217
|
+
cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
|
|
218
|
+
deleteUnverified: false,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
|
|
179
222
|
async function mergeVectors(dataDir: string, profile: SemanticIndexProfile, records: SemanticVectorRecord[]): Promise<void> {
|
|
180
223
|
if (records.length === 0) return;
|
|
181
224
|
const state = await getState(dataDir, profile, records);
|
|
@@ -186,18 +229,50 @@ async function mergeVectors(dataDir: string, profile: SemanticIndexProfile, reco
|
|
|
186
229
|
.whenMatchedUpdateAll()
|
|
187
230
|
.whenNotMatchedInsertAll()
|
|
188
231
|
.execute(rows);
|
|
232
|
+
const key = stateKey(dataDir, profile);
|
|
233
|
+
const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
|
|
234
|
+
if (mutationCount >= semanticOptimizeEvery()) {
|
|
235
|
+
mutationCounts.set(key, 0);
|
|
236
|
+
await optimizeState(state).catch(() => undefined);
|
|
237
|
+
} else {
|
|
238
|
+
mutationCounts.set(key, mutationCount);
|
|
239
|
+
}
|
|
189
240
|
// Build the ANN index asynchronously once the table is large enough. The
|
|
190
241
|
// current write remains cheap and the unindexed tail stays queryable while
|
|
191
242
|
// LanceDB trains the derived HNSW/SQ index.
|
|
192
243
|
void ensureSemanticIndex(dataDir, profile);
|
|
193
244
|
}
|
|
194
245
|
|
|
246
|
+
function flushPendingVectorBatch(key: string): Promise<void> {
|
|
247
|
+
const pending = pendingVectorBatches.get(key);
|
|
248
|
+
if (!pending) return Promise.resolve();
|
|
249
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
250
|
+
pendingVectorBatches.delete(key);
|
|
251
|
+
const records = [...pending.records.values()];
|
|
252
|
+
const waiters = pending.waiters.splice(0);
|
|
253
|
+
return queueOperation(key, () => mergeVectors(pending.dataDir, pending.profile, records))
|
|
254
|
+
.then(() => waiters.forEach((waiter) => waiter.resolve()))
|
|
255
|
+
.catch((error) => {
|
|
256
|
+
waiters.forEach((waiter) => waiter.reject(error));
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
195
260
|
export function upsertSemanticVector(
|
|
196
261
|
dataDir: string,
|
|
197
262
|
profile: SemanticIndexProfile,
|
|
198
263
|
record: SemanticVectorRecord,
|
|
199
264
|
): Promise<void> {
|
|
200
|
-
|
|
265
|
+
const key = stateKey(dataDir, profile);
|
|
266
|
+
let pending = pendingVectorBatches.get(key);
|
|
267
|
+
if (!pending) {
|
|
268
|
+
pending = { dataDir, profile, records: new Map(), waiters: [] };
|
|
269
|
+
pendingVectorBatches.set(key, pending);
|
|
270
|
+
}
|
|
271
|
+
pending.records.set(`${record.projectId}:${record.observationId}`, record);
|
|
272
|
+
const promise = new Promise<void>((resolve, reject) => pending!.waiters.push({ resolve, reject }));
|
|
273
|
+
if (pending.records.size >= semanticWriteBatchSize()) void flushPendingVectorBatch(key);
|
|
274
|
+
else if (!pending.timer) pending.timer = setTimeout(() => { void flushPendingVectorBatch(key); }, semanticWriteFlushMs());
|
|
275
|
+
return promise;
|
|
201
276
|
}
|
|
202
277
|
|
|
203
278
|
export function upsertSemanticVectors(
|
|
@@ -208,6 +283,68 @@ export function upsertSemanticVectors(
|
|
|
208
283
|
return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
|
|
209
284
|
}
|
|
210
285
|
|
|
286
|
+
/** Return persisted vector IDs without loading vector payloads. */
|
|
287
|
+
export async function listSemanticVectorIds(
|
|
288
|
+
dataDir: string,
|
|
289
|
+
profile: SemanticIndexProfile,
|
|
290
|
+
): Promise<Set<number> | null> {
|
|
291
|
+
const state = await getState(dataDir, profile);
|
|
292
|
+
if (!state?.table) return null;
|
|
293
|
+
const rows = await state.table.query().select(['observation_id']).toArray();
|
|
294
|
+
return new Set(rows.map((row: any) => Number(row.observation_id)).filter(Number.isSafeInteger));
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/** Read small, operator-safe table statistics without exposing vector data. */
|
|
298
|
+
export async function getSemanticIndexStats(
|
|
299
|
+
dataDir: string,
|
|
300
|
+
profile: SemanticIndexProfile,
|
|
301
|
+
): Promise<{ rowCount: number; version: number } | null> {
|
|
302
|
+
const state = await getState(dataDir, profile);
|
|
303
|
+
if (!state?.table) return null;
|
|
304
|
+
return {
|
|
305
|
+
rowCount: await state.table.countRows(),
|
|
306
|
+
version: typeof state.table.version === 'function' ? await state.table.version() : 0,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** Compact Lance fragments and prune old manifests for a semantic profile. */
|
|
311
|
+
export function optimizeSemanticIndex(
|
|
312
|
+
dataDir: string,
|
|
313
|
+
profile: SemanticIndexProfile,
|
|
314
|
+
): Promise<void> {
|
|
315
|
+
const key = stateKey(dataDir, profile);
|
|
316
|
+
return queueOperation(key, async () => {
|
|
317
|
+
const state = await getState(dataDir, profile);
|
|
318
|
+
if (state) await optimizeState(state);
|
|
319
|
+
mutationCounts.set(key, 0);
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** Repair all persisted semantic tables without needing an active embedding provider. */
|
|
324
|
+
export async function optimizeSemanticIndexes(dataDir: string): Promise<string[]> {
|
|
325
|
+
if (!existsSync(indexRoot(dataDir))) return [];
|
|
326
|
+
const lance = await loadLanceDb();
|
|
327
|
+
if (!lance) throw new Error('LanceDB is unavailable; install the optional @lancedb/lancedb package');
|
|
328
|
+
const connection = await lance.connect(indexRoot(dataDir));
|
|
329
|
+
try {
|
|
330
|
+
const names: string[] = typeof connection.tableNames === 'function'
|
|
331
|
+
? await connection.tableNames()
|
|
332
|
+
: (await connection.listTables()).tables;
|
|
333
|
+
const optimized: string[] = [];
|
|
334
|
+
for (const name of names.filter((value) => value.startsWith(TABLE_PREFIX))) {
|
|
335
|
+
const table = await connection.openTable(name);
|
|
336
|
+
await table.optimize({
|
|
337
|
+
cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
|
|
338
|
+
deleteUnverified: false,
|
|
339
|
+
});
|
|
340
|
+
optimized.push(name);
|
|
341
|
+
}
|
|
342
|
+
return optimized;
|
|
343
|
+
} finally {
|
|
344
|
+
try { connection.close?.(); } catch { /* best effort */ }
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
211
348
|
export function deleteSemanticVector(
|
|
212
349
|
dataDir: string,
|
|
213
350
|
profile: SemanticIndexProfile,
|
|
@@ -309,6 +446,8 @@ export async function searchSemanticVectors(options: {
|
|
|
309
446
|
|
|
310
447
|
/** Close native connections and release this process's derived-index cache. */
|
|
311
448
|
export async function closeSemanticIndexes(): Promise<void> {
|
|
449
|
+
await Promise.all([...pendingVectorBatches.keys()].map((key) => flushPendingVectorBatch(key)));
|
|
450
|
+
await Promise.all([...writeQueues.values()]);
|
|
312
451
|
for (const statePromise of statePromises.values()) {
|
|
313
452
|
const state = await statePromise.catch(() => null);
|
|
314
453
|
try { state?.connection?.close?.(); } catch { /* best effort */ }
|
|
@@ -316,11 +455,14 @@ export async function closeSemanticIndexes(): Promise<void> {
|
|
|
316
455
|
statePromises.clear();
|
|
317
456
|
writeQueues.clear();
|
|
318
457
|
indexBuilds.clear();
|
|
458
|
+
mutationCounts.clear();
|
|
319
459
|
}
|
|
320
460
|
|
|
321
461
|
/** Close only the semantic tables rooted in one Memorix data directory. */
|
|
322
462
|
export async function closeSemanticIndex(dataDir: string): Promise<void> {
|
|
323
463
|
const prefix = `${path.resolve(dataDir)}::`;
|
|
464
|
+
await Promise.all([...pendingVectorBatches.keys()].filter((key) => key.startsWith(prefix)).map(flushPendingVectorBatch));
|
|
465
|
+
await Promise.all([...writeQueues.entries()].filter(([key]) => key.startsWith(prefix)).map(([, queue]) => queue));
|
|
324
466
|
for (const [key, statePromise] of statePromises.entries()) {
|
|
325
467
|
if (!key.startsWith(prefix)) continue;
|
|
326
468
|
const state = await statePromise.catch(() => null);
|
|
@@ -328,13 +470,19 @@ export async function closeSemanticIndex(dataDir: string): Promise<void> {
|
|
|
328
470
|
statePromises.delete(key);
|
|
329
471
|
writeQueues.delete(key);
|
|
330
472
|
indexBuilds.delete(key);
|
|
473
|
+
mutationCounts.delete(key);
|
|
331
474
|
}
|
|
332
475
|
}
|
|
333
476
|
|
|
334
477
|
/** @internal Reset state for isolated tests. */
|
|
335
478
|
export function resetSemanticIndexRuntime(): void {
|
|
479
|
+
for (const pending of pendingVectorBatches.values()) {
|
|
480
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
481
|
+
}
|
|
482
|
+
pendingVectorBatches.clear();
|
|
336
483
|
statePromises.clear();
|
|
337
484
|
writeQueues.clear();
|
|
338
485
|
indexBuilds.clear();
|
|
486
|
+
mutationCounts.clear();
|
|
339
487
|
availability = undefined;
|
|
340
488
|
}
|
package/src/server.ts
CHANGED
|
@@ -31,6 +31,7 @@ import { extractEntities } from './memory/entity-extractor.js';
|
|
|
31
31
|
import { scopeKnowledgeGraphToProject } from './memory/graph-scope.js';
|
|
32
32
|
import { canManageObservation, canReadObservation, filterReadableObservations, resolveObservationVisibility } from './memory/visibility.js';
|
|
33
33
|
import { compactSearch, compactTimeline, compactDetail } from './compact/engine.js';
|
|
34
|
+
import { formatEntryRef } from './compact/index-format.js';
|
|
34
35
|
import { buildGraphContextPacket, formatGraphContextPrompt } from './memory/graph-context.js';
|
|
35
36
|
import { detectProject } from './project/detector.js';
|
|
36
37
|
import { homeProjectRootError, isHomeDirectory, writeLastProjectRoot } from './project/launch-root.js';
|
|
@@ -1562,7 +1563,18 @@ export async function createMemorixServer(
|
|
|
1562
1563
|
text,
|
|
1563
1564
|
},
|
|
1564
1565
|
],
|
|
1565
|
-
|
|
1566
|
+
// Clients that surface only structuredContent (e.g. Claude Code) must
|
|
1567
|
+
// still see the results, not just the retrieval diagnostics.
|
|
1568
|
+
structuredContent: {
|
|
1569
|
+
results: result.entries.map(entry => ({
|
|
1570
|
+
ref: formatEntryRef(entry),
|
|
1571
|
+
title: entry.title,
|
|
1572
|
+
type: entry.type,
|
|
1573
|
+
time: entry.time,
|
|
1574
|
+
tokens: entry.tokens,
|
|
1575
|
+
})),
|
|
1576
|
+
retrieval: result.receipt,
|
|
1577
|
+
},
|
|
1566
1578
|
};
|
|
1567
1579
|
}, { loadCorpus: false }); // withFreshIndex
|
|
1568
1580
|
},
|
|
@@ -4086,9 +4098,12 @@ export async function createMemorixServer(
|
|
|
4086
4098
|
}
|
|
4087
4099
|
} catch { /* team context injection is optional */ }
|
|
4088
4100
|
|
|
4101
|
+
const card = lines.filter(Boolean).join('\n');
|
|
4089
4102
|
return {
|
|
4090
|
-
content: [{ type: 'text' as const, text:
|
|
4091
|
-
structuredContent
|
|
4103
|
+
content: [{ type: 'text' as const, text: card }],
|
|
4104
|
+
// Clients that surface only structuredContent (e.g. Claude Code) must
|
|
4105
|
+
// still see the session card, not just the binding receipt.
|
|
4106
|
+
structuredContent: { card, binding: bindingReceipt },
|
|
4092
4107
|
};
|
|
4093
4108
|
},
|
|
4094
4109
|
);
|
package/src/store/orama-store.ts
CHANGED
|
@@ -19,7 +19,9 @@ import {
|
|
|
19
19
|
type EmbeddingInput,
|
|
20
20
|
type EmbeddingOptions,
|
|
21
21
|
type EmbeddingProvider,
|
|
22
|
+
type EmbeddingRuntimeHealth,
|
|
22
23
|
} from '../embedding/provider.js';
|
|
24
|
+
import * as embeddingRuntime from '../embedding/provider.js';
|
|
23
25
|
import { calculateProjectAffinity, extractProjectKeywords, type AffinityContext, type MemoryContent } from './project-affinity.js';
|
|
24
26
|
import { detectQueryIntent, applyIntentBoost } from '../search/intent-detector.js';
|
|
25
27
|
import { maybeExpandSearchQuery } from '../search/query-expansion.js';
|
|
@@ -29,10 +31,17 @@ import { getObservationStore } from './obs-store.js';
|
|
|
29
31
|
import {
|
|
30
32
|
createSemanticIndexProfile,
|
|
31
33
|
searchSemanticVectors,
|
|
34
|
+
listSemanticVectorIds,
|
|
35
|
+
upsertSemanticVector,
|
|
32
36
|
upsertSemanticVectors,
|
|
33
37
|
type SemanticIndexProfile,
|
|
34
38
|
type SemanticVectorRecord,
|
|
35
39
|
} from '../search/semantic-index.js';
|
|
40
|
+
import {
|
|
41
|
+
embeddingHealthReceipt,
|
|
42
|
+
sanitizeDerivedViewFailureReason,
|
|
43
|
+
type RetrievalDerivedViews,
|
|
44
|
+
} from '../search/derived-view-receipt.js';
|
|
36
45
|
|
|
37
46
|
let db: AnyOrama | null = null;
|
|
38
47
|
let dbInitPromise: Promise<AnyOrama> | null = null;
|
|
@@ -77,6 +86,66 @@ export function getLastSearchDiagnostics(projectId?: string): SearchDiagnostics
|
|
|
77
86
|
return diagnostics ? { ...diagnostics } : undefined;
|
|
78
87
|
}
|
|
79
88
|
|
|
89
|
+
/**
|
|
90
|
+
* Return bounded health metadata for the derived views used by retrieval.
|
|
91
|
+
* This is intentionally synchronous and network-free; provider initialization
|
|
92
|
+
* remains owned by the request that actually needs semantic search.
|
|
93
|
+
*/
|
|
94
|
+
export function getSearchDerivedViews(): RetrievalDerivedViews {
|
|
95
|
+
const views: RetrievalDerivedViews = {};
|
|
96
|
+
const store = getOptionalObservationStore();
|
|
97
|
+
if (store) {
|
|
98
|
+
try {
|
|
99
|
+
const generation = store.getGeneration();
|
|
100
|
+
if (store.hasLexicalIndex?.()) {
|
|
101
|
+
views.fts = { generation, freshness: 'current', rebuildStatus: 'idle' };
|
|
102
|
+
} else {
|
|
103
|
+
views.fts = {
|
|
104
|
+
generation,
|
|
105
|
+
freshness: 'unknown',
|
|
106
|
+
rebuildStatus: 'unavailable',
|
|
107
|
+
failureReason: sanitizeDerivedViewFailureReason(
|
|
108
|
+
store.getBackendReason?.() ?? 'persistent lexical index unavailable',
|
|
109
|
+
),
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
} catch (error) {
|
|
113
|
+
views.fts = {
|
|
114
|
+
freshness: 'unknown',
|
|
115
|
+
rebuildStatus: 'failed',
|
|
116
|
+
failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error)),
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
} else {
|
|
120
|
+
views.fts = {
|
|
121
|
+
freshness: 'unknown',
|
|
122
|
+
rebuildStatus: 'unavailable',
|
|
123
|
+
failureReason: 'observation store is not initialized',
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
views.orama = db
|
|
128
|
+
? { generation: dbGeneration, freshness: 'current', rebuildStatus: 'idle' }
|
|
129
|
+
: {
|
|
130
|
+
generation: dbGeneration,
|
|
131
|
+
freshness: 'unknown',
|
|
132
|
+
rebuildStatus: 'unavailable',
|
|
133
|
+
failureReason: 'Orama index is not initialized',
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
let embeddingHealth: EmbeddingRuntimeHealth | undefined;
|
|
137
|
+
try {
|
|
138
|
+
embeddingHealth = (embeddingRuntime as unknown as {
|
|
139
|
+
getEmbeddingRuntimeHealth?: () => EmbeddingRuntimeHealth;
|
|
140
|
+
}).getEmbeddingRuntimeHealth?.();
|
|
141
|
+
} catch {
|
|
142
|
+
// Legacy provider mocks/adapters may not expose health metadata.
|
|
143
|
+
}
|
|
144
|
+
views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
|
|
145
|
+
|
|
146
|
+
return views;
|
|
147
|
+
}
|
|
148
|
+
|
|
80
149
|
function rememberSearchDiagnostics(key: string, value: SearchDiagnostics): void {
|
|
81
150
|
if (!lastSearchDiagnosticsByProject.has(key) && lastSearchDiagnosticsByProject.size >= MAX_SEARCH_MODE_KEYS) {
|
|
82
151
|
const oldest = lastSearchDiagnosticsByProject.keys().next().value;
|
|
@@ -548,6 +617,12 @@ export function getActiveSemanticIndexProfile(): SemanticIndexProfile | null {
|
|
|
548
617
|
return indexEmbeddingProvider ? createSemanticIndexProfile(indexEmbeddingProvider) : null;
|
|
549
618
|
}
|
|
550
619
|
|
|
620
|
+
/** Read the durable semantic shadow's IDs without loading vector payloads. */
|
|
621
|
+
export async function getPersistentSemanticVectorIds(dataDir: string): Promise<Set<number> | null> {
|
|
622
|
+
if (!indexEmbeddingProvider) return null;
|
|
623
|
+
return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
|
|
624
|
+
}
|
|
625
|
+
|
|
551
626
|
/** Queue one derived vector without delaying the durable observation write. */
|
|
552
627
|
export async function queueSemanticVector(
|
|
553
628
|
dataDir: string,
|
|
@@ -560,7 +635,7 @@ export async function queueSemanticVector(
|
|
|
560
635
|
const profile = provider ? createSemanticIndexProfile(provider) : null;
|
|
561
636
|
if (!profile) return;
|
|
562
637
|
try {
|
|
563
|
-
await
|
|
638
|
+
await upsertSemanticVector(dataDir, profile, record);
|
|
564
639
|
} catch {
|
|
565
640
|
// The vector index is rebuildable; lexical memory remains authoritative.
|
|
566
641
|
}
|
|
@@ -667,6 +742,9 @@ async function attachCachedVectors(
|
|
|
667
742
|
): Promise<void> {
|
|
668
743
|
const semanticDataDir = (await import('../memory/observations.js')).getObservationDataDir();
|
|
669
744
|
const semanticProfile = getActiveSemanticIndexProfile();
|
|
745
|
+
const persistedSemanticIds = semanticDataDir && semanticProfile
|
|
746
|
+
? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null)
|
|
747
|
+
: null;
|
|
670
748
|
const batchSize = 200;
|
|
671
749
|
for (let start = 0; start < observations.length; start += batchSize) {
|
|
672
750
|
// Keep cache lookup and the temporary vector array bounded to one batch.
|
|
@@ -682,7 +760,7 @@ async function attachCachedVectors(
|
|
|
682
760
|
const vector = cachedVectors[index];
|
|
683
761
|
if (!isCompatibleCachedVector(vector)) continue;
|
|
684
762
|
const observation = batch[index];
|
|
685
|
-
if (semanticDataDir && semanticProfile) {
|
|
763
|
+
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
|
|
686
764
|
semanticRecords.push({
|
|
687
765
|
observationId: observation.id,
|
|
688
766
|
projectId: observation.projectId,
|