@agentmemory/agentmemory 0.9.10 → 0.9.12

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.
@@ -1,5 +1,5 @@
1
1
  import { a as jaccardSimilarity, i as generateId, n as STREAM, r as fingerprintId, t as KV } from "./cli.mjs";
2
- import { _ as loadSnapshotConfig, a as detectLlmProviderKind, d as isContextInjectionEnabled, f as isGraphExtractionEnabled, g as loadFallbackConfig, h as loadEmbeddingConfig, i as detectEmbeddingProvider, l as isAutoCompressEnabled, m as loadConfig, n as getVisibleTools, o as getConsolidationDecayDays, p as loadClaudeBridgeConfig, r as VERSION, s as getEnvVar, t as getAllTools, u as isConsolidationEnabled, v as loadTeamConfig } from "./tools-registry-C04WM1dS.mjs";
2
+ import { _ as loadSnapshotConfig, a as detectLlmProviderKind, d as isContextInjectionEnabled, f as isGraphExtractionEnabled, g as loadFallbackConfig, h as loadEmbeddingConfig, i as detectEmbeddingProvider, l as isAutoCompressEnabled, m as loadConfig, n as getVisibleTools, o as getConsolidationDecayDays, p as loadClaudeBridgeConfig, r as VERSION, s as getEnvVar, t as getAllTools, u as isConsolidationEnabled, v as loadTeamConfig } from "./tools-registry-NUso4hxA.mjs";
3
3
  import { execFile } from "node:child_process";
