@anuma/sdk 1.4.0 → 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.
@@ -121,7 +121,7 @@ import {
121
121
  updateVaultMemoryEmbeddingOp,
122
122
  updateVaultMemoryOp,
123
123
  useEncryption
124
- } from "./chunk-SEZCFG24.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-SEZCFG24.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-24ZIA2VL.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-Z7CJGOTG.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-Z7CJGOTG.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.0",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",
@@ -145,7 +145,7 @@
145
145
  "homepage": "https://github.com/anuma-ai/sdk#readme",
146
146
  "packageManager": "pnpm@10.23.0",
147
147
  "dependencies": {
148
- "@anuma/portal": "1.0.0-next.20260709030454",
148
+ "@anuma/portal": "1.0.0-next.20260715224031",
149
149
  "@babel/parser": "^7.29.2",
150
150
  "@babel/types": "^7.29.0",
151
151
  "ai": "6.0.202",