@anuma/sdk 1.4.1 → 2.0.0

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.
@@ -4373,29 +4373,29 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
4373
4373
  const uncachedKeys = [];
4374
4374
  const uncachedIds = [];
4375
4375
  for (const m of memories) {
4376
- const key = m.content;
4377
- if (isEncrypted(key)) continue;
4378
- if (!cache.has(key)) {
4376
+ const content = m.content;
4377
+ if (isEncrypted(content)) continue;
4378
+ if (!cache.has(m.uniqueId)) {
4379
4379
  const modelCompatible = (m.embeddingModel ?? currentModel) === currentModel;
4380
4380
  if (m.embedding && modelCompatible) {
4381
4381
  try {
4382
4382
  const parsed = JSON.parse(m.embedding);
4383
4383
  if (Array.isArray(parsed)) {
4384
- cache.set(key, parsed);
4384
+ cache.set(m.uniqueId, Float32Array.from(parsed));
4385
4385
  continue;
4386
4386
  }
4387
4387
  } catch {
4388
4388
  }
4389
4389
  }
4390
4390
  uncachedTexts.push(m.content);
4391
- uncachedKeys.push(key);
4391
+ uncachedKeys.push(m.uniqueId);
4392
4392
  uncachedIds.push(m.uniqueId);
4393
4393
  }
4394
4394
  }
4395
4395
  if (uncachedTexts.length > 0) {
4396
4396
  const embeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
4397
4397
  for (let i = 0; i < uncachedKeys.length; i++) {
4398
- cache.set(uncachedKeys[i], embeddings[i]);
4398
+ cache.set(uncachedKeys[i], Float32Array.from(embeddings[i]));
4399
4399
  updateVaultMemoryEmbeddingOp(
4400
4400
  vaultCtx,
4401
4401
  uncachedIds[i],
@@ -4409,7 +4409,7 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
4409
4409
  async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, memoryId) {
4410
4410
  if (isEncrypted(content)) return;
4411
4411
  const embedding = await generateEmbedding(content, embeddingOptions);
4412
- cache.set(content, embedding);
4412
+ if (memoryId) cache.set(memoryId, Float32Array.from(embedding));
4413
4413
  if (vaultCtx && memoryId) {
4414
4414
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
4415
4415
  updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
@@ -4450,16 +4450,17 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4450
4450
  let staleReembedCount = 0;
4451
4451
  for (let i = 0; i < memories.length; i++) {
4452
4452
  const content = memories[i].content;
4453
- const cached = cache.get(content);
4453
+ const memoryId = memories[i].uniqueId;
4454
+ const cached = cache.get(memoryId);
4454
4455
  if (cached && cached.length === queryEmbedding.length) continue;
4455
- if (cached) cache.delete(content);
4456
+ if (cached) cache.delete(memoryId);
4456
4457
  const storedModel = memories[i].embeddingModel;
4457
4458
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
4458
4459
  if (memories[i].embedding && modelCompatible) {
4459
4460
  try {
4460
4461
  const parsed = JSON.parse(memories[i].embedding);
4461
4462
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
4462
- cache.set(content, parsed);
4463
+ cache.set(memoryId, Float32Array.from(parsed));
4463
4464
  continue;
4464
4465
  }
4465
4466
  } catch {
@@ -4477,7 +4478,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4477
4478
  if (uncachedTexts.length > 0) {
4478
4479
  const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
4479
4480
  for (let j = 0; j < uncachedTexts.length; j++) {
4480
- cache.set(memories[uncachedIndices[j]].content, newEmbeddings[j]);
4481
+ cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
4481
4482
  updateVaultMemoryEmbeddingOp(
4482
4483
  vaultCtx,
4483
4484
  memories[uncachedIndices[j]].uniqueId,
@@ -4493,7 +4494,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4493
4494
  const embeddedItems = memories.map((m) => ({
4494
4495
  id: m.uniqueId,
4495
4496
  content: m.content,
4496
- embedding: cache.get(m.content) ?? [],
4497
+ embedding: cache.get(m.uniqueId) ?? [],
4497
4498
  createdAt: m.createdAt,
4498
4499
  updatedAt: m.updatedAt,
4499
4500
  proofCount: m.proofCount,
@@ -4689,7 +4690,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
4689
4690
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
4690
4691
  );
4691
4692
  }
4692
- const { recall: recall2 } = await import("./recall-UAL346D2.mjs");
4693
+ const { recall: recall2 } = await import("./recall-DHOR5WWW.mjs");
4693
4694
  const result = await recall2(
4694
4695
  query,
4695
4696
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -6110,29 +6110,29 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
6110
6110
  const uncachedKeys = [];
6111
6111
  const uncachedIds = [];
6112
6112
  for (const m of memories) {
6113
- const key = m.content;
6114
- if (isEncrypted(key)) continue;
6115
- if (!cache.has(key)) {
6113
+ const content = m.content;
6114
+ if (isEncrypted(content)) continue;
6115
+ if (!cache.has(m.uniqueId)) {
6116
6116
  const modelCompatible = (m.embeddingModel ?? currentModel) === currentModel;
6117
6117
  if (m.embedding && modelCompatible) {
6118
6118
  try {
6119
6119
  const parsed = JSON.parse(m.embedding);
6120
6120
  if (Array.isArray(parsed)) {
6121
- cache.set(key, parsed);
6121
+ cache.set(m.uniqueId, Float32Array.from(parsed));
6122
6122
  continue;
6123
6123
  }
6124
6124
  } catch {
6125
6125
  }
6126
6126
  }
6127
6127
  uncachedTexts.push(m.content);
6128
- uncachedKeys.push(key);
6128
+ uncachedKeys.push(m.uniqueId);
6129
6129
  uncachedIds.push(m.uniqueId);
6130
6130
  }
6131
6131
  }
6132
6132
  if (uncachedTexts.length > 0) {
6133
6133
  const embeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
6134
6134
  for (let i = 0; i < uncachedKeys.length; i++) {
6135
- cache.set(uncachedKeys[i], embeddings[i]);
6135
+ cache.set(uncachedKeys[i], Float32Array.from(embeddings[i]));
6136
6136
  updateVaultMemoryEmbeddingOp(
6137
6137
  vaultCtx,
6138
6138
  uncachedIds[i],
@@ -6146,7 +6146,7 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
6146
6146
  async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, memoryId) {
6147
6147
  if (isEncrypted(content)) return;
6148
6148
  const embedding = await generateEmbedding(content, embeddingOptions);
6149
- cache.set(content, embedding);
6149
+ if (memoryId) cache.set(memoryId, Float32Array.from(embedding));
6150
6150
  if (vaultCtx && memoryId) {
6151
6151
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
6152
6152
  updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
@@ -6187,16 +6187,17 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
6187
6187
  let staleReembedCount = 0;
6188
6188
  for (let i = 0; i < memories.length; i++) {
6189
6189
  const content = memories[i].content;
6190
- const cached = cache.get(content);
6190
+ const memoryId = memories[i].uniqueId;
6191
+ const cached = cache.get(memoryId);
6191
6192
  if (cached && cached.length === queryEmbedding.length) continue;
6192
- if (cached) cache.delete(content);
6193
+ if (cached) cache.delete(memoryId);
6193
6194
  const storedModel = memories[i].embeddingModel;
6194
6195
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
6195
6196
  if (memories[i].embedding && modelCompatible) {
6196
6197
  try {
6197
6198
  const parsed = JSON.parse(memories[i].embedding);
6198
6199
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
6199
- cache.set(content, parsed);
6200
+ cache.set(memoryId, Float32Array.from(parsed));
6200
6201
  continue;
6201
6202
  }
6202
6203
  } catch {
@@ -6214,7 +6215,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
6214
6215
  if (uncachedTexts.length > 0) {
6215
6216
  const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
6216
6217
  for (let j = 0; j < uncachedTexts.length; j++) {
6217
- cache.set(memories[uncachedIndices[j]].content, newEmbeddings[j]);
6218
+ cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
6218
6219
  updateVaultMemoryEmbeddingOp(
6219
6220
  vaultCtx,
6220
6221
  memories[uncachedIndices[j]].uniqueId,
@@ -6230,7 +6231,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
6230
6231
  const embeddedItems = memories.map((m) => ({
6231
6232
  id: m.uniqueId,
6232
6233
  content: m.content,
6233
- embedding: cache.get(m.content) ?? [],
6234
+ embedding: cache.get(m.uniqueId) ?? [],
6234
6235
  createdAt: m.createdAt,
6235
6236
  updatedAt: m.updatedAt,
6236
6237
  proofCount: m.proofCount,
@@ -12635,7 +12636,6 @@ async function retain(content, ctx, options = {}) {
12635
12636
  }
12636
12637
  }
12637
12638
  const embedding = await generateEmbedding(trimmed, ctx.embeddingOptions);
12638
- ctx.vaultCache.set(trimmed, embedding);
12639
12639
  const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
12640
12640
  const created = await createVaultMemoryOp(ctx.vaultCtx, {
12641
12641
  content: trimmed,
@@ -12656,6 +12656,7 @@ async function retain(content, ctx, options = {}) {
12656
12656
  }
12657
12657
  }
12658
12658
  });
12659
+ ctx.vaultCache.set(created.uniqueId, Float32Array.from(embedding));
12659
12660
  return {
12660
12661
  action: "create",
12661
12662
  memoryId: created.uniqueId,
@@ -12732,7 +12733,6 @@ async function tryConsolidate(trimmed, ctx, options) {
12732
12733
  options.sourceChunkIds ?? []
12733
12734
  );
12734
12735
  const newEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
12735
- ctx.vaultCache.set(decision.content, newEmbedding);
12736
12736
  const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
12737
12737
  const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
12738
12738
  const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
@@ -12752,6 +12752,7 @@ async function tryConsolidate(trimmed, ctx, options) {
12752
12752
  await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
12753
12753
  return null;
12754
12754
  }
12755
+ ctx.vaultCache.set(decision.targetId, Float32Array.from(newEmbedding));
12755
12756
  return {
12756
12757
  action: "update",
12757
12758
  memoryId: decision.targetId,
@@ -13821,9 +13822,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
13821
13822
  return `Error: Failed to update memory "${id}".`;
13822
13823
  }
13823
13824
  if (embeddingOptions && cache) {
13824
- if (previousContent) {
13825
- cache.delete(previousContent);
13826
- }
13825
+ cache.delete(id);
13827
13826
  eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, id).catch(
13828
13827
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
13829
13828
  () => {
@@ -4726,7 +4726,9 @@ interface RecencyOptions {
4726
4726
 
4727
4727
  declare const DEFAULT_VAULT_CACHE_SIZE = 5000;
4728
4728
  /**
4729
- * Create a VaultEmbeddingCache backed by an LRU with a default cap of 1000 entries.
4729
+ * Create a VaultEmbeddingCache backed by an LRU with a default cap of
4730
+ * DEFAULT_VAULT_CACHE_SIZE entries. Values are Float32Array — the model's
4731
+ * native precision — not float64 number[], halving resident RAM losslessly.
4730
4732
  */
4731
4733
  declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCache;
4732
4734
 
@@ -4741,7 +4743,7 @@ declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCach
4741
4743
  * Embedding cache keyed by content string. Stores pre-computed embeddings
4742
4744
  * so that search only needs to embed the query, not the vault entries.
4743
4745
  */
4744
- type VaultEmbeddingCache = Map<string, number[]>;
4746
+ type VaultEmbeddingCache = Map<string, Float32Array>;
4745
4747
  /**
4746
4748
  * Options for the vault search tool.
4747
4749
  */
@@ -4726,7 +4726,9 @@ interface RecencyOptions {
4726
4726
 
4727
4727
  declare const DEFAULT_VAULT_CACHE_SIZE = 5000;
4728
4728
  /**
4729
- * Create a VaultEmbeddingCache backed by an LRU with a default cap of 1000 entries.
4729
+ * Create a VaultEmbeddingCache backed by an LRU with a default cap of
4730
+ * DEFAULT_VAULT_CACHE_SIZE entries. Values are Float32Array — the model's
4731
+ * native precision — not float64 number[], halving resident RAM losslessly.
4730
4732
  */
4731
4733
  declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCache;
4732
4734
 
@@ -4741,7 +4743,7 @@ declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCach
4741
4743
  * Embedding cache keyed by content string. Stores pre-computed embeddings
4742
4744
  * so that search only needs to embed the query, not the vault entries.
4743
4745
  */
4744
- type VaultEmbeddingCache = Map<string, number[]>;
4746
+ type VaultEmbeddingCache = Map<string, Float32Array>;
4745
4747
  /**
4746
4748
  * Options for the vault search tool.
4747
4749
  */
@@ -79,7 +79,7 @@ import {
79
79
  updateVaultMemoryOp,
80
80
  upsertMessageOp,
81
81
  useEncryption
82
- } from "./chunk-RMZ4QAQV.mjs";
82
+ } from "./chunk-N4FEY34G.mjs";
83
83
  import {
84
84
  PII_PATTERNS,
85
85
  PiiRedactor,
@@ -5911,7 +5911,6 @@ async function retain(content, ctx, options = {}) {
5911
5911
  }
5912
5912
  }
5913
5913
  const embedding = await generateEmbedding(trimmed, ctx.embeddingOptions);
5914
- ctx.vaultCache.set(trimmed, embedding);
5915
5914
  const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
5916
5915
  const created = await createVaultMemoryOp(ctx.vaultCtx, {
5917
5916
  content: trimmed,
@@ -5932,6 +5931,7 @@ async function retain(content, ctx, options = {}) {
5932
5931
  }
5933
5932
  }
5934
5933
  });
5934
+ ctx.vaultCache.set(created.uniqueId, Float32Array.from(embedding));
5935
5935
  return {
5936
5936
  action: "create",
5937
5937
  memoryId: created.uniqueId,
@@ -6008,7 +6008,6 @@ async function tryConsolidate(trimmed, ctx, options) {
6008
6008
  options.sourceChunkIds ?? []
6009
6009
  );
6010
6010
  const newEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
6011
- ctx.vaultCache.set(decision.content, newEmbedding);
6012
6011
  const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
6013
6012
  const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
6014
6013
  const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
@@ -6028,6 +6027,7 @@ async function tryConsolidate(trimmed, ctx, options) {
6028
6027
  await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
6029
6028
  return null;
6030
6029
  }
6030
+ ctx.vaultCache.set(decision.targetId, Float32Array.from(newEmbedding));
6031
6031
  return {
6032
6032
  action: "update",
6033
6033
  memoryId: decision.targetId,
@@ -7072,9 +7072,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
7072
7072
  return `Error: Failed to update memory "${id}".`;
7073
7073
  }
7074
7074
  if (embeddingOptions && cache) {
7075
- if (previousContent) {
7076
- cache.delete(previousContent);
7077
- }
7075
+ cache.delete(id);
7078
7076
  eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, id).catch(
7079
7077
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
7080
7078
  () => {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-RMZ4QAQV.mjs";
3
+ } from "./chunk-N4FEY34G.mjs";
4
4
  import "./chunk-DFVCS3QQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -4704,29 +4704,29 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
4704
4704
  const uncachedKeys = [];
4705
4705
  const uncachedIds = [];
4706
4706
  for (const m of memories) {
4707
- const key = m.content;
4708
- if (isEncrypted(key)) continue;
4709
- if (!cache.has(key)) {
4707
+ const content = m.content;
4708
+ if (isEncrypted(content)) continue;
4709
+ if (!cache.has(m.uniqueId)) {
4710
4710
  const modelCompatible = (m.embeddingModel ?? currentModel) === currentModel;
4711
4711
  if (m.embedding && modelCompatible) {
4712
4712
  try {
4713
4713
  const parsed = JSON.parse(m.embedding);
4714
4714
  if (Array.isArray(parsed)) {
4715
- cache.set(key, parsed);
4715
+ cache.set(m.uniqueId, Float32Array.from(parsed));
4716
4716
  continue;
4717
4717
  }
4718
4718
  } catch {
4719
4719
  }
4720
4720
  }
4721
4721
  uncachedTexts.push(m.content);
4722
- uncachedKeys.push(key);
4722
+ uncachedKeys.push(m.uniqueId);
4723
4723
  uncachedIds.push(m.uniqueId);
4724
4724
  }
4725
4725
  }
4726
4726
  if (uncachedTexts.length > 0) {
4727
4727
  const embeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
4728
4728
  for (let i = 0; i < uncachedKeys.length; i++) {
4729
- cache.set(uncachedKeys[i], embeddings[i]);
4729
+ cache.set(uncachedKeys[i], Float32Array.from(embeddings[i]));
4730
4730
  updateVaultMemoryEmbeddingOp(
4731
4731
  vaultCtx,
4732
4732
  uncachedIds[i],
@@ -4740,7 +4740,7 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
4740
4740
  async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, memoryId) {
4741
4741
  if (isEncrypted(content)) return;
4742
4742
  const embedding = await generateEmbedding(content, embeddingOptions);
4743
- cache.set(content, embedding);
4743
+ if (memoryId) cache.set(memoryId, Float32Array.from(embedding));
4744
4744
  if (vaultCtx && memoryId) {
4745
4745
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
4746
4746
  updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
@@ -4781,16 +4781,17 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4781
4781
  let staleReembedCount = 0;
4782
4782
  for (let i = 0; i < memories.length; i++) {
4783
4783
  const content = memories[i].content;
4784
- const cached = cache.get(content);
4784
+ const memoryId = memories[i].uniqueId;
4785
+ const cached = cache.get(memoryId);
4785
4786
  if (cached && cached.length === queryEmbedding.length) continue;
4786
- if (cached) cache.delete(content);
4787
+ if (cached) cache.delete(memoryId);
4787
4788
  const storedModel = memories[i].embeddingModel;
4788
4789
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
4789
4790
  if (memories[i].embedding && modelCompatible) {
4790
4791
  try {
4791
4792
  const parsed = JSON.parse(memories[i].embedding);
4792
4793
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
4793
- cache.set(content, parsed);
4794
+ cache.set(memoryId, Float32Array.from(parsed));
4794
4795
  continue;
4795
4796
  }
4796
4797
  } catch {
@@ -4808,7 +4809,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4808
4809
  if (uncachedTexts.length > 0) {
4809
4810
  const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
4810
4811
  for (let j = 0; j < uncachedTexts.length; j++) {
4811
- cache.set(memories[uncachedIndices[j]].content, newEmbeddings[j]);
4812
+ cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
4812
4813
  updateVaultMemoryEmbeddingOp(
4813
4814
  vaultCtx,
4814
4815
  memories[uncachedIndices[j]].uniqueId,
@@ -4824,7 +4825,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
4824
4825
  const embeddedItems = memories.map((m) => ({
4825
4826
  id: m.uniqueId,
4826
4827
  content: m.content,
4827
- embedding: cache.get(m.content) ?? [],
4828
+ embedding: cache.get(m.uniqueId) ?? [],
4828
4829
  createdAt: m.createdAt,
4829
4830
  updatedAt: m.updatedAt,
4830
4831
  proofCount: m.proofCount,
@@ -5020,7 +5021,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
5020
5021
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
5021
5022
  );
5022
5023
  }
5023
- const { recall: recall2 } = await import("./recall-L3QROVGM.mjs");
5024
+ const { recall: recall2 } = await import("./recall-PUXEQHAP.mjs");
5024
5025
  const result = await recall2(
5025
5026
  query,
5026
5027
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -6441,29 +6441,29 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
6441
6441
  const uncachedKeys = [];
6442
6442
  const uncachedIds = [];
6443
6443
  for (const m of memories) {
6444
- const key = m.content;
6445
- if (isEncrypted(key)) continue;
6446
- if (!cache.has(key)) {
6444
+ const content = m.content;
6445
+ if (isEncrypted(content)) continue;
6446
+ if (!cache.has(m.uniqueId)) {
6447
6447
  const modelCompatible = (m.embeddingModel ?? currentModel) === currentModel;
6448
6448
  if (m.embedding && modelCompatible) {
6449
6449
  try {
6450
6450
  const parsed = JSON.parse(m.embedding);
6451
6451
  if (Array.isArray(parsed)) {
6452
- cache.set(key, parsed);
6452
+ cache.set(m.uniqueId, Float32Array.from(parsed));
6453
6453
  continue;
6454
6454
  }
6455
6455
  } catch {
6456
6456
  }
6457
6457
  }
6458
6458
  uncachedTexts.push(m.content);
6459
- uncachedKeys.push(key);
6459
+ uncachedKeys.push(m.uniqueId);
6460
6460
  uncachedIds.push(m.uniqueId);
6461
6461
  }
6462
6462
  }
6463
6463
  if (uncachedTexts.length > 0) {
6464
6464
  const embeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
6465
6465
  for (let i = 0; i < uncachedKeys.length; i++) {
6466
- cache.set(uncachedKeys[i], embeddings[i]);
6466
+ cache.set(uncachedKeys[i], Float32Array.from(embeddings[i]));
6467
6467
  updateVaultMemoryEmbeddingOp(
6468
6468
  vaultCtx,
6469
6469
  uncachedIds[i],
@@ -6477,7 +6477,7 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
6477
6477
  async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, memoryId) {
6478
6478
  if (isEncrypted(content)) return;
6479
6479
  const embedding = await generateEmbedding(content, embeddingOptions);
6480
- cache.set(content, embedding);
6480
+ if (memoryId) cache.set(memoryId, Float32Array.from(embedding));
6481
6481
  if (vaultCtx && memoryId) {
6482
6482
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
6483
6483
  updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
@@ -6518,16 +6518,17 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
6518
6518
  let staleReembedCount = 0;
6519
6519
  for (let i = 0; i < memories.length; i++) {
6520
6520
  const content = memories[i].content;
6521
- const cached = cache.get(content);
6521
+ const memoryId = memories[i].uniqueId;
6522
+ const cached = cache.get(memoryId);
6522
6523
  if (cached && cached.length === queryEmbedding.length) continue;
6523
- if (cached) cache.delete(content);
6524
+ if (cached) cache.delete(memoryId);
6524
6525
  const storedModel = memories[i].embeddingModel;
6525
6526
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
6526
6527
  if (memories[i].embedding && modelCompatible) {
6527
6528
  try {
6528
6529
  const parsed = JSON.parse(memories[i].embedding);
6529
6530
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
6530
- cache.set(content, parsed);
6531
+ cache.set(memoryId, Float32Array.from(parsed));
6531
6532
  continue;
6532
6533
  }
6533
6534
  } catch {
@@ -6545,7 +6546,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
6545
6546
  if (uncachedTexts.length > 0) {
6546
6547
  const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
6547
6548
  for (let j = 0; j < uncachedTexts.length; j++) {
6548
- cache.set(memories[uncachedIndices[j]].content, newEmbeddings[j]);
6549
+ cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
6549
6550
  updateVaultMemoryEmbeddingOp(
6550
6551
  vaultCtx,
6551
6552
  memories[uncachedIndices[j]].uniqueId,
@@ -6561,7 +6562,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
6561
6562
  const embeddedItems = memories.map((m) => ({
6562
6563
  id: m.uniqueId,
6563
6564
  content: m.content,
6564
- embedding: cache.get(m.content) ?? [],
6565
+ embedding: cache.get(m.uniqueId) ?? [],
6565
6566
  createdAt: m.createdAt,
6566
6567
  updatedAt: m.updatedAt,
6567
6568
  proofCount: m.proofCount,
@@ -13984,7 +13985,6 @@ async function retain(content, ctx, options = {}) {
13984
13985
  }
13985
13986
  }
13986
13987
  const embedding = await generateEmbedding(trimmed, ctx.embeddingOptions);
13987
- ctx.vaultCache.set(trimmed, embedding);
13988
13988
  const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
13989
13989
  const created = await createVaultMemoryOp(ctx.vaultCtx, {
13990
13990
  content: trimmed,
@@ -14005,6 +14005,7 @@ async function retain(content, ctx, options = {}) {
14005
14005
  }
14006
14006
  }
14007
14007
  });
14008
+ ctx.vaultCache.set(created.uniqueId, Float32Array.from(embedding));
14008
14009
  return {
14009
14010
  action: "create",
14010
14011
  memoryId: created.uniqueId,
@@ -14081,7 +14082,6 @@ async function tryConsolidate(trimmed, ctx, options) {
14081
14082
  options.sourceChunkIds ?? []
14082
14083
  );
14083
14084
  const newEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
14084
- ctx.vaultCache.set(decision.content, newEmbedding);
14085
14085
  const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
14086
14086
  const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
14087
14087
  const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
@@ -14101,6 +14101,7 @@ async function tryConsolidate(trimmed, ctx, options) {
14101
14101
  await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
14102
14102
  return null;
14103
14103
  }
14104
+ ctx.vaultCache.set(decision.targetId, Float32Array.from(newEmbedding));
14104
14105
  return {
14105
14106
  action: "update",
14106
14107
  memoryId: decision.targetId,
@@ -15170,9 +15171,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
15170
15171
  return `Error: Failed to update memory "${id}".`;
15171
15172
  }
15172
15173
  if (embeddingOptions && cache) {
15173
- if (previousContent) {
15174
- cache.delete(previousContent);
15175
- }
15174
+ cache.delete(id);
15176
15175
  eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, id).catch(
15177
15176
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
15178
15177
  () => {
@@ -17795,7 +17794,7 @@ function useChatStorage(options) {
17795
17794
  const result = await updateVaultMemoryOp(vaultCtx, id, { content, scope, embedding: null });
17796
17795
  if (result && getToken) {
17797
17796
  if (existing) {
17798
- vaultEmbeddingCacheRef.current.delete(existing.content);
17797
+ vaultEmbeddingCacheRef.current.delete(id);
17799
17798
  }
17800
17799
  eagerEmbedContent(
17801
17800
  content,
@@ -17816,7 +17815,7 @@ function useChatStorage(options) {
17816
17815
  const existing = await getVaultMemoryOp(vaultCtx, id);
17817
17816
  const result = await deleteVaultMemoryOp(vaultCtx, id);
17818
17817
  if (result && existing) {
17819
- vaultEmbeddingCacheRef.current.delete(existing.content);
17818
+ vaultEmbeddingCacheRef.current.delete(id);
17820
17819
  }
17821
17820
  return result;
17822
17821
  },
@@ -5857,7 +5857,9 @@ interface RecencyOptions {
5857
5857
 
5858
5858
  declare const DEFAULT_VAULT_CACHE_SIZE = 5000;
5859
5859
  /**
5860
- * Create a VaultEmbeddingCache backed by an LRU with a default cap of 1000 entries.
5860
+ * Create a VaultEmbeddingCache backed by an LRU with a default cap of
5861
+ * DEFAULT_VAULT_CACHE_SIZE entries. Values are Float32Array — the model's
5862
+ * native precision — not float64 number[], halving resident RAM losslessly.
5861
5863
  */
5862
5864
  declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCache;
5863
5865
 
@@ -5872,7 +5874,7 @@ declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCach
5872
5874
  * Embedding cache keyed by content string. Stores pre-computed embeddings
5873
5875
  * so that search only needs to embed the query, not the vault entries.
5874
5876
  */
5875
- type VaultEmbeddingCache = Map<string, number[]>;
5877
+ type VaultEmbeddingCache = Map<string, Float32Array>;
5876
5878
  /**
5877
5879
  * Options for the vault search tool.
5878
5880
  */
@@ -5857,7 +5857,9 @@ interface RecencyOptions {
5857
5857
 
5858
5858
  declare const DEFAULT_VAULT_CACHE_SIZE = 5000;
5859
5859
  /**
5860
- * Create a VaultEmbeddingCache backed by an LRU with a default cap of 1000 entries.
5860
+ * Create a VaultEmbeddingCache backed by an LRU with a default cap of
5861
+ * DEFAULT_VAULT_CACHE_SIZE entries. Values are Float32Array — the model's
5862
+ * native precision — not float64 number[], halving resident RAM losslessly.
5861
5863
  */
5862
5864
  declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCache;
5863
5865
 
@@ -5872,7 +5874,7 @@ declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCach
5872
5874
  * Embedding cache keyed by content string. Stores pre-computed embeddings
5873
5875
  * so that search only needs to embed the query, not the vault entries.
5874
5876
  */
5875
- type VaultEmbeddingCache = Map<string, number[]>;
5877
+ type VaultEmbeddingCache = Map<string, Float32Array>;
5876
5878
  /**
5877
5879
  * Options for the vault search tool.
5878
5880
  */
@@ -121,7 +121,7 @@ import {
121
121
  updateVaultMemoryEmbeddingOp,
122
122
  updateVaultMemoryOp,
123
123
  useEncryption
124
- } from "./chunk-4FNDAPTF.mjs";
124
+ } from "./chunk-63IW5BS5.mjs";
125
125
  import {
126
126
  PiiRedactor,
127
127
  createStreamingDeAnonymizer,
@@ -6733,7 +6733,6 @@ async function retain(content, ctx, options = {}) {
6733
6733
  }
6734
6734
  }
6735
6735
  const embedding = await generateEmbedding(trimmed, ctx.embeddingOptions);
6736
- ctx.vaultCache.set(trimmed, embedding);
6737
6736
  const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
6738
6737
  const created = await createVaultMemoryOp(ctx.vaultCtx, {
6739
6738
  content: trimmed,
@@ -6754,6 +6753,7 @@ async function retain(content, ctx, options = {}) {
6754
6753
  }
6755
6754
  }
6756
6755
  });
6756
+ ctx.vaultCache.set(created.uniqueId, Float32Array.from(embedding));
6757
6757
  return {
6758
6758
  action: "create",
6759
6759
  memoryId: created.uniqueId,
@@ -6830,7 +6830,6 @@ async function tryConsolidate(trimmed, ctx, options) {
6830
6830
  options.sourceChunkIds ?? []
6831
6831
  );
6832
6832
  const newEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
6833
- ctx.vaultCache.set(decision.content, newEmbedding);
6834
6833
  const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
6835
6834
  const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
6836
6835
  const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
@@ -6850,6 +6849,7 @@ async function tryConsolidate(trimmed, ctx, options) {
6850
6849
  await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
6851
6850
  return null;
6852
6851
  }
6852
+ ctx.vaultCache.set(decision.targetId, Float32Array.from(newEmbedding));
6853
6853
  return {
6854
6854
  action: "update",
6855
6855
  memoryId: decision.targetId,
@@ -7894,9 +7894,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
7894
7894
  return `Error: Failed to update memory "${id}".`;
7895
7895
  }
7896
7896
  if (embeddingOptions && cache) {
7897
- if (previousContent) {
7898
- cache.delete(previousContent);
7899
- }
7897
+ cache.delete(id);
7900
7898
  eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, id).catch(
7901
7899
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
7902
7900
  () => {
@@ -10499,7 +10497,7 @@ function useChatStorage(options) {
10499
10497
  const result = await updateVaultMemoryOp(vaultCtx, id, { content, scope, embedding: null });
10500
10498
  if (result && getToken) {
10501
10499
  if (existing) {
10502
- vaultEmbeddingCacheRef.current.delete(existing.content);
10500
+ vaultEmbeddingCacheRef.current.delete(id);
10503
10501
  }
10504
10502
  eagerEmbedContent(
10505
10503
  content,
@@ -10520,7 +10518,7 @@ function useChatStorage(options) {
10520
10518
  const existing = await getVaultMemoryOp(vaultCtx, id);
10521
10519
  const result = await deleteVaultMemoryOp(vaultCtx, id);
10522
10520
  if (result && existing) {
10523
- vaultEmbeddingCacheRef.current.delete(existing.content);
10521
+ vaultEmbeddingCacheRef.current.delete(id);
10524
10522
  }
10525
10523
  return result;
10526
10524
  },
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-4FNDAPTF.mjs";
3
+ } from "./chunk-63IW5BS5.mjs";
4
4
  import "./chunk-DFVCS3QQ.mjs";
5
5
  import "./chunk-GYKJOWEO.mjs";
6
6
  export {
@@ -18531,29 +18531,29 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
18531
18531
  const uncachedKeys = [];
18532
18532
  const uncachedIds = [];
18533
18533
  for (const m of memories) {
18534
- const key = m.content;
18535
- if (isEncrypted(key)) continue;
18536
- if (!cache.has(key)) {
18534
+ const content = m.content;
18535
+ if (isEncrypted(content)) continue;
18536
+ if (!cache.has(m.uniqueId)) {
18537
18537
  const modelCompatible = (m.embeddingModel ?? currentModel) === currentModel;
18538
18538
  if (m.embedding && modelCompatible) {
18539
18539
  try {
18540
18540
  const parsed = JSON.parse(m.embedding);
18541
18541
  if (Array.isArray(parsed)) {
18542
- cache.set(key, parsed);
18542
+ cache.set(m.uniqueId, Float32Array.from(parsed));
18543
18543
  continue;
18544
18544
  }
18545
18545
  } catch {
18546
18546
  }
18547
18547
  }
18548
18548
  uncachedTexts.push(m.content);
18549
- uncachedKeys.push(key);
18549
+ uncachedKeys.push(m.uniqueId);
18550
18550
  uncachedIds.push(m.uniqueId);
18551
18551
  }
18552
18552
  }
18553
18553
  if (uncachedTexts.length > 0) {
18554
18554
  const embeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
18555
18555
  for (let i = 0; i < uncachedKeys.length; i++) {
18556
- cache.set(uncachedKeys[i], embeddings[i]);
18556
+ cache.set(uncachedKeys[i], Float32Array.from(embeddings[i]));
18557
18557
  updateVaultMemoryEmbeddingOp(
18558
18558
  vaultCtx,
18559
18559
  uncachedIds[i],
@@ -18567,7 +18567,7 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
18567
18567
  async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, memoryId) {
18568
18568
  if (isEncrypted(content)) return;
18569
18569
  const embedding = await generateEmbedding(content, embeddingOptions);
18570
- cache.set(content, embedding);
18570
+ if (memoryId) cache.set(memoryId, Float32Array.from(embedding));
18571
18571
  if (vaultCtx && memoryId) {
18572
18572
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
18573
18573
  updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
@@ -18608,16 +18608,17 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
18608
18608
  let staleReembedCount = 0;
18609
18609
  for (let i = 0; i < memories.length; i++) {
18610
18610
  const content = memories[i].content;
18611
- const cached = cache.get(content);
18611
+ const memoryId = memories[i].uniqueId;
18612
+ const cached = cache.get(memoryId);
18612
18613
  if (cached && cached.length === queryEmbedding.length) continue;
18613
- if (cached) cache.delete(content);
18614
+ if (cached) cache.delete(memoryId);
18614
18615
  const storedModel = memories[i].embeddingModel;
18615
18616
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
18616
18617
  if (memories[i].embedding && modelCompatible) {
18617
18618
  try {
18618
18619
  const parsed = JSON.parse(memories[i].embedding);
18619
18620
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
18620
- cache.set(content, parsed);
18621
+ cache.set(memoryId, Float32Array.from(parsed));
18621
18622
  continue;
18622
18623
  }
18623
18624
  } catch {
@@ -18635,7 +18636,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
18635
18636
  if (uncachedTexts.length > 0) {
18636
18637
  const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
18637
18638
  for (let j = 0; j < uncachedTexts.length; j++) {
18638
- cache.set(memories[uncachedIndices[j]].content, newEmbeddings[j]);
18639
+ cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
18639
18640
  updateVaultMemoryEmbeddingOp(
18640
18641
  vaultCtx,
18641
18642
  memories[uncachedIndices[j]].uniqueId,
@@ -18651,7 +18652,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
18651
18652
  const embeddedItems = memories.map((m) => ({
18652
18653
  id: m.uniqueId,
18653
18654
  content: m.content,
18654
- embedding: cache.get(m.content) ?? [],
18655
+ embedding: cache.get(m.uniqueId) ?? [],
18655
18656
  createdAt: m.createdAt,
18656
18657
  updatedAt: m.updatedAt,
18657
18658
  proofCount: m.proofCount,
@@ -18847,7 +18848,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
18847
18848
  legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
18848
18849
  );
18849
18850
  }
18850
- const { recall: recall2 } = await import("./recall-UHJN6H5V.mjs");
18851
+ const { recall: recall2 } = await import("./recall-JJ3E74XY.mjs");
18851
18852
  const result = await recall2(
18852
18853
  query,
18853
18854
  { vaultCtx, embeddingOptions, vaultCache: cache },
@@ -20246,29 +20246,29 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
20246
20246
  const uncachedKeys = [];
20247
20247
  const uncachedIds = [];
20248
20248
  for (const m of memories) {
20249
- const key = m.content;
20250
- if (isEncrypted(key)) continue;
20251
- if (!cache.has(key)) {
20249
+ const content = m.content;
20250
+ if (isEncrypted(content)) continue;
20251
+ if (!cache.has(m.uniqueId)) {
20252
20252
  const modelCompatible = (m.embeddingModel ?? currentModel) === currentModel;
20253
20253
  if (m.embedding && modelCompatible) {
20254
20254
  try {
20255
20255
  const parsed = JSON.parse(m.embedding);
20256
20256
  if (Array.isArray(parsed)) {
20257
- cache.set(key, parsed);
20257
+ cache.set(m.uniqueId, Float32Array.from(parsed));
20258
20258
  continue;
20259
20259
  }
20260
20260
  } catch {
20261
20261
  }
20262
20262
  }
20263
20263
  uncachedTexts.push(m.content);
20264
- uncachedKeys.push(key);
20264
+ uncachedKeys.push(m.uniqueId);
20265
20265
  uncachedIds.push(m.uniqueId);
20266
20266
  }
20267
20267
  }
20268
20268
  if (uncachedTexts.length > 0) {
20269
20269
  const embeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
20270
20270
  for (let i = 0; i < uncachedKeys.length; i++) {
20271
- cache.set(uncachedKeys[i], embeddings[i]);
20271
+ cache.set(uncachedKeys[i], Float32Array.from(embeddings[i]));
20272
20272
  updateVaultMemoryEmbeddingOp(
20273
20273
  vaultCtx,
20274
20274
  uncachedIds[i],
@@ -20282,7 +20282,7 @@ async function preEmbedVaultMemories(vaultCtx, embeddingOptions, cache, options)
20282
20282
  async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, memoryId) {
20283
20283
  if (isEncrypted(content)) return;
20284
20284
  const embedding = await generateEmbedding(content, embeddingOptions);
20285
- cache.set(content, embedding);
20285
+ if (memoryId) cache.set(memoryId, Float32Array.from(embedding));
20286
20286
  if (vaultCtx && memoryId) {
20287
20287
  const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
20288
20288
  updateVaultMemoryEmbeddingOp(vaultCtx, memoryId, JSON.stringify(embedding), currentModel).catch(
@@ -20323,16 +20323,17 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
20323
20323
  let staleReembedCount = 0;
20324
20324
  for (let i = 0; i < memories.length; i++) {
20325
20325
  const content = memories[i].content;
20326
- const cached = cache.get(content);
20326
+ const memoryId = memories[i].uniqueId;
20327
+ const cached = cache.get(memoryId);
20327
20328
  if (cached && cached.length === queryEmbedding.length) continue;
20328
- if (cached) cache.delete(content);
20329
+ if (cached) cache.delete(memoryId);
20329
20330
  const storedModel = memories[i].embeddingModel;
20330
20331
  const modelCompatible = (storedModel ?? currentModel) === currentModel;
20331
20332
  if (memories[i].embedding && modelCompatible) {
20332
20333
  try {
20333
20334
  const parsed = JSON.parse(memories[i].embedding);
20334
20335
  if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
20335
- cache.set(content, parsed);
20336
+ cache.set(memoryId, Float32Array.from(parsed));
20336
20337
  continue;
20337
20338
  }
20338
20339
  } catch {
@@ -20350,7 +20351,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
20350
20351
  if (uncachedTexts.length > 0) {
20351
20352
  const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
20352
20353
  for (let j = 0; j < uncachedTexts.length; j++) {
20353
- cache.set(memories[uncachedIndices[j]].content, newEmbeddings[j]);
20354
+ cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
20354
20355
  updateVaultMemoryEmbeddingOp(
20355
20356
  vaultCtx,
20356
20357
  memories[uncachedIndices[j]].uniqueId,
@@ -20366,7 +20367,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
20366
20367
  const embeddedItems = memories.map((m) => ({
20367
20368
  id: m.uniqueId,
20368
20369
  content: m.content,
20369
- embedding: cache.get(m.content) ?? [],
20370
+ embedding: cache.get(m.uniqueId) ?? [],
20370
20371
  createdAt: m.createdAt,
20371
20372
  updatedAt: m.updatedAt,
20372
20373
  proofCount: m.proofCount,
@@ -25527,9 +25528,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
25527
25528
  return `Error: Failed to update memory "${id}".`;
25528
25529
  }
25529
25530
  if (embeddingOptions && cache) {
25530
- if (previousContent) {
25531
- cache.delete(previousContent);
25532
- }
25531
+ cache.delete(id);
25533
25532
  eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, id).catch(
25534
25533
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
25535
25534
  () => {
@@ -25640,7 +25639,6 @@ async function retain(content, ctx, options = {}) {
25640
25639
  }
25641
25640
  }
25642
25641
  const embedding = await generateEmbedding(trimmed, ctx.embeddingOptions);
25643
- ctx.vaultCache.set(trimmed, embedding);
25644
25642
  const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
25645
25643
  const created = await createVaultMemoryOp(ctx.vaultCtx, {
25646
25644
  content: trimmed,
@@ -25661,6 +25659,7 @@ async function retain(content, ctx, options = {}) {
25661
25659
  }
25662
25660
  }
25663
25661
  });
25662
+ ctx.vaultCache.set(created.uniqueId, Float32Array.from(embedding));
25664
25663
  return {
25665
25664
  action: "create",
25666
25665
  memoryId: created.uniqueId,
@@ -25737,7 +25736,6 @@ async function tryConsolidate(trimmed, ctx, options) {
25737
25736
  options.sourceChunkIds ?? []
25738
25737
  );
25739
25738
  const newEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
25740
- ctx.vaultCache.set(decision.content, newEmbedding);
25741
25739
  const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
25742
25740
  const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
25743
25741
  const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
@@ -25757,6 +25755,7 @@ async function tryConsolidate(trimmed, ctx, options) {
25757
25755
  await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
25758
25756
  return null;
25759
25757
  }
25758
+ ctx.vaultCache.set(decision.targetId, Float32Array.from(newEmbedding));
25760
25759
  return {
25761
25760
  action: "update",
25762
25761
  memoryId: decision.targetId,
@@ -5311,7 +5311,9 @@ interface RecencyOptions {
5311
5311
 
5312
5312
  declare const DEFAULT_VAULT_CACHE_SIZE = 5000;
5313
5313
  /**
5314
- * Create a VaultEmbeddingCache backed by an LRU with a default cap of 1000 entries.
5314
+ * Create a VaultEmbeddingCache backed by an LRU with a default cap of
5315
+ * DEFAULT_VAULT_CACHE_SIZE entries. Values are Float32Array — the model's
5316
+ * native precision — not float64 number[], halving resident RAM losslessly.
5315
5317
  */
5316
5318
  declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCache;
5317
5319
 
@@ -5326,7 +5328,7 @@ declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCach
5326
5328
  * Embedding cache keyed by content string. Stores pre-computed embeddings
5327
5329
  * so that search only needs to embed the query, not the vault entries.
5328
5330
  */
5329
- type VaultEmbeddingCache = Map<string, number[]>;
5331
+ type VaultEmbeddingCache = Map<string, Float32Array>;
5330
5332
  /**
5331
5333
  * Options for the vault search tool.
5332
5334
  */
@@ -5311,7 +5311,9 @@ interface RecencyOptions {
5311
5311
 
5312
5312
  declare const DEFAULT_VAULT_CACHE_SIZE = 5000;
5313
5313
  /**
5314
- * Create a VaultEmbeddingCache backed by an LRU with a default cap of 1000 entries.
5314
+ * Create a VaultEmbeddingCache backed by an LRU with a default cap of
5315
+ * DEFAULT_VAULT_CACHE_SIZE entries. Values are Float32Array — the model's
5316
+ * native precision — not float64 number[], halving resident RAM losslessly.
5315
5317
  */
5316
5318
  declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCache;
5317
5319
 
@@ -5326,7 +5328,7 @@ declare function createVaultEmbeddingCache(maxSize?: number): VaultEmbeddingCach
5326
5328
  * Embedding cache keyed by content string. Stores pre-computed embeddings
5327
5329
  * so that search only needs to embed the query, not the vault entries.
5328
5330
  */
5329
- type VaultEmbeddingCache = Map<string, number[]>;
5331
+ type VaultEmbeddingCache = Map<string, Float32Array>;
5330
5332
  /**
5331
5333
  * Options for the vault search tool.
5332
5334
  */
@@ -95,7 +95,7 @@ import {
95
95
  updateVaultMemoryEmbeddingOp,
96
96
  updateVaultMemoryOp,
97
97
  upsertMessageOp
98
- } from "./chunk-SJLYHCMG.mjs";
98
+ } from "./chunk-P7KA2HAM.mjs";
99
99
  import {
100
100
  createStreamingDeAnonymizer,
101
101
  resolvePiiRedactor
@@ -4595,9 +4595,7 @@ function createMemoryVaultTool(vaultCtx, options, embeddingOptions, cache) {
4595
4595
  return `Error: Failed to update memory "${id}".`;
4596
4596
  }
4597
4597
  if (embeddingOptions && cache) {
4598
- if (previousContent) {
4599
- cache.delete(previousContent);
4600
- }
4598
+ cache.delete(id);
4601
4599
  eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, id).catch(
4602
4600
  // Silently swallow – SDK must not use console.*; embedding will be retried on next search
4603
4601
  () => {
@@ -4699,7 +4697,6 @@ async function retain(content, ctx, options = {}) {
4699
4697
  }
4700
4698
  }
4701
4699
  const embedding = await generateEmbedding(trimmed, ctx.embeddingOptions);
4702
- ctx.vaultCache.set(trimmed, embedding);
4703
4700
  const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
4704
4701
  const created = await createVaultMemoryOp(ctx.vaultCtx, {
4705
4702
  content: trimmed,
@@ -4720,6 +4717,7 @@ async function retain(content, ctx, options = {}) {
4720
4717
  }
4721
4718
  }
4722
4719
  });
4720
+ ctx.vaultCache.set(created.uniqueId, Float32Array.from(embedding));
4723
4721
  return {
4724
4722
  action: "create",
4725
4723
  memoryId: created.uniqueId,
@@ -4796,7 +4794,6 @@ async function tryConsolidate(trimmed, ctx, options) {
4796
4794
  options.sourceChunkIds ?? []
4797
4795
  );
4798
4796
  const newEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
4799
- ctx.vaultCache.set(decision.content, newEmbedding);
4800
4797
  const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
4801
4798
  const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
4802
4799
  const updated = await updateVaultMemoryOp(ctx.vaultCtx, decision.targetId, {
@@ -4816,6 +4813,7 @@ async function tryConsolidate(trimmed, ctx, options) {
4816
4813
  await assertMergeTargetGoneOrThrow(ctx, decision.targetId);
4817
4814
  return null;
4818
4815
  }
4816
+ ctx.vaultCache.set(decision.targetId, Float32Array.from(newEmbedding));
4819
4817
  return {
4820
4818
  action: "update",
4821
4819
  memoryId: decision.targetId,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  recall
3
- } from "./chunk-SJLYHCMG.mjs";
3
+ } from "./chunk-P7KA2HAM.mjs";
4
4
  import "./chunk-RCCKRTBI.mjs";
5
5
  import "./chunk-FMGZTVXQ.mjs";
6
6
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "1.4.1",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",