4
4
  import { constants, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
5
5
  import { basename, dirname, extname, join, resolve, sep } from "node:path";
@@ -2054,7 +2054,7 @@ var SearchIndex = class SearchIndex {
2054
2054
  return this.tokenize(parts.join(" ").toLowerCase());
2055
2055
  }
2056
2056
  tokenize(text) {
2057
- return text.replace(/[^\w\s/.\-_]/g, " ").split(/\s+/).filter((t) => t.length > 1).map((t) => stem(t));
2057
+ return text.replace(/[^\p{L}\p{N}\s/.\\-_]/gu, " ").split(/\s+/).filter((t) => t.length > 1).map((t) => stem(t));
2058
2058
  }
2059
2059
  getSortedTerms() {
2060
2060
  if (!this.sortedTerms) this.sortedTerms = Array.from(this.invertedIndex.keys()).sort();
@@ -2340,13 +2340,55 @@ async function deleteAccessLog(kv, memoryId) {
2340
2340
  //#endregion
2341
2341
  //#region src/functions/search.ts
2342
2342
  let index = null;
2343
+ let vectorIndex = null;
2344
+ let currentEmbeddingProvider = null;
2343
2345
  function getSearchIndex() {
2344
2346
  if (!index) index = new SearchIndex();
2345
2347
  return index;
2346
2348
  }
2349
+ function setVectorIndex(idx) {
2350
+ vectorIndex = idx;
2351
+ }
2352
+ function setEmbeddingProvider(provider) {
2353
+ currentEmbeddingProvider = provider;
2354
+ }
2355
+ const EMBED_MAX_CHARS = 16e3;
2356
+ function clipEmbedInput(text) {
2357
+ if (text.length <= EMBED_MAX_CHARS) return text;
2358
+ return text.slice(0, EMBED_MAX_CHARS);
2359
+ }
2360
+ async function vectorIndexAddGuarded(id, sessionId, text, context) {
2361
+ const vi = vectorIndex;
2362
+ const ep = currentEmbeddingProvider;
2363
+ if (!vi || !ep) return false;
2364
+ try {
2365
+ const embedding = await ep.embed(clipEmbedInput(text));
2366
+ if (embedding.length !== ep.dimensions) {
2367
+ logger.warn("vector-index add: dimension mismatch — skipping", {
2368
+ kind: context.kind,
2369
+ id: context.logId,
2370
+ provider: ep.name,
2371
+ expected: ep.dimensions,
2372
+ received: embedding.length
2373
+ });
2374
+ return false;
2375
+ }
2376
+ vi.add(id, sessionId, embedding);
2377
+ return true;
2378
+ } catch (err) {
2379
+ logger.warn("vector-index add: embed failed — skipping", {
2380
+ kind: context.kind,
2381
+ id: context.logId,
2382
+ provider: ep.name,
2383
+ error: err instanceof Error ? err.message : String(err)
2384
+ });
2385
+ return false;
2386
+ }
2387
+ }
2347
2388
  async function rebuildIndex(kv) {
2348
2389
  const idx = getSearchIndex();
2349
2390
  idx.clear();
2391
+ vectorIndex?.clear();
2350
2392
  let count = 0;
2351
2393
  try {
2352
2394
  const memories = await kv.list(KV.memories);
@@ -2354,6 +2396,10 @@ async function rebuildIndex(kv) {
2354
2396
  if (memory.isLatest === false) continue;
2355
2397
  if (!memory.title || !memory.content) continue;
2356
2398
  idx.add(memoryToObservation(memory));
2399
+ await vectorIndexAddGuarded(memory.id, memory.sessionIds[0] ?? "memory", memory.title + " " + memory.content, {
2400
+ kind: "memory",
2401
+ logId: memory.id
2402
+ });
2357
2403
  count++;
2358
2404
  }
2359
2405
  } catch (err) {
@@ -2378,6 +2424,10 @@ async function rebuildIndex(kv) {
2378
2424
  if (failedSessions.length > 0) logger.warn("rebuildIndex: failed to load observations for sessions", { failedSessions });
2379
2425
  for (const observations of obsPerSession) for (const obs of observations) if (obs.title && obs.narrative) {
2380
2426
  idx.add(obs);
2427
+ await vectorIndexAddGuarded(obs.id, obs.sessionId, obs.title + " " + obs.narrative, {
2428
+ kind: "observation",
2429
+ logId: obs.id
2430
+ });
2381
2431
  count++;
2382
2432
  }
2383
2433
  return count;
@@ -2600,10 +2650,10 @@ function registerObserveFunction(sdk, kv, dedupMap, maxObservationsPerSession) {
2600
2650
  };
2601
2651
  }
2602
2652
  if (pendingImageData && (pendingImageData.startsWith("data:image/") || pendingImageData.startsWith("iVBORw0KGgo") || pendingImageData.startsWith("/9j/"))) {
2603
- const { saveImageToDisk } = await import("./image-store-BmdmQ4tI.mjs");
2653
+ const { saveImageToDisk } = await import("./image-store-RY_BkYWK.mjs");
2604
2654
  const { filePath, bytesWritten } = await saveImageToDisk(pendingImageData);
2605
2655
  raw.imageData = filePath;
2606
- const { incrementImageRef } = await import("./image-refs-BIABW8uB.mjs");
2656
+ const { incrementImageRef } = await import("./image-refs-BkMGNmEs.mjs");
2607
2657
  await incrementImageRef(kv, filePath);
2608
2658
  sdk.triggerVoid("mem::disk-size-delta", { deltaBytes: bytesWritten });
2609
2659
  if (process.env["AGENTMEMORY_IMAGE_EMBEDDINGS"] === "true") sdk.triggerVoid("mem::vision-embed", {
@@ -2616,7 +2666,7 @@ function registerObserveFunction(sdk, kv, dedupMap, maxObservationsPerSession) {
2616
2666
  await kv.set(KV.observations(payload.sessionId), obsId, raw);
2617
2667
  } catch (error) {
2618
2668
  if (raw.imageData) {
2619
- const { deleteImage } = await import("./image-store-BmdmQ4tI.mjs");
2669
+ const { deleteImage } = await import("./image-store-RY_BkYWK.mjs");
2620
2670
  const { deletedBytes } = await deleteImage(raw.imageData);
2621
2671
  if (deletedBytes > 0) sdk.triggerVoid("mem::disk-size-delta", { deltaBytes: -deletedBytes });
2622
2672
  }
@@ -2684,6 +2734,10 @@ function registerObserveFunction(sdk, kv, dedupMap, maxObservationsPerSession) {
2684
2734
  const synthetic = buildSyntheticCompression(raw);
2685
2735
  await kv.set(KV.observations(payload.sessionId), obsId, synthetic);
2686
2736
  getSearchIndex().add(synthetic);
2737
+ await vectorIndexAddGuarded(synthetic.id, synthetic.sessionId, synthetic.title + " " + (synthetic.narrative || ""), {
2738
+ kind: "synthetic",
2739
+ logId: synthetic.id
2740
+ });
2687
2741
  await sdk.trigger({
2688
2742
  function_id: "stream::set",
2689
2743
  payload: {
@@ -3821,7 +3875,20 @@ function registerCompressFunction(sdk, kv, provider, metricsStore) {
3821
3875
  ...data.raw.imageData ? { imageRef: data.raw.imageData } : {}
3822
3876
  };
3823
3877
  await kv.set(KV.observations(data.sessionId), data.observationId, compressed);
3824
- getSearchIndex().add(compressed);
3878
+ try {
3879
+ getSearchIndex().add(compressed);
3880
+ } catch (err) {
3881
+ logger.warn("Failed to index compressed observation into BM25", {
3882
+ obsId: compressed.id,
3883
+ sessionId: compressed.sessionId,
3884
+ title: compressed.title,
3885
+ error: err instanceof Error ? err.message : String(err)
3886
+ });
3887
+ }
3888
+ await vectorIndexAddGuarded(compressed.id, compressed.sessionId, compressed.title + " " + (compressed.narrative || ""), {
3889
+ kind: "observation",
3890
+ logId: compressed.id
3891
+ });
3825
3892
  const streamResults = await Promise.allSettled([sdk.trigger({
3826
3893
  function_id: "stream::set",
3827
3894
  payload: {
@@ -4661,6 +4728,10 @@ function registerRememberFunction(sdk, kv) {
4661
4728
  error: err instanceof Error ? err.message : String(err)
4662
4729
  });
4663
4730
  }
4731
+ await vectorIndexAddGuarded(memory.id, memory.sessionIds[0] ?? "memory", memory.title + " " + memory.content, {
4732
+ kind: "memory",
4733
+ logId: memory.id
4734
+ });
4664
4735
  if (supersededId) await sdk.trigger({
4665
4736
  function_id: "mem::cascade-update",
4666
4737
  payload: { supersededMemoryId: supersededId },
@@ -4681,7 +4752,7 @@ function registerRememberFunction(sdk, kv) {
4681
4752
  const deletedMemoryIds = [];
4682
4753
  const deletedObservationIds = [];
4683
4754
  let deletedSession = false;
4684
- const { decrementImageRef } = await import("./image-refs-BIABW8uB.mjs");
4755
+ const { decrementImageRef } = await import("./image-refs-BkMGNmEs.mjs");
4685
4756
  if (data.memoryId) {
4686
4757
  const mem = await kv.get(KV.memories, data.memoryId);
4687
4758
  await kv.delete(KV.memories, data.memoryId);
@@ -4740,7 +4811,7 @@ const DEFAULTS$1 = {
4740
4811
  function registerEvictFunction(sdk, kv) {
4741
4812
  sdk.registerFunction("mem::evict", async (data) => {
4742
4813
  const dryRun = data?.dryRun ?? false;
4743
- const { decrementImageRef } = await import("./image-refs-BIABW8uB.mjs");
4814
+ const { decrementImageRef } = await import("./image-refs-BkMGNmEs.mjs");
4744
4815
  const configOverride = await kv.get(KV.config, "eviction").catch(() => null);
4745
4816
  const cfg = {
4746
4817
  ...DEFAULTS$1,
@@ -5343,7 +5414,7 @@ function registerAutoForgetFunction(sdk, kv) {
5343
5414
  sdk.registerFunction("mem::auto-forget", async (data) => {
5344
5415
  const dryRun = data?.dryRun ?? false;
5345
5416
  const now = Date.now();
5346
- const { decrementImageRef } = await import("./image-refs-BIABW8uB.mjs");
5417
+ const { decrementImageRef } = await import("./image-refs-BkMGNmEs.mjs");
5347
5418
  const result = {
5348
5419
  ttlExpired: [],
5349
5420
  contradictions: [],
@@ -5582,7 +5653,9 @@ function registerExportImportFunction(sdk, kv) {
5582
5653
  "0.9.7",
5583
5654
  "0.9.8",
5584
5655
  "0.9.9",
5585
- "0.9.10"
5656
+ "0.9.10",
5657
+ "0.9.11",
5658
+ "0.9.12"
5586
5659
  ]).has(importData.version)) return {
5587
5660
  success: false,
5588
5661
  error: `Unsupported export version: ${importData.version}`
@@ -11939,7 +12012,7 @@ function registerRetentionFunctions(sdk, kv) {
11939
12012
  const threshold = typeof data?.threshold === "number" && Number.isFinite(data.threshold) ? data.threshold : DEFAULT_DECAY.tierThresholds.cold;
11940
12013
  const maxEvictRaw = typeof data?.maxEvict === "number" && Number.isInteger(data.maxEvict) ? data.maxEvict : 50;
11941
12014
  const maxEvict = Math.min(1e3, Math.max(0, maxEvictRaw));
11942
- const { decrementImageRef } = await import("./image-refs-BIABW8uB.mjs");
12015
+ const { decrementImageRef } = await import("./image-refs-BkMGNmEs.mjs");
11943
12016
  const candidates = (await kv.list(KV.retentionScores)).filter((s) => s.score < threshold).sort((a, b) => a.score - b.score).slice(0, maxEvict);
11944
12017
  if (data?.dryRun) return {
11945
12018
  success: true,
@@ -18076,6 +18149,8 @@ async function main() {
18076
18149
  const metricsStore = new MetricsStore(kv);
18077
18150
  const dedupMap = new DedupMap();
18078
18151
  const vectorIndex = embeddingProvider ? new VectorIndex() : null;
18152
+ setVectorIndex(vectorIndex);
18153
+ setEmbeddingProvider(embeddingProvider);
18079
18154
  initMetrics(hasGetMeter(sdk) ? sdk.getMeter.bind(sdk) : void 0);
18080
18155
  registerPrivacyFunction(sdk);
18081
18156
  registerObserveFunction(sdk, kv, dedupMap, config.maxObservationsPerSession);
@@ -18293,4 +18368,4 @@ main().catch((err) => {
18293
18368
 
18294
18369
  //#endregion
18295
18370
  export { deleteImage as a, saveImageToDisk as c, IMAGES_DIR as i, touchImage as l, getImageRefCount as n, getMaxBytes as o, incrementImageRef as r, isManagedImagePath as s, decrementImageRef as t };
18296
- //# sourceMappingURL=src-d1vwmuPU.mjs.map
18371
+ //# sourceMappingURL=src-Cqsy23f_.mjs.map