memorix 1.10.1 → 1.10.3
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 +34 -0
- package/README.md +3 -1
- package/README.zh-CN.md +3 -1
- package/dist/cli/index.js +810 -379
- package/dist/cli/memcode.js +0 -0
- package/dist/index.js +380 -142
- package/dist/maintenance-runner.js +275 -79
- package/dist/media-audio-runner.js +247 -51
- package/dist/media-video-runner.js +274 -78
- package/dist/memcode-runtime/CHANGELOG.md +34 -0
- package/dist/sdk.js +431 -142
- package/dist/types.d.ts +1 -1
- package/dist/vector-backfill-runner.js +274 -78
- package/docs/CONFIGURATION.md +34 -0
- package/docs/DEVELOPMENT.md +3 -4
- package/docs/INTEGRATIONS.md +1 -1
- package/docs/PERFORMANCE.md +23 -0
- package/docs/README.md +3 -2
- package/docs/ROADMAP-1.9.12-2.0.md +2 -2
- package/docs/SETUP.md +19 -4
- 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/agent-integrations.ts +1 -1
- package/src/cli/commands/background.ts +1 -1
- package/src/cli/commands/context.ts +3 -2
- package/src/cli/commands/doctor.ts +9 -0
- package/src/cli/commands/explain.ts +3 -2
- package/src/cli/commands/init.ts +6 -2
- package/src/cli/commands/repair.ts +17 -3
- package/src/cli/commands/setup.ts +9 -6
- package/src/cli/commands/uninstall.ts +15 -0
- package/src/cli/tui/App.tsx +9 -16
- package/src/cli/tui/ConfigureView.tsx +2 -0
- package/src/codegraph/auto-context.ts +1 -1
- package/src/codegraph/store.ts +37 -0
- package/src/codegraph/types.ts +3 -0
- package/src/compact/index-format.ts +1 -1
- package/src/config/dotenv-loader.ts +1 -0
- package/src/config/resolved-config.ts +7 -2
- package/src/config/toml-loader.ts +1 -0
- package/src/config/yaml-loader.ts +4 -2
- package/src/dashboard/server.ts +5 -6
- package/src/hooks/handler.ts +0 -1
- package/src/integrations/registry.ts +2 -1
- package/src/knowledge/context-receipt.ts +6 -3
- package/src/llm/provider.ts +2 -1
- package/src/memory/observations.ts +68 -22
- package/src/multimodal/image-loader.ts +2 -2
- package/src/runtime/open-browser.ts +25 -0
- package/src/search/derived-view-receipt.ts +40 -0
- package/src/search/semantic-index.ts +149 -1
- package/src/server.ts +20 -5
- package/src/store/orama-store.ts +59 -19
- package/src/types.ts +1 -1
- package/src/workspace/mcp-adapters/pi.ts +58 -0
- package/plugins/pi/memorix/skills/memorix-git-memory/SKILL.md +0 -26
- package/plugins/pi/memorix/skills/memorix-memory/SKILL.md +0 -51
- package/plugins/pi/memorix/skills/memorix-mini-skills/SKILL.md +0 -31
- package/plugins/pi/memorix/skills/memorix-orchestrate/SKILL.md +0 -28
- package/plugins/pi/memorix/skills/memorix-reasoning/SKILL.md +0 -30
- package/plugins/pi/memorix/skills/memorix-sessions/SKILL.md +0 -25
- package/plugins/pi/memorix/skills/memorix-troubleshooting/SKILL.md +0 -27
|
@@ -2408,7 +2408,8 @@ function getResolvedConfig(options = {}) {
|
|
|
2408
2408
|
const isRequesty = memoryLlmProvider === "requesty";
|
|
2409
2409
|
const isApiRoute = memoryLlmProvider === "apiroute";
|
|
2410
2410
|
const isCheaperInference = memoryLlmProvider === "cheaperinference";
|
|
2411
|
-
const
|
|
2411
|
+
const isRuncrate = memoryLlmProvider === "runcrate";
|
|
2412
|
+
const usesPresetKeyOnly = isAtlasCloud || isRequesty || isApiRoute || isCheaperInference || isRuncrate;
|
|
2412
2413
|
const memoryLlmApiKey = first(
|
|
2413
2414
|
process.env.MEMORIX_LLM_API_KEY,
|
|
2414
2415
|
process.env.MEMORIX_API_KEY,
|
|
@@ -2416,7 +2417,7 @@ function getResolvedConfig(options = {}) {
|
|
|
2416
2417
|
yaml.llm?.apiKey,
|
|
2417
2418
|
legacy.llm?.apiKey,
|
|
2418
2419
|
// Never borrow another provider's credentials for these gateway presets.
|
|
2419
|
-
isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : isApiRoute ? process.env.API_ROUTE_API_KEY : isCheaperInference ? process.env.CHEAPER_INFERENCE_API_KEY : process.env.OPENAI_API_KEY,
|
|
2420
|
+
isAtlasCloud ? process.env.ATLASCLOUD_API_KEY : isRequesty ? process.env.REQUESTY_API_KEY : isApiRoute ? process.env.API_ROUTE_API_KEY : isCheaperInference ? process.env.CHEAPER_INFERENCE_API_KEY : isRuncrate ? process.env.RUNCRATE_API_KEY : process.env.OPENAI_API_KEY,
|
|
2420
2421
|
usesPresetKeyOnly ? void 0 : process.env.ANTHROPIC_API_KEY,
|
|
2421
2422
|
usesPresetKeyOnly ? void 0 : openRouterMemoryLlmApiKey
|
|
2422
2423
|
);
|
|
@@ -2487,6 +2488,7 @@ function getResolvedConfig(options = {}) {
|
|
|
2487
2488
|
codegraph: {
|
|
2488
2489
|
excludePatterns: firstArray(toml.codegraph?.exclude_patterns, yaml.codegraph?.excludePatterns),
|
|
2489
2490
|
maxFileBytes: firstNumber(toml.codegraph?.max_file_bytes, yaml.codegraph?.maxFileBytes),
|
|
2491
|
+
autoRefresh: first(toml.codegraph?.auto_refresh, yaml.codegraph?.autoRefresh, "auto"),
|
|
2490
2492
|
externalContext: first(
|
|
2491
2493
|
normalizeExternalContext(process.env.MEMORIX_CODEGRAPH_EXTERNAL_CONTEXT),
|
|
2492
2494
|
toml.codegraph?.external_context,
|
|
@@ -2601,6 +2603,7 @@ function getEnvSourceNames() {
|
|
|
2601
2603
|
"REQUESTY_API_KEY",
|
|
2602
2604
|
"API_ROUTE_API_KEY",
|
|
2603
2605
|
"CHEAPER_INFERENCE_API_KEY",
|
|
2606
|
+
"RUNCRATE_API_KEY",
|
|
2604
2607
|
"ATLASCLOUD_API_KEY"
|
|
2605
2608
|
].filter((name) => process.env[name]);
|
|
2606
2609
|
}
|
|
@@ -5596,6 +5599,7 @@ var init_provider2 = __esm({
|
|
|
5596
5599
|
requesty: { baseUrl: "https://router.requesty.ai/v1", model: "openai/gpt-4.1-nano" },
|
|
5597
5600
|
apiroute: { baseUrl: "https://global.api-route.com/v1", model: "deepseek-v4.1-flash" },
|
|
5598
5601
|
cheaperinference: { baseUrl: "https://api.cheaperinference.com/v1", model: "gpt-5.4-mini" },
|
|
5602
|
+
runcrate: { baseUrl: "https://api.runcrate.ai/v1", model: "deepseek-ai/DeepSeek-V4.1-Flash" },
|
|
5599
5603
|
atlascloud: { baseUrl: "https://api.atlascloud.ai/v1", model: "deepseek-ai/deepseek-v3.2" },
|
|
5600
5604
|
custom: { baseUrl: "http://localhost:11434/v1", model: "llama3" }
|
|
5601
5605
|
};
|
|
@@ -6374,6 +6378,7 @@ var init_obs_store = __esm({
|
|
|
6374
6378
|
|
|
6375
6379
|
// src/search/semantic-index.ts
|
|
6376
6380
|
import { createHash as createHash4 } from "crypto";
|
|
6381
|
+
import { existsSync as existsSync8 } from "fs";
|
|
6377
6382
|
import { createRequire as createRequire3 } from "module";
|
|
6378
6383
|
import path8 from "path";
|
|
6379
6384
|
function createSemanticIndexProfile(provider2) {
|
|
@@ -6472,17 +6477,80 @@ function queueOperation(key, operation) {
|
|
|
6472
6477
|
writeQueues.set(key, run.catch(() => void 0));
|
|
6473
6478
|
return run;
|
|
6474
6479
|
}
|
|
6480
|
+
function positiveEnvInt(name, fallback) {
|
|
6481
|
+
const value = Number.parseInt(process.env[name] ?? "", 10);
|
|
6482
|
+
return Number.isSafeInteger(value) && value > 0 ? value : fallback;
|
|
6483
|
+
}
|
|
6484
|
+
function semanticWriteBatchSize() {
|
|
6485
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_BATCH_SIZE", DEFAULT_WRITE_BATCH_SIZE);
|
|
6486
|
+
}
|
|
6487
|
+
function semanticWriteFlushMs() {
|
|
6488
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_WRITE_FLUSH_MS", DEFAULT_WRITE_FLUSH_MS);
|
|
6489
|
+
}
|
|
6490
|
+
function semanticOptimizeEvery() {
|
|
6491
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_OPTIMIZE_EVERY", DEFAULT_OPTIMIZE_EVERY);
|
|
6492
|
+
}
|
|
6493
|
+
function semanticVersionRetentionMs() {
|
|
6494
|
+
return positiveEnvInt("MEMORIX_SEMANTIC_VERSION_RETENTION_MS", DEFAULT_VERSION_RETENTION_MS);
|
|
6495
|
+
}
|
|
6496
|
+
async function optimizeState(state) {
|
|
6497
|
+
if (!state.table || typeof state.table.optimize !== "function") return;
|
|
6498
|
+
await state.table.optimize({
|
|
6499
|
+
cleanupOlderThan: new Date(Date.now() - semanticVersionRetentionMs()),
|
|
6500
|
+
deleteUnverified: false
|
|
6501
|
+
});
|
|
6502
|
+
}
|
|
6475
6503
|
async function mergeVectors(dataDir, profile, records) {
|
|
6476
6504
|
if (records.length === 0) return;
|
|
6477
6505
|
const state = await getState(dataDir, profile, records);
|
|
6478
6506
|
if (!state?.table) return;
|
|
6479
6507
|
const rows = records.map(toLanceRow);
|
|
6480
6508
|
await state.table.mergeInsert("observation_id").whenMatchedUpdateAll().whenNotMatchedInsertAll().execute(rows);
|
|
6509
|
+
const key = stateKey(dataDir, profile);
|
|
6510
|
+
const mutationCount = (mutationCounts.get(key) ?? 0) + 1;
|
|
6511
|
+
if (mutationCount >= semanticOptimizeEvery()) {
|
|
6512
|
+
mutationCounts.set(key, 0);
|
|
6513
|
+
await optimizeState(state).catch(() => void 0);
|
|
6514
|
+
} else {
|
|
6515
|
+
mutationCounts.set(key, mutationCount);
|
|
6516
|
+
}
|
|
6481
6517
|
void ensureSemanticIndex(dataDir, profile);
|
|
6482
6518
|
}
|
|
6519
|
+
function flushPendingVectorBatch(key) {
|
|
6520
|
+
const pending = pendingVectorBatches.get(key);
|
|
6521
|
+
if (!pending) return Promise.resolve();
|
|
6522
|
+
if (pending.timer) clearTimeout(pending.timer);
|
|
6523
|
+
pendingVectorBatches.delete(key);
|
|
6524
|
+
const records = [...pending.records.values()];
|
|
6525
|
+
const waiters = pending.waiters.splice(0);
|
|
6526
|
+
return queueOperation(key, () => mergeVectors(pending.dataDir, pending.profile, records)).then(() => waiters.forEach((waiter) => waiter.resolve())).catch((error) => {
|
|
6527
|
+
waiters.forEach((waiter) => waiter.reject(error));
|
|
6528
|
+
});
|
|
6529
|
+
}
|
|
6530
|
+
function upsertSemanticVector(dataDir, profile, record80) {
|
|
6531
|
+
const key = stateKey(dataDir, profile);
|
|
6532
|
+
let pending = pendingVectorBatches.get(key);
|
|
6533
|
+
if (!pending) {
|
|
6534
|
+
pending = { dataDir, profile, records: /* @__PURE__ */ new Map(), waiters: [] };
|
|
6535
|
+
pendingVectorBatches.set(key, pending);
|
|
6536
|
+
}
|
|
6537
|
+
pending.records.set(`${record80.projectId}:${record80.observationId}`, record80);
|
|
6538
|
+
const promise = new Promise((resolve2, reject) => pending.waiters.push({ resolve: resolve2, reject }));
|
|
6539
|
+
if (pending.records.size >= semanticWriteBatchSize()) void flushPendingVectorBatch(key);
|
|
6540
|
+
else if (!pending.timer) pending.timer = setTimeout(() => {
|
|
6541
|
+
void flushPendingVectorBatch(key);
|
|
6542
|
+
}, semanticWriteFlushMs());
|
|
6543
|
+
return promise;
|
|
6544
|
+
}
|
|
6483
6545
|
function upsertSemanticVectors(dataDir, profile, records) {
|
|
6484
6546
|
return queueOperation(stateKey(dataDir, profile), () => mergeVectors(dataDir, profile, records));
|
|
6485
6547
|
}
|
|
6548
|
+
async function listSemanticVectorIds(dataDir, profile) {
|
|
6549
|
+
const state = await getState(dataDir, profile);
|
|
6550
|
+
if (!state?.table) return null;
|
|
6551
|
+
const rows = await state.table.query().select(["observation_id"]).toArray();
|
|
6552
|
+
return new Set(rows.map((row) => Number(row.observation_id)).filter(Number.isSafeInteger));
|
|
6553
|
+
}
|
|
6486
6554
|
function resolveIndexThreshold() {
|
|
6487
6555
|
const raw = Number.parseInt(process.env.MEMORIX_SEMANTIC_INDEX_THRESHOLD ?? "", 10);
|
|
6488
6556
|
return Number.isSafeInteger(raw) && raw > 0 ? raw : DEFAULT_INDEX_THRESHOLD;
|
|
@@ -6534,7 +6602,7 @@ async function searchSemanticVectors(options) {
|
|
|
6534
6602
|
distance: Number(row._distance ?? Number.POSITIVE_INFINITY)
|
|
6535
6603
|
})).filter((row) => Number.isFinite(row.distance));
|
|
6536
6604
|
}
|
|
6537
|
-
var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, statePromises, writeQueues, indexBuilds, availability, requireFromHere2;
|
|
6605
|
+
var SEMANTIC_INDEX_DIR, TABLE_PREFIX, DEFAULT_INDEX_THRESHOLD, MAX_INDEX_PARTITIONS, DEFAULT_WRITE_BATCH_SIZE, DEFAULT_WRITE_FLUSH_MS, DEFAULT_OPTIMIZE_EVERY, DEFAULT_VERSION_RETENTION_MS, statePromises, writeQueues, indexBuilds, mutationCounts, pendingVectorBatches, availability, requireFromHere2;
|
|
6538
6606
|
var init_semantic_index = __esm({
|
|
6539
6607
|
"src/search/semantic-index.ts"() {
|
|
6540
6608
|
"use strict";
|
|
@@ -6543,13 +6611,81 @@ var init_semantic_index = __esm({
|
|
|
6543
6611
|
TABLE_PREFIX = "observations_";
|
|
6544
6612
|
DEFAULT_INDEX_THRESHOLD = 1e4;
|
|
6545
6613
|
MAX_INDEX_PARTITIONS = 32;
|
|
6614
|
+
DEFAULT_WRITE_BATCH_SIZE = 100;
|
|
6615
|
+
DEFAULT_WRITE_FLUSH_MS = 50;
|
|
6616
|
+
DEFAULT_OPTIMIZE_EVERY = 20;
|
|
6617
|
+
DEFAULT_VERSION_RETENTION_MS = 24 * 60 * 60 * 1e3;
|
|
6546
6618
|
statePromises = /* @__PURE__ */ new Map();
|
|
6547
6619
|
writeQueues = /* @__PURE__ */ new Map();
|
|
6548
6620
|
indexBuilds = /* @__PURE__ */ new Map();
|
|
6621
|
+
mutationCounts = /* @__PURE__ */ new Map();
|
|
6622
|
+
pendingVectorBatches = /* @__PURE__ */ new Map();
|
|
6549
6623
|
requireFromHere2 = createRequire3(import.meta.url);
|
|
6550
6624
|
}
|
|
6551
6625
|
});
|
|
6552
6626
|
|
|
6627
|
+
// src/memory/secret-filter.ts
|
|
6628
|
+
function applyRedaction(text2) {
|
|
6629
|
+
if (!text2) return text2;
|
|
6630
|
+
let out = text2;
|
|
6631
|
+
out = out.replace(
|
|
6632
|
+
/((?:password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|access[_-]?key|private[_-]?key|client[_-]?secret)\s*[:=]\s*["']?)([^\s"',;\n]{6,})/gi,
|
|
6633
|
+
"$1[REDACTED]"
|
|
6634
|
+
);
|
|
6635
|
+
out = out.replace(
|
|
6636
|
+
/(Bearer\s+)([A-Za-z0-9._\-/+]{20,})/g,
|
|
6637
|
+
"$1[REDACTED]"
|
|
6638
|
+
);
|
|
6639
|
+
out = out.replace(/\b(?:ghp|ghs|gho|github_pat)_[A-Za-z0-9]{36,}\b/g, "[REDACTED]");
|
|
6640
|
+
out = out.replace(/\bsk-[A-Za-z0-9T-]{20,}\b/g, "[REDACTED]");
|
|
6641
|
+
out = out.replace(/\beyJ[A-Za-z0-9._-]{40,}\b/g, "[REDACTED]");
|
|
6642
|
+
return out;
|
|
6643
|
+
}
|
|
6644
|
+
function sanitizeCredentials(text2) {
|
|
6645
|
+
return applyRedaction(text2);
|
|
6646
|
+
}
|
|
6647
|
+
var init_secret_filter = __esm({
|
|
6648
|
+
"src/memory/secret-filter.ts"() {
|
|
6649
|
+
"use strict";
|
|
6650
|
+
init_esm_shims();
|
|
6651
|
+
}
|
|
6652
|
+
});
|
|
6653
|
+
|
|
6654
|
+
// src/search/derived-view-receipt.ts
|
|
6655
|
+
function sanitizeDerivedViewFailureReason(reason) {
|
|
6656
|
+
const safe = sanitizeCredentials(reason).replace(/(?:[A-Za-z]:[\\/]|\\\\[^\\/\s]+[\\/]|\/(?:home|Users|tmp|var|private|mnt|workspace|workspaces)\/)[^\s"'<>|]*/gi, "[path]").replace(/\s+/g, " ").trim();
|
|
6657
|
+
return safe.slice(0, 240) || "derived view failed";
|
|
6658
|
+
}
|
|
6659
|
+
function embeddingHealthReceipt(health, embeddingEnabled2) {
|
|
6660
|
+
if (health?.status === "disabled") {
|
|
6661
|
+
return { freshness: "current", rebuildStatus: "disabled" };
|
|
6662
|
+
}
|
|
6663
|
+
if (health?.status === "ready" || embeddingEnabled2) {
|
|
6664
|
+
return { freshness: "current", rebuildStatus: "idle" };
|
|
6665
|
+
}
|
|
6666
|
+
if (health?.status === "degraded") {
|
|
6667
|
+
return {
|
|
6668
|
+
freshness: "stale",
|
|
6669
|
+
rebuildStatus: "failed",
|
|
6670
|
+
...health.failure ? {
|
|
6671
|
+
failureReason: `embedding ${health.failure.kind}; retry in ${health.failure.retryAfterMs}ms`
|
|
6672
|
+
} : { failureReason: "embedding provider degraded" }
|
|
6673
|
+
};
|
|
6674
|
+
}
|
|
6675
|
+
return {
|
|
6676
|
+
freshness: "unknown",
|
|
6677
|
+
rebuildStatus: "unavailable",
|
|
6678
|
+
failureReason: "embedding provider is not initialized"
|
|
6679
|
+
};
|
|
6680
|
+
}
|
|
6681
|
+
var init_derived_view_receipt = __esm({
|
|
6682
|
+
"src/search/derived-view-receipt.ts"() {
|
|
6683
|
+
"use strict";
|
|
6684
|
+
init_esm_shims();
|
|
6685
|
+
init_secret_filter();
|
|
6686
|
+
}
|
|
6687
|
+
});
|
|
6688
|
+
|
|
6553
6689
|
// src/project/aliases.ts
|
|
6554
6690
|
var aliases_exports = {};
|
|
6555
6691
|
__export(aliases_exports, {
|
|
@@ -7158,6 +7294,7 @@ __export(orama_store_exports, {
|
|
|
7158
7294
|
getLastSearchMode: () => getLastSearchMode,
|
|
7159
7295
|
getObservationCount: () => getObservationCount,
|
|
7160
7296
|
getObservationsByIds: () => getObservationsByIds,
|
|
7297
|
+
getPersistentSemanticVectorIds: () => getPersistentSemanticVectorIds,
|
|
7161
7298
|
getSearchDerivedViews: () => getSearchDerivedViews,
|
|
7162
7299
|
getTimeline: () => getTimeline,
|
|
7163
7300
|
getVectorDimensions: () => getVectorDimensions,
|
|
@@ -7170,10 +7307,18 @@ __export(orama_store_exports, {
|
|
|
7170
7307
|
queueSemanticVector: () => queueSemanticVector,
|
|
7171
7308
|
removeObservation: () => removeObservation,
|
|
7172
7309
|
resetDb: () => resetDb,
|
|
7310
|
+
resolveSearchFuzzyTolerance: () => resolveSearchFuzzyTolerance,
|
|
7173
7311
|
searchObservations: () => searchObservations,
|
|
7174
7312
|
updateObservationMetadata: () => updateObservationMetadata
|
|
7175
7313
|
});
|
|
7176
7314
|
import { components, create, insert as insert2, insertMultiple, search, remove as remove2, update, count, getByID } from "@orama/orama";
|
|
7315
|
+
function resolveSearchFuzzyTolerance(query, quality) {
|
|
7316
|
+
if (quality === "fast") return void 0;
|
|
7317
|
+
const characters = [...query];
|
|
7318
|
+
const cjkCount = characters.filter((char) => /[\u3400-\u4dbf\u4e00-\u9fff\u3040-\u30ff\uac00-\ud7af]/u.test(char)).length;
|
|
7319
|
+
if (characters.length > 0 && cjkCount / characters.length > 0.3) return void 0;
|
|
7320
|
+
return query.length > 6 ? 2 : 1;
|
|
7321
|
+
}
|
|
7177
7322
|
function rememberSearchMode(key, value) {
|
|
7178
7323
|
if (!lastSearchModeByProject.has(key) && lastSearchModeByProject.size >= MAX_SEARCH_MODE_KEYS) {
|
|
7179
7324
|
const oldest = lastSearchModeByProject.keys().next().value;
|
|
@@ -7202,14 +7347,16 @@ function getSearchDerivedViews() {
|
|
|
7202
7347
|
generation,
|
|
7203
7348
|
freshness: "unknown",
|
|
7204
7349
|
rebuildStatus: "unavailable",
|
|
7205
|
-
failureReason:
|
|
7350
|
+
failureReason: sanitizeDerivedViewFailureReason(
|
|
7351
|
+
store.getBackendReason?.() ?? "persistent lexical index unavailable"
|
|
7352
|
+
)
|
|
7206
7353
|
};
|
|
7207
7354
|
}
|
|
7208
7355
|
} catch (error) {
|
|
7209
7356
|
views.fts = {
|
|
7210
7357
|
freshness: "unknown",
|
|
7211
7358
|
rebuildStatus: "failed",
|
|
7212
|
-
failureReason: error instanceof Error ? error.message
|
|
7359
|
+
failureReason: sanitizeDerivedViewFailureReason(error instanceof Error ? error.message : String(error))
|
|
7213
7360
|
};
|
|
7214
7361
|
}
|
|
7215
7362
|
} else {
|
|
@@ -7225,18 +7372,12 @@ function getSearchDerivedViews() {
|
|
|
7225
7372
|
rebuildStatus: "unavailable",
|
|
7226
7373
|
failureReason: "Orama index is not initialized"
|
|
7227
7374
|
};
|
|
7228
|
-
|
|
7229
|
-
|
|
7230
|
-
|
|
7231
|
-
}
|
|
7232
|
-
views.embedding = { freshness: "current", rebuildStatus: "idle" };
|
|
7233
|
-
} else {
|
|
7234
|
-
views.embedding = {
|
|
7235
|
-
freshness: "unknown",
|
|
7236
|
-
rebuildStatus: "unavailable",
|
|
7237
|
-
failureReason: "embedding provider is not initialized"
|
|
7238
|
-
};
|
|
7375
|
+
let embeddingHealth;
|
|
7376
|
+
try {
|
|
7377
|
+
embeddingHealth = getEmbeddingRuntimeHealth?.();
|
|
7378
|
+
} catch {
|
|
7239
7379
|
}
|
|
7380
|
+
views.embedding = embeddingHealthReceipt(embeddingHealth, embeddingEnabled);
|
|
7240
7381
|
return views;
|
|
7241
7382
|
}
|
|
7242
7383
|
function rememberSearchDiagnostics(key, value) {
|
|
@@ -7540,12 +7681,16 @@ function getVectorDimensions() {
|
|
|
7540
7681
|
function getActiveSemanticIndexProfile() {
|
|
7541
7682
|
return indexEmbeddingProvider ? createSemanticIndexProfile(indexEmbeddingProvider) : null;
|
|
7542
7683
|
}
|
|
7684
|
+
async function getPersistentSemanticVectorIds(dataDir) {
|
|
7685
|
+
if (!indexEmbeddingProvider) return null;
|
|
7686
|
+
return listSemanticVectorIds(dataDir, createSemanticIndexProfile(indexEmbeddingProvider));
|
|
7687
|
+
}
|
|
7543
7688
|
async function queueSemanticVector(dataDir, record80) {
|
|
7544
7689
|
const provider2 = indexEmbeddingProvider ?? await getEmbeddingProvider();
|
|
7545
7690
|
const profile = provider2 ? createSemanticIndexProfile(provider2) : null;
|
|
7546
7691
|
if (!profile) return;
|
|
7547
7692
|
try {
|
|
7548
|
-
await
|
|
7693
|
+
await upsertSemanticVector(dataDir, profile, record80);
|
|
7549
7694
|
} catch {
|
|
7550
7695
|
}
|
|
7551
7696
|
}
|
|
@@ -7607,6 +7752,7 @@ function isCompatibleCachedVector(vector) {
|
|
|
7607
7752
|
async function attachCachedVectors(database, observations2) {
|
|
7608
7753
|
const semanticDataDir = (await Promise.resolve().then(() => (init_observations(), observations_exports))).getObservationDataDir();
|
|
7609
7754
|
const semanticProfile = getActiveSemanticIndexProfile();
|
|
7755
|
+
const persistedSemanticIds = semanticDataDir && semanticProfile ? await listSemanticVectorIds(semanticDataDir, semanticProfile).catch(() => null) : null;
|
|
7610
7756
|
const batchSize = 200;
|
|
7611
7757
|
for (let start = 0; start < observations2.length; start += batchSize) {
|
|
7612
7758
|
const batch = observations2.slice(start, start + batchSize);
|
|
@@ -7617,7 +7763,7 @@ async function attachCachedVectors(database, observations2) {
|
|
|
7617
7763
|
const vector = cachedVectors[index];
|
|
7618
7764
|
if (!isCompatibleCachedVector(vector)) continue;
|
|
7619
7765
|
const observation = batch[index];
|
|
7620
|
-
if (semanticDataDir && semanticProfile) {
|
|
7766
|
+
if (semanticDataDir && semanticProfile && !persistedSemanticIds?.has(observation.id)) {
|
|
7621
7767
|
semanticRecords.push({
|
|
7622
7768
|
observationId: observation.id,
|
|
7623
7769
|
projectId: observation.projectId,
|
|
@@ -7818,7 +7964,10 @@ async function searchObservations(options) {
|
|
|
7818
7964
|
// Fuzzy tolerance: allow 1-char typos for short queries, 2 for longer
|
|
7819
7965
|
// Fuzzy matching is useful for ordinary recall, but grows sharply with
|
|
7820
7966
|
// corpus size. The fast profile deliberately uses exact lexical matching.
|
|
7821
|
-
...hasQuery
|
|
7967
|
+
...hasQuery ? (() => {
|
|
7968
|
+
const tolerance = resolveSearchFuzzyTolerance(originalQuery, quality);
|
|
7969
|
+
return tolerance === void 0 ? {} : { tolerance };
|
|
7970
|
+
})() : {}
|
|
7822
7971
|
};
|
|
7823
7972
|
let queryVector = null;
|
|
7824
7973
|
let embeddingProviderForSearch = null;
|
|
@@ -8049,14 +8198,16 @@ async function searchObservations(options) {
|
|
|
8049
8198
|
filesModified: doc.filesModified?.split?.("\n") ?? (Array.isArray(doc.filesModified) ? doc.filesModified : [])
|
|
8050
8199
|
});
|
|
8051
8200
|
}
|
|
8201
|
+
const topScore = Math.max(...intermediate.map((entry) => entry.score));
|
|
8202
|
+
const affinityTieWindow = topScore * 0.92;
|
|
8052
8203
|
intermediate = intermediate.map((entry) => {
|
|
8053
8204
|
const memory = memoryContentMap.get(entry.id);
|
|
8054
8205
|
if (!memory) return entry;
|
|
8055
8206
|
const { score: affinityScore } = calculateProjectAffinity(memory, affinityContext);
|
|
8207
|
+
if (entry.score < affinityTieWindow) return entry;
|
|
8056
8208
|
return {
|
|
8057
8209
|
...entry,
|
|
8058
|
-
score: entry.score * affinityScore
|
|
8059
|
-
// Apply affinity as multiplier
|
|
8210
|
+
score: entry.score * (0.98 + affinityScore * 0.02)
|
|
8060
8211
|
};
|
|
8061
8212
|
});
|
|
8062
8213
|
intermediate.sort((a, b) => b.score - a.score);
|
|
@@ -8390,6 +8541,7 @@ var init_orama_store = __esm({
|
|
|
8390
8541
|
init_mini_skills();
|
|
8391
8542
|
init_visibility();
|
|
8392
8543
|
init_provider();
|
|
8544
|
+
init_provider();
|
|
8393
8545
|
init_project_affinity();
|
|
8394
8546
|
init_intent_detector();
|
|
8395
8547
|
init_query_expansion();
|
|
@@ -8397,6 +8549,7 @@ var init_orama_store = __esm({
|
|
|
8397
8549
|
init_timeout();
|
|
8398
8550
|
init_obs_store();
|
|
8399
8551
|
init_semantic_index();
|
|
8552
|
+
init_derived_view_receipt();
|
|
8400
8553
|
db = null;
|
|
8401
8554
|
dbInitPromise = null;
|
|
8402
8555
|
dbGeneration = 0;
|
|
@@ -8521,33 +8674,6 @@ var init_entity_extractor = __esm({
|
|
|
8521
8674
|
}
|
|
8522
8675
|
});
|
|
8523
8676
|
|
|
8524
|
-
// src/memory/secret-filter.ts
|
|
8525
|
-
function applyRedaction(text2) {
|
|
8526
|
-
if (!text2) return text2;
|
|
8527
|
-
let out = text2;
|
|
8528
|
-
out = out.replace(
|
|
8529
|
-
/((?:password|passwd|pwd|secret|token|api[_-]?key|auth[_-]?key|access[_-]?key|private[_-]?key|client[_-]?secret)\s*[:=]\s*["']?)([^\s"',;\n]{6,})/gi,
|
|
8530
|
-
"$1[REDACTED]"
|
|
8531
|
-
);
|
|
8532
|
-
out = out.replace(
|
|
8533
|
-
/(Bearer\s+)([A-Za-z0-9._\-/+]{20,})/g,
|
|
8534
|
-
"$1[REDACTED]"
|
|
8535
|
-
);
|
|
8536
|
-
out = out.replace(/\b(?:ghp|ghs|gho|github_pat)_[A-Za-z0-9]{36,}\b/g, "[REDACTED]");
|
|
8537
|
-
out = out.replace(/\bsk-[A-Za-z0-9T-]{20,}\b/g, "[REDACTED]");
|
|
8538
|
-
out = out.replace(/\beyJ[A-Za-z0-9._-]{40,}\b/g, "[REDACTED]");
|
|
8539
|
-
return out;
|
|
8540
|
-
}
|
|
8541
|
-
function sanitizeCredentials(text2) {
|
|
8542
|
-
return applyRedaction(text2);
|
|
8543
|
-
}
|
|
8544
|
-
var init_secret_filter = __esm({
|
|
8545
|
-
"src/memory/secret-filter.ts"() {
|
|
8546
|
-
"use strict";
|
|
8547
|
-
init_esm_shims();
|
|
8548
|
-
}
|
|
8549
|
-
});
|
|
8550
|
-
|
|
8551
8677
|
// src/runtime/maintenance-jobs.ts
|
|
8552
8678
|
var maintenance_jobs_exports = {};
|
|
8553
8679
|
__export(maintenance_jobs_exports, {
|
|
@@ -144126,7 +144252,7 @@ __export(video_jobs_exports, {
|
|
|
144126
144252
|
runMiniMaxVideoGenerationJob: () => runMiniMaxVideoGenerationJob
|
|
144127
144253
|
});
|
|
144128
144254
|
import { spawn } from "child_process";
|
|
144129
|
-
import { existsSync as
|
|
144255
|
+
import { existsSync as existsSync9 } from "fs";
|
|
144130
144256
|
import path15 from "path";
|
|
144131
144257
|
import { fileURLToPath as fileURLToPath2 } from "url";
|
|
144132
144258
|
function safeError2(error) {
|
|
@@ -144374,7 +144500,7 @@ function resolveMediaVideoRunnerPath(moduleUrl = import.meta.url) {
|
|
|
144374
144500
|
}
|
|
144375
144501
|
function launchMediaVideoRunner(request, options = {}) {
|
|
144376
144502
|
const runnerPath = options.runnerPath ?? resolveMediaVideoRunnerPath();
|
|
144377
|
-
if (!
|
|
144503
|
+
if (!existsSync9(runnerPath)) {
|
|
144378
144504
|
return { launched: false, reason: "Media video runner is unavailable until Memorix is built or reinstalled." };
|
|
144379
144505
|
}
|
|
144380
144506
|
try {
|
|
@@ -144419,7 +144545,7 @@ __export(audio_jobs_exports, {
|
|
|
144419
144545
|
transcribeAudio: () => transcribeAudio
|
|
144420
144546
|
});
|
|
144421
144547
|
import { spawn as spawn2 } from "child_process";
|
|
144422
|
-
import { existsSync as
|
|
144548
|
+
import { existsSync as existsSync10 } from "fs";
|
|
144423
144549
|
import path16 from "path";
|
|
144424
144550
|
import { fileURLToPath as fileURLToPath3 } from "url";
|
|
144425
144551
|
function safeError3(error) {
|
|
@@ -144670,7 +144796,7 @@ function resolveMediaAudioRunnerPath(moduleUrl = import.meta.url) {
|
|
|
144670
144796
|
}
|
|
144671
144797
|
function launchMediaAudioRunner(request, options = {}) {
|
|
144672
144798
|
const runnerPath = options.runnerPath ?? resolveMediaAudioRunnerPath();
|
|
144673
|
-
if (!
|
|
144799
|
+
if (!existsSync10(runnerPath)) return { launched: false, reason: "Audio runner is unavailable until Memorix is built or reinstalled." };
|
|
144674
144800
|
try {
|
|
144675
144801
|
const child = spawn2(process.execPath, [runnerPath, JSON.stringify(request)], {
|
|
144676
144802
|
cwd: request.projectRoot,
|
|
@@ -147079,6 +147205,7 @@ var init_store = __esm({
|
|
|
147079
147205
|
recordCodeStateSnapshot(input) {
|
|
147080
147206
|
const id = randomUUID11();
|
|
147081
147207
|
let snapshot;
|
|
147208
|
+
let compactNeeded = false;
|
|
147082
147209
|
const tx = this.db.transaction(() => {
|
|
147083
147210
|
const previous = this.db.prepare(
|
|
147084
147211
|
"SELECT id, sourceEpoch FROM code_state_snapshots WHERE projectId = ? ORDER BY sourceEpoch DESC LIMIT 1"
|
|
@@ -147122,6 +147249,26 @@ var init_store = __esm({
|
|
|
147122
147249
|
for (const file of snapshotFileRows) {
|
|
147123
147250
|
insertSnapshotFile.run(id, file.projectId, file.id, file.path, file.contentHash);
|
|
147124
147251
|
}
|
|
147252
|
+
const staleSymbolIds = this.db.prepare(
|
|
147253
|
+
"SELECT id FROM code_symbols WHERE projectId = ? AND stale = 1"
|
|
147254
|
+
).all(input.projectId).map((row) => row.id);
|
|
147255
|
+
if (staleSymbolIds.length > 0) {
|
|
147256
|
+
const placeholders = staleSymbolIds.map(() => "?").join(", ");
|
|
147257
|
+
this.db.prepare(
|
|
147258
|
+
`DELETE FROM code_edges WHERE projectId = ? AND (fromSymbolId IN (${placeholders}) OR toSymbolId IN (${placeholders}))`
|
|
147259
|
+
).run(input.projectId, ...staleSymbolIds, ...staleSymbolIds);
|
|
147260
|
+
this.db.prepare("DELETE FROM code_symbols WHERE projectId = ? AND stale = 1").run(input.projectId);
|
|
147261
|
+
compactNeeded = true;
|
|
147262
|
+
}
|
|
147263
|
+
const oldSnapshots = this.db.prepare(
|
|
147264
|
+
"SELECT id FROM code_state_snapshots WHERE projectId = ? ORDER BY sourceEpoch DESC LIMIT -1 OFFSET 2"
|
|
147265
|
+
).all(input.projectId).map((row) => row.id);
|
|
147266
|
+
if (oldSnapshots.length > 0) {
|
|
147267
|
+
const placeholders = oldSnapshots.map(() => "?").join(", ");
|
|
147268
|
+
this.db.prepare(`DELETE FROM code_state_snapshot_files WHERE snapshotId IN (${placeholders})`).run(...oldSnapshots);
|
|
147269
|
+
this.db.prepare(`DELETE FROM code_state_snapshots WHERE id IN (${placeholders})`).run(...oldSnapshots);
|
|
147270
|
+
compactNeeded = true;
|
|
147271
|
+
}
|
|
147125
147272
|
snapshot = {
|
|
147126
147273
|
...input,
|
|
147127
147274
|
id,
|
|
@@ -147130,11 +147277,24 @@ var init_store = __esm({
|
|
|
147130
147277
|
};
|
|
147131
147278
|
});
|
|
147132
147279
|
tx();
|
|
147280
|
+
if (compactNeeded) this.compactStorage();
|
|
147133
147281
|
return snapshot;
|
|
147134
147282
|
}
|
|
147283
|
+
/** Reclaim WAL/free pages after a derived codegraph sweep. */
|
|
147284
|
+
compactStorage() {
|
|
147285
|
+
try {
|
|
147286
|
+
this.db.pragma("wal_checkpoint(TRUNCATE)");
|
|
147287
|
+
} catch {
|
|
147288
|
+
}
|
|
147289
|
+
try {
|
|
147290
|
+
this.db.exec("VACUUM");
|
|
147291
|
+
} catch {
|
|
147292
|
+
}
|
|
147293
|
+
}
|
|
147135
147294
|
status(projectId) {
|
|
147136
147295
|
const files = this.db.prepare(`SELECT COUNT(*) AS count FROM code_files WHERE projectId = ?`).get(projectId).count;
|
|
147137
147296
|
const symbols = this.db.prepare(`SELECT COUNT(*) AS count FROM code_symbols WHERE projectId = ? AND stale = 0`).get(projectId).count;
|
|
147297
|
+
const staleSymbols = this.db.prepare(`SELECT COUNT(*) AS count FROM code_symbols WHERE projectId = ? AND stale = 1`).get(projectId).count;
|
|
147138
147298
|
const edges = this.db.prepare(`SELECT COUNT(*) AS count FROM code_edges WHERE projectId = ?`).get(projectId).count;
|
|
147139
147299
|
const refs = this.db.prepare(`SELECT COUNT(*) AS count FROM observation_code_refs WHERE projectId = ?`).get(projectId).count;
|
|
147140
147300
|
const semanticSymbols = this.db.prepare(`SELECT COUNT(*) AS count FROM code_symbols WHERE projectId = ? AND stale = 0 AND source = 'typescript-compiler'`).get(projectId).count;
|
|
@@ -147142,6 +147302,8 @@ var init_store = __esm({
|
|
|
147142
147302
|
const parserErrors = this.db.prepare(`SELECT COUNT(*) AS count FROM code_files WHERE projectId = ? AND parserError IS NOT NULL`).get(projectId).count;
|
|
147143
147303
|
const latest = this.db.prepare(`SELECT MAX(indexedAt) AS indexedAt FROM code_files WHERE projectId = ?`).get(projectId);
|
|
147144
147304
|
const latestSnapshot = this.latestSnapshot(projectId);
|
|
147305
|
+
const snapshots = this.db.prepare(`SELECT COUNT(*) AS count FROM code_state_snapshots WHERE projectId = ?`).get(projectId).count;
|
|
147306
|
+
const snapshotFiles = this.db.prepare(`SELECT COUNT(*) AS count FROM code_state_snapshot_files WHERE projectId = ?`).get(projectId).count;
|
|
147145
147307
|
return {
|
|
147146
147308
|
provider: "lite",
|
|
147147
147309
|
files,
|
|
@@ -147151,6 +147313,9 @@ var init_store = __esm({
|
|
|
147151
147313
|
semanticSymbols,
|
|
147152
147314
|
semanticEdges,
|
|
147153
147315
|
parserErrors,
|
|
147316
|
+
staleSymbols,
|
|
147317
|
+
snapshots,
|
|
147318
|
+
snapshotFiles,
|
|
147154
147319
|
...latest?.indexedAt ? { indexedAt: latest.indexedAt } : {},
|
|
147155
147320
|
...latestSnapshot ? { latestSnapshot } : {}
|
|
147156
147321
|
};
|
|
@@ -147635,7 +147800,7 @@ __export(lite_provider_exports, {
|
|
|
147635
147800
|
refreshProjectLite: () => refreshProjectLite
|
|
147636
147801
|
});
|
|
147637
147802
|
import { createHash as createHash11 } from "crypto";
|
|
147638
|
-
import { existsSync as
|
|
147803
|
+
import { existsSync as existsSync12, readdirSync as readdirSync2, readFileSync as readFileSync8, statSync as statSync3 } from "fs";
|
|
147639
147804
|
import { join as join4, relative as relative2 } from "path";
|
|
147640
147805
|
function hashText2(text2) {
|
|
147641
147806
|
return createHash11("sha256").update(text2).digest("hex");
|
|
@@ -147653,7 +147818,7 @@ function resolveMaxFileBytes(value) {
|
|
|
147653
147818
|
return Math.max(1, Math.floor(value));
|
|
147654
147819
|
}
|
|
147655
147820
|
function isPythonVirtualenvDir(dir) {
|
|
147656
|
-
return
|
|
147821
|
+
return existsSync12(join4(dir, "pyvenv.cfg"));
|
|
147657
147822
|
}
|
|
147658
147823
|
function walk(root, exclude, maxFiles) {
|
|
147659
147824
|
const out = [];
|
|
@@ -151192,7 +151357,7 @@ __export(vector_backfill_runner_exports, {
|
|
|
151192
151357
|
import { spawn as spawn3 } from "child_process";
|
|
151193
151358
|
import {
|
|
151194
151359
|
closeSync,
|
|
151195
|
-
existsSync as
|
|
151360
|
+
existsSync as existsSync13,
|
|
151196
151361
|
mkdirSync as mkdirSync2,
|
|
151197
151362
|
openSync,
|
|
151198
151363
|
readFileSync as readFileSync9,
|
|
@@ -151320,7 +151485,7 @@ function releaseVectorBackfillLock(lockPath = process.env.MEMORIX_VECTOR_BACKFIL
|
|
|
151320
151485
|
}
|
|
151321
151486
|
function launchDetachedVectorBackfill(request, options = {}) {
|
|
151322
151487
|
const runnerPath = options.runnerPath ?? resolveVectorBackfillRunnerPath();
|
|
151323
|
-
const exists = options.exists ??
|
|
151488
|
+
const exists = options.exists ?? existsSync13;
|
|
151324
151489
|
if (!exists(runnerPath)) return false;
|
|
151325
151490
|
const lock = acquireVectorBackfillLock(request.dataDir, request.projectId, options.lockPath);
|
|
151326
151491
|
if (!lock) return false;
|
|
@@ -151476,10 +151641,22 @@ function resetObservationRuntime() {
|
|
|
151476
151641
|
loadedObservationStore = null;
|
|
151477
151642
|
embeddingWriteMode = "background";
|
|
151478
151643
|
embeddingWorkerProjectRoot = void 0;
|
|
151479
|
-
|
|
151644
|
+
clearVectorMissingIds();
|
|
151480
151645
|
vectorSchemaUpgradePromise = null;
|
|
151481
151646
|
embeddingFailureLogTimestamps.clear();
|
|
151482
151647
|
}
|
|
151648
|
+
function markVectorMissing(observationId2, projectId) {
|
|
151649
|
+
vectorMissingIds.add(observationId2);
|
|
151650
|
+
vectorMissingProjectIds.set(observationId2, projectId);
|
|
151651
|
+
}
|
|
151652
|
+
function clearVectorMissing(observationId2) {
|
|
151653
|
+
vectorMissingIds.delete(observationId2);
|
|
151654
|
+
vectorMissingProjectIds.delete(observationId2);
|
|
151655
|
+
}
|
|
151656
|
+
function clearVectorMissingIds() {
|
|
151657
|
+
vectorMissingIds.clear();
|
|
151658
|
+
vectorMissingProjectIds.clear();
|
|
151659
|
+
}
|
|
151483
151660
|
function logEmbeddingFailureOnce(key, message) {
|
|
151484
151661
|
const now3 = Date.now();
|
|
151485
151662
|
const last = embeddingFailureLogTimestamps.get(key) ?? 0;
|
|
@@ -151599,10 +151776,13 @@ function isVectorCompatibleWithCurrentIndex(embedding) {
|
|
|
151599
151776
|
}
|
|
151600
151777
|
async function upgradeVectorSchemaAfterFirstEmbedding(embedding) {
|
|
151601
151778
|
if (isVectorCompatibleWithCurrentIndex(embedding)) return true;
|
|
151602
|
-
if (
|
|
151779
|
+
if (!embedding.every(Number.isFinite)) return false;
|
|
151603
151780
|
const targetProjectDir = projectDir;
|
|
151604
151781
|
if (!vectorSchemaUpgradePromise) {
|
|
151605
|
-
vectorSchemaUpgradePromise =
|
|
151782
|
+
vectorSchemaUpgradePromise = getDb().then(async () => {
|
|
151783
|
+
if (getVectorDimensions() === null && observations.length > 0) await reindexObservations();
|
|
151784
|
+
return projectDir === targetProjectDir && isVectorCompatibleWithCurrentIndex(embedding);
|
|
151785
|
+
}).catch(() => false).finally(() => {
|
|
151606
151786
|
vectorSchemaUpgradePromise = null;
|
|
151607
151787
|
});
|
|
151608
151788
|
}
|
|
@@ -151642,9 +151822,9 @@ async function initObservations(dir, options = {}) {
|
|
|
151642
151822
|
}
|
|
151643
151823
|
function scheduleObservationEmbedding(input) {
|
|
151644
151824
|
const { observationId: observationId2, projectId, searchableText, doc } = input;
|
|
151645
|
-
|
|
151825
|
+
markVectorMissing(observationId2, projectId);
|
|
151646
151826
|
if (isEmbeddingExplicitlyDisabled()) {
|
|
151647
|
-
|
|
151827
|
+
clearVectorMissing(observationId2);
|
|
151648
151828
|
return;
|
|
151649
151829
|
}
|
|
151650
151830
|
if (embeddingWriteMode === "deferred") {
|
|
@@ -151679,13 +151859,13 @@ function scheduleObservationEmbedding(input) {
|
|
|
151679
151859
|
vector: embedding
|
|
151680
151860
|
});
|
|
151681
151861
|
}
|
|
151682
|
-
|
|
151862
|
+
clearVectorMissing(observationId2);
|
|
151683
151863
|
} catch {
|
|
151684
151864
|
console.error(`[memorix] Embedding index update failed for obs-${observationId2} (kept in backfill queue)`);
|
|
151685
151865
|
queueVectorBackfill(projectId);
|
|
151686
151866
|
}
|
|
151687
151867
|
} else if (isEmbeddingExplicitlyDisabled()) {
|
|
151688
|
-
|
|
151868
|
+
clearVectorMissing(observationId2);
|
|
151689
151869
|
} else {
|
|
151690
151870
|
queueVectorBackfill(projectId);
|
|
151691
151871
|
logEmbeddingFailureOnce(
|
|
@@ -152245,7 +152425,7 @@ async function reindexObservations() {
|
|
|
152245
152425
|
if (observations.length === 0) return 0;
|
|
152246
152426
|
await resetDb();
|
|
152247
152427
|
searchIndexPrepared = false;
|
|
152248
|
-
|
|
152428
|
+
clearVectorMissingIds();
|
|
152249
152429
|
let embeddings = observations.map(() => null);
|
|
152250
152430
|
const provider2 = await getEmbeddingProvider();
|
|
152251
152431
|
const canBatchEmbedAtStartup = provider2 !== null && !provider2.name.startsWith("api-");
|
|
@@ -152310,7 +152490,7 @@ async function reindexObservations() {
|
|
|
152310
152490
|
};
|
|
152311
152491
|
await insertObservation(doc);
|
|
152312
152492
|
if (!compatibleEmbedding && !isEmbeddingExplicitlyDisabled()) {
|
|
152313
|
-
|
|
152493
|
+
markVectorMissing(obs.id, obs.projectId);
|
|
152314
152494
|
}
|
|
152315
152495
|
count2++;
|
|
152316
152496
|
} catch (err) {
|
|
@@ -152327,7 +152507,17 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152327
152507
|
if (!isEmbeddingExplicitlyDisabled()) {
|
|
152328
152508
|
const store = getObservationStore();
|
|
152329
152509
|
const projects = await store.listProjectIds?.() ?? [];
|
|
152330
|
-
|
|
152510
|
+
await getDb({ allowNetworkProbe: false }).catch(() => void 0);
|
|
152511
|
+
const persistedIds = projectDir ? await getPersistentSemanticVectorIds(projectDir).catch(() => null) : null;
|
|
152512
|
+
for (const projectId of projects) {
|
|
152513
|
+
const projectObservations = await store.loadByProject(projectId);
|
|
152514
|
+
for (const observation of projectObservations) {
|
|
152515
|
+
if (!persistedIds?.has(observation.id)) markVectorMissing(observation.id, observation.projectId);
|
|
152516
|
+
}
|
|
152517
|
+
if (projectObservations.some((observation) => !persistedIds?.has(observation.id))) {
|
|
152518
|
+
queueVectorBackfill(projectId);
|
|
152519
|
+
}
|
|
152520
|
+
}
|
|
152331
152521
|
}
|
|
152332
152522
|
return 0;
|
|
152333
152523
|
}
|
|
@@ -152339,14 +152529,15 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152339
152529
|
return 0;
|
|
152340
152530
|
}
|
|
152341
152531
|
const hydratedProjectDir = projectDir;
|
|
152342
|
-
const queueMissingVectors = () => {
|
|
152343
|
-
if (projectDir !== hydratedProjectDir) return;
|
|
152344
|
-
|
|
152532
|
+
const queueMissingVectors = async () => {
|
|
152533
|
+
if (!hydratedProjectDir || projectDir !== hydratedProjectDir) return;
|
|
152534
|
+
clearVectorMissingIds();
|
|
152345
152535
|
if (!isEmbeddingExplicitlyDisabled()) {
|
|
152536
|
+
const persistedSemanticIds = await getPersistentSemanticVectorIds(hydratedProjectDir).catch(() => null);
|
|
152346
152537
|
const projectsWithMissingVectors = /* @__PURE__ */ new Set();
|
|
152347
152538
|
for (const obs of observations) {
|
|
152348
|
-
if (!hasObservationVector(obs.projectId, obs.id)) {
|
|
152349
|
-
|
|
152539
|
+
if (!hasObservationVector(obs.projectId, obs.id) && !persistedSemanticIds?.has(obs.id)) {
|
|
152540
|
+
markVectorMissing(obs.id, obs.projectId);
|
|
152350
152541
|
projectsWithMissingVectors.add(obs.projectId);
|
|
152351
152542
|
}
|
|
152352
152543
|
}
|
|
@@ -152355,15 +152546,18 @@ async function prepareSearchIndex(options = {}) {
|
|
|
152355
152546
|
};
|
|
152356
152547
|
const cacheHydration = getDeferredCachedVectorHydration();
|
|
152357
152548
|
if (cacheHydration) {
|
|
152358
|
-
void cacheHydration.
|
|
152549
|
+
void cacheHydration.then(queueMissingVectors, queueMissingVectors).catch(() => void 0);
|
|
152359
152550
|
} else {
|
|
152360
|
-
queueMissingVectors();
|
|
152551
|
+
await queueMissingVectors();
|
|
152361
152552
|
}
|
|
152362
152553
|
searchIndexPrepared = true;
|
|
152363
152554
|
return count2;
|
|
152364
152555
|
}
|
|
152365
152556
|
function getVectorMissingIds(projectId) {
|
|
152366
152557
|
if (!projectId) return [...vectorMissingIds];
|
|
152558
|
+
if (!corpusLoaded) {
|
|
152559
|
+
return [...vectorMissingIds].filter((id) => vectorMissingProjectIds.get(id) === projectId);
|
|
152560
|
+
}
|
|
152367
152561
|
const observationById = new Map(observations.map((observation) => [observation.id, observation]));
|
|
152368
152562
|
return [...vectorMissingIds].filter((id) => observationById.get(id)?.projectId === projectId);
|
|
152369
152563
|
}
|
|
@@ -152401,7 +152595,8 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152401
152595
|
return { attempted: 0, succeeded: 0, failed: 0 };
|
|
152402
152596
|
}
|
|
152403
152597
|
vectorBackfillRunning = true;
|
|
152404
|
-
const
|
|
152598
|
+
const sourceObservations = corpusLoaded ? observations : options.projectId ? await getObservationStore().loadByProject(options.projectId, { status: "active" }) : await getObservationStore().loadAll();
|
|
152599
|
+
const observationById = new Map(sourceObservations.map((observation) => [observation.id, observation]));
|
|
152405
152600
|
const limit2 = Number.isFinite(options.limit) ? Math.max(1, Math.floor(options.limit)) : Number.POSITIVE_INFINITY;
|
|
152406
152601
|
const ids = [...vectorMissingIds].filter((id) => !options.projectId || observationById.get(id)?.projectId === options.projectId).slice(0, limit2);
|
|
152407
152602
|
let succeeded = 0;
|
|
@@ -152414,7 +152609,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152414
152609
|
for (const id of ids) {
|
|
152415
152610
|
const observation = observationById.get(id);
|
|
152416
152611
|
if (!observation) {
|
|
152417
|
-
|
|
152612
|
+
clearVectorMissing(id);
|
|
152418
152613
|
continue;
|
|
152419
152614
|
}
|
|
152420
152615
|
candidates.push({
|
|
@@ -152432,7 +152627,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152432
152627
|
const provider2 = await getEmbeddingProvider();
|
|
152433
152628
|
if (!provider2) {
|
|
152434
152629
|
if (isEmbeddingExplicitlyDisabled()) {
|
|
152435
|
-
for (const candidate of candidates)
|
|
152630
|
+
for (const candidate of candidates) clearVectorMissing(candidate.id);
|
|
152436
152631
|
} else {
|
|
152437
152632
|
recordFailure("embedding provider unavailable");
|
|
152438
152633
|
failed += candidates.length;
|
|
@@ -152509,7 +152704,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152509
152704
|
vector: embedding
|
|
152510
152705
|
});
|
|
152511
152706
|
}
|
|
152512
|
-
|
|
152707
|
+
clearVectorMissing(id);
|
|
152513
152708
|
succeeded++;
|
|
152514
152709
|
} catch (error) {
|
|
152515
152710
|
recordFailure(vectorBackfillError(error));
|
|
@@ -152534,7 +152729,7 @@ async function backfillVectorEmbeddings(options = {}) {
|
|
|
152534
152729
|
...lastFailure ? { lastError: lastFailure } : {}
|
|
152535
152730
|
};
|
|
152536
152731
|
}
|
|
152537
|
-
var observations, nextId, projectDir, searchIndexPrepared, embeddingWriteMode, embeddingWorkerProjectRoot, corpusLoaded, largeCorpusLazyMode, loadedObservationStore, DEFAULT_ORAMA_HYDRATION_THRESHOLD, vectorMissingIds, vectorBackfillRunning, vectorSchemaUpgradePromise, lastVectorBackfill, embeddingFailureLogTimestamps, EMBEDDING_FAILURE_LOG_COOLDOWN_MS, MAX_EMBEDDING_FAILURE_KEYS;
|
|
152732
|
+
var observations, nextId, projectDir, searchIndexPrepared, embeddingWriteMode, embeddingWorkerProjectRoot, corpusLoaded, largeCorpusLazyMode, loadedObservationStore, DEFAULT_ORAMA_HYDRATION_THRESHOLD, vectorMissingIds, vectorMissingProjectIds, vectorBackfillRunning, vectorSchemaUpgradePromise, lastVectorBackfill, embeddingFailureLogTimestamps, EMBEDDING_FAILURE_LOG_COOLDOWN_MS, MAX_EMBEDDING_FAILURE_KEYS;
|
|
152538
152733
|
var init_observations = __esm({
|
|
152539
152734
|
"src/memory/observations.ts"() {
|
|
152540
152735
|
"use strict";
|
|
@@ -152559,6 +152754,7 @@ var init_observations = __esm({
|
|
|
152559
152754
|
loadedObservationStore = null;
|
|
152560
152755
|
DEFAULT_ORAMA_HYDRATION_THRESHOLD = 1e4;
|
|
152561
152756
|
vectorMissingIds = /* @__PURE__ */ new Set();
|
|
152757
|
+
vectorMissingProjectIds = /* @__PURE__ */ new Map();
|
|
152562
152758
|
vectorBackfillRunning = false;
|
|
152563
152759
|
vectorSchemaUpgradePromise = null;
|
|
152564
152760
|
lastVectorBackfill = null;
|