@anuma/sdk 7.0.4 → 7.0.5

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.
@@ -5496,6 +5496,24 @@ var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v
5496
5496
  // src/lib/memoryEngine/generate.ts
5497
5497
  init_clientConfig();
5498
5498
  init_taskType();
5499
+
5500
+ // src/lib/memoryEngine/embeddingCacheState.ts
5501
+ var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
5502
+ var cacheGlobal = globalThis;
5503
+ var fallbackState = {
5504
+ scopedViews: /* @__PURE__ */ new WeakMap(),
5505
+ inFlightByCache: /* @__PURE__ */ new WeakMap(),
5506
+ cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
5507
+ };
5508
+ function getEmbeddingCacheState() {
5509
+ try {
5510
+ return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
5511
+ } catch {
5512
+ return fallbackState;
5513
+ }
5514
+ }
5515
+
5516
+ // src/lib/memoryEngine/generate.ts
5499
5517
  var EMBED_MAX_ATTEMPTS = 4;
5500
5518
  var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
5501
5519
  var DEFAULT_EMBEDDING_TOKEN_TIMEOUT_MS = 1e4;
@@ -5586,15 +5604,18 @@ async function generateEmbedding(text14, options) {
5586
5604
  if (total === void 0) return embedOne(text14, options, void 0);
5587
5605
  return withDeadline((signal) => embedOne(text14, options, signal), total, "embedding");
5588
5606
  }
5589
- var inFlightByCache = /* @__PURE__ */ new WeakMap();
5607
+ var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
5590
5608
  async function embedOne(text14, options, outer) {
5591
5609
  const { cache } = options;
5592
5610
  if (!cache) return Array.from(await requestEmbedding(text14, options, outer));
5611
+ const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
5593
5612
  const cached = cache.get(text14);
5594
- if (cached) return Array.from(cached);
5613
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
5614
+ if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
5595
5615
  const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
5596
5616
  inFlightByCache.set(cache, inFlight);
5597
- const pending = inFlight.get(text14);
5617
+ const requestKey = JSON.stringify([model, text14]);
5618
+ const pending = inFlight.get(requestKey);
5598
5619
  if (pending) {
5599
5620
  try {
5600
5621
  return Array.from(await pending);
@@ -5603,13 +5624,14 @@ async function embedOne(text14, options, outer) {
5603
5624
  }
5604
5625
  }
5605
5626
  const request = requestEmbedding(text14, options, outer);
5606
- inFlight.set(text14, request);
5627
+ inFlight.set(requestKey, request);
5607
5628
  try {
5608
5629
  const embedding2 = await request;
5630
+ cachedEmbeddingModels.set(embedding2, model);
5609
5631
  cache.set(text14, embedding2);
5610
5632
  return Array.from(embedding2);
5611
5633
  } finally {
5612
- if (inFlight.get(text14) === request) inFlight.delete(text14);
5634
+ if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
5613
5635
  }
5614
5636
  }
5615
5637
  async function requestEmbedding(text14, options, outer) {
@@ -5692,13 +5714,15 @@ async function embedMany(texts, options, outer) {
5692
5714
  const { baseUrl = BASE_URL, model, batchSize, cache } = options;
5693
5715
  const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
5694
5716
  const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
5717
+ const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
5695
5718
  const results = new Array(texts.length).fill(null);
5696
5719
  const uncachedIndices = [];
5697
5720
  const uncachedTexts = [];
5698
5721
  for (let i = 0; i < texts.length; i++) {
5699
5722
  if (cache) {
5700
5723
  const cached = cache.get(texts[i]);
5701
- if (cached) {
5724
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
5725
+ if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
5702
5726
  results[i] = Array.from(cached);
5703
5727
  continue;
5704
5728
  }
@@ -5714,7 +5738,6 @@ async function embedMany(texts, options, outer) {
5714
5738
  ...taskTypeHeader(options.taskType)
5715
5739
  };
5716
5740
  if (outer?.aborted) throw outer.reason;
5717
- const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
5718
5741
  let newEmbeddings;
5719
5742
  if (uncachedTexts.length <= chunkSize) {
5720
5743
  newEmbeddings = await generateEmbeddingsBatch(
@@ -5762,6 +5785,7 @@ async function embedMany(texts, options, outer) {
5762
5785
  const f32Embedding = Float32Array.from(newEmbeddings[i]);
5763
5786
  results[uncachedIndices[i]] = Array.from(f32Embedding);
5764
5787
  if (cache) {
5788
+ cachedEmbeddingModels.set(f32Embedding, embeddingModel);
5765
5789
  cache.set(uncachedTexts[i], f32Embedding);
5766
5790
  }
5767
5791
  }
@@ -11203,7 +11227,7 @@ var MaskScopedEmbeddingCache = class extends Map {
11203
11227
  return this;
11204
11228
  }
11205
11229
  };
11206
- var scopedViews = /* @__PURE__ */ new WeakMap();
11230
+ var { scopedViews } = getEmbeddingCacheState();
11207
11231
  function maskScopedEmbeddingCache(cache, masked) {
11208
11232
  const views = scopedViews.get(cache) ?? {};
11209
11233
  scopedViews.set(cache, views);
@@ -19401,44 +19425,48 @@ async function recall(query, ctx, options = {}) {
19401
19425
  embeddingOptions,
19402
19426
  ctx.vaultCache,
19403
19427
  searchOptions
19404
- )))(query, {
19405
- limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
19406
- minSimilarity: vaultMinScore,
19407
- useFusion: true,
19408
- rerank: flags.rerank,
19409
- ...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
19410
- ...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
19411
- ...options.rerankLoadTimeoutMs !== void 0 && {
19412
- rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
19413
- },
19414
- ...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
19415
- ...options.recency && { recency: options.recency },
19416
- ...options.mmr !== void 0 && { mmr: options.mmr },
19417
- ...options.supersessionBoost !== void 0 && {
19418
- supersessionBoost: options.supersessionBoost
19419
- },
19420
- ...options.supersessionWindow !== void 0 && {
19421
- supersessionWindow: options.supersessionWindow
19422
- },
19423
- ...options.proofCountAlpha !== void 0 && {
19424
- proofCountAlpha: options.proofCountAlpha
19425
- },
19426
- ...options.bm25AdmissionDivisor !== void 0 && {
19427
- bm25AdmissionDivisor: options.bm25AdmissionDivisor
19428
+ )))(
19429
+ query,
19430
+ {
19431
+ limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
19432
+ minSimilarity: vaultMinScore,
19433
+ useFusion: true,
19434
+ rerank: flags.rerank,
19435
+ ...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
19436
+ ...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
19437
+ ...options.rerankLoadTimeoutMs !== void 0 && {
19438
+ rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
19439
+ },
19440
+ ...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
19441
+ ...options.recency && { recency: options.recency },
19442
+ ...options.mmr !== void 0 && { mmr: options.mmr },
19443
+ ...options.supersessionBoost !== void 0 && {
19444
+ supersessionBoost: options.supersessionBoost
19445
+ },
19446
+ ...options.supersessionWindow !== void 0 && {
19447
+ supersessionWindow: options.supersessionWindow
19448
+ },
19449
+ ...options.proofCountAlpha !== void 0 && {
19450
+ proofCountAlpha: options.proofCountAlpha
19451
+ },
19452
+ ...options.bm25AdmissionDivisor !== void 0 && {
19453
+ bm25AdmissionDivisor: options.bm25AdmissionDivisor
19454
+ },
19455
+ ...options.rrfK !== void 0 && { rrfK: options.rrfK },
19456
+ ...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
19457
+ ...subQueries && { subQueries },
19458
+ ...options.scopes && { scopes: options.scopes },
19459
+ ...options.folderId !== void 0 && { folderId: options.folderId },
19460
+ ...options.factTypes?.length && { factTypes: options.factTypes },
19461
+ ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
19462
+ ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
19463
+ ...entityRanking.length > 0 && { entityRanking },
19464
+ ...temporalRanking.length > 0 && { temporalRanking },
19465
+ ...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
19466
+ queryEmbedTotalTimeoutMs
19428
19467
  },
19429
- ...options.rrfK !== void 0 && { rrfK: options.rrfK },
19430
- ...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
19431
- ...subQueries && { subQueries },
19432
- ...options.scopes && { scopes: options.scopes },
19433
- ...options.folderId !== void 0 && { folderId: options.folderId },
19434
- ...options.factTypes?.length && { factTypes: options.factTypes },
19435
- ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
19436
- ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
19437
- ...entityRanking.length > 0 && { entityRanking },
19438
- ...temporalRanking.length > 0 && { temporalRanking },
19439
- ...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
19440
- queryEmbedTotalTimeoutMs
19441
- });
19468
+ options.embeddingCache
19469
+ );
19442
19470
  factResults.push(
19443
19471
  ...dedupeBy(
19444
19472
  results,
@@ -20585,10 +20613,19 @@ function createLocalMemoryStore(options) {
20585
20613
  retainOptions
20586
20614
  ),
20587
20615
  factSource: {
20588
- search: (query, searchOptions) => searchVaultMemoriesWithSize(
20616
+ search: (query, searchOptions, embeddingCache) => searchVaultMemoriesWithSize(
20589
20617
  query,
20590
20618
  vaultCtx,
20591
- { ...options.embeddingOptions, taskType: "memory_recall_embed" },
20619
+ {
20620
+ ...options.embeddingOptions,
20621
+ taskType: "memory_recall_embed",
20622
+ ...embeddingCache && !options.embeddingOptions.cache && {
20623
+ cache: maskScopedEmbeddingCache(
20624
+ embeddingCache,
20625
+ Boolean(options.embeddingOptions.maskInput)
20626
+ )
20627
+ }
20628
+ },
20592
20629
  vaultCache,
20593
20630
  searchOptions
20594
20631
  ),
@@ -21220,7 +21257,7 @@ function stored(row) {
21220
21257
  function createRemoteMemoryPipeline(options) {
21221
21258
  const { persistence, embeddingOptions } = options;
21222
21259
  const model = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
21223
- const operation = (mode) => {
21260
+ const operation = (mode, queryOptions = embeddingOptions) => {
21224
21261
  const rejectUndecryptable = (failed) => {
21225
21262
  if (!failed.length) return;
21226
21263
  if (mode === "retain")
@@ -21251,7 +21288,7 @@ function createRemoteMemoryPipeline(options) {
21251
21288
  const start = Date.now();
21252
21289
  const budgetMs = search.queryEmbedTotalTimeoutMs ?? 8e3;
21253
21290
  const embed = (texts) => generateEmbeddings(texts, {
21254
- ...embeddingOptions,
21291
+ ...queryOptions,
21255
21292
  taskType: mode === "retain" ? "memory_retain_embed" : "memory_recall_embed",
21256
21293
  totalTimeoutMs: budgetMs
21257
21294
  });
@@ -21271,7 +21308,11 @@ function createRemoteMemoryPipeline(options) {
21271
21308
  }
21272
21309
  };
21273
21310
  const [primary, facetEmbeddings] = await Promise.all([
21274
- search.queryEmbedding ?? embed([query]).then((vectors2) => vectors2[0]),
21311
+ search.queryEmbedding ?? (mode === "recall" && queryOptions.cache ? generateEmbedding(query, {
21312
+ ...queryOptions,
21313
+ taskType: "memory_recall_embed",
21314
+ totalTimeoutMs: budgetMs
21315
+ }) : embed([query]).then((vectors2) => vectors2[0])),
21275
21316
  embedFacets()
21276
21317
  ]);
21277
21318
  const queryEmbedding = storedVector(primary);
@@ -21495,15 +21536,17 @@ function createRemoteMemoryPipeline(options) {
21495
21536
  const factSource = {
21496
21537
  graphRanking: options.graphRanking,
21497
21538
  temporalRanking: options.temporalRanking,
21498
- search: async (text14, searchOptions) => {
21499
- const { prepare } = operation("recall");
21539
+ search: async (text14, searchOptions, embeddingCache) => {
21540
+ const queryOptions = {
21541
+ ...embeddingOptions,
21542
+ taskType: "memory_recall_embed",
21543
+ ...embeddingCache && !embeddingOptions.cache && {
21544
+ cache: maskScopedEmbeddingCache(embeddingCache, Boolean(embeddingOptions.maskInput))
21545
+ }
21546
+ };
21547
+ const { prepare } = operation("recall", queryOptions);
21500
21548
  const prepared = await prepare(text14, searchOptions);
21501
- const ranked = await rankPreparedVaultCandidates(
21502
- text14,
21503
- prepared,
21504
- { ...embeddingOptions, taskType: "memory_recall_embed" },
21505
- searchOptions
21506
- );
21549
+ const ranked = await rankPreparedVaultCandidates(text14, prepared, queryOptions, searchOptions);
21507
21550
  return {
21508
21551
  ...ranked,
21509
21552
  rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
@@ -4508,7 +4508,7 @@ interface RecallOptions {
4508
4508
  }
4509
4509
  /** A fact source supplies bounded candidates; recall owns ranking and result handling. */
4510
4510
  interface RecallFactSource {
4511
- search: (query: string, options?: MemoryVaultSearchOptions) => ReturnType<typeof searchVaultMemoriesWithSize>;
4511
+ search: (query: string, options?: MemoryVaultSearchOptions, embeddingCache?: Map<string, Float32Array>) => ReturnType<typeof searchVaultMemoriesWithSize>;
4512
4512
  graphRanking: (query: string, traverse: boolean, options: RecallOptions) => Promise<string[]>;
4513
4513
  temporalRanking: (query: string, now?: number) => Promise<string[]>;
4514
4514
  }
@@ -7990,13 +7990,6 @@ declare const chatStorageMigrations: Readonly<{
7990
7990
  sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
7991
7991
  }>;
7992
7992
 
7993
- /**
7994
- * Namespacing for a caller-shared embedding cache.
7995
- *
7996
- * Lives here, next to the `embeddingCache` send-arg it serves, rather than in either platform hook:
7997
- * react and expo both thread the option through their own send paths, and a copy per platform is how
7998
- * the two drift.
7999
- */
8000
7993
  declare function maskScopedEmbeddingCache(cache: Map<string, Float32Array>, masked: boolean): Map<string, Float32Array>;
8001
7994
 
8002
7995
  /**
@@ -4508,7 +4508,7 @@ interface RecallOptions {
4508
4508
  }
4509
4509
  /** A fact source supplies bounded candidates; recall owns ranking and result handling. */
4510
4510
  interface RecallFactSource {
4511
- search: (query: string, options?: MemoryVaultSearchOptions) => ReturnType<typeof searchVaultMemoriesWithSize>;
4511
+ search: (query: string, options?: MemoryVaultSearchOptions, embeddingCache?: Map<string, Float32Array>) => ReturnType<typeof searchVaultMemoriesWithSize>;
4512
4512
  graphRanking: (query: string, traverse: boolean, options: RecallOptions) => Promise<string[]>;
4513
4513
  temporalRanking: (query: string, now?: number) => Promise<string[]>;
4514
4514
  }
@@ -7990,13 +7990,6 @@ declare const chatStorageMigrations: Readonly<{
7990
7990
  sortedMigrations: _nozbe_watermelondb_Schema_migrations.Migration[];
7991
7991
  }>;
7992
7992
 
7993
- /**
7994
- * Namespacing for a caller-shared embedding cache.
7995
- *
7996
- * Lives here, next to the `embeddingCache` send-arg it serves, rather than in either platform hook:
7997
- * react and expo both thread the option through their own send paths, and a copy per platform is how
7998
- * the two drift.
7999
- */
8000
7993
  declare function maskScopedEmbeddingCache(cache: Map<string, Float32Array>, masked: boolean): Map<string, Float32Array>;
8001
7994
 
8002
7995
  /**
@@ -3916,6 +3916,22 @@ var postApiV1Embeddings = (options) => (options.client ?? client).post({
3916
3916
  });
3917
3917
  var getApiV1Models = (options) => (options?.client ?? client).get({ url: "/api/v1/models", ...options });
3918
3918
 
3919
+ // src/lib/memoryEngine/embeddingCacheState.ts
3920
+ var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
3921
+ var cacheGlobal = globalThis;
3922
+ var fallbackState = {
3923
+ scopedViews: /* @__PURE__ */ new WeakMap(),
3924
+ inFlightByCache: /* @__PURE__ */ new WeakMap(),
3925
+ cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
3926
+ };
3927
+ function getEmbeddingCacheState() {
3928
+ try {
3929
+ return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
3930
+ } catch {
3931
+ return fallbackState;
3932
+ }
3933
+ }
3934
+
3919
3935
  // src/lib/memoryEngine/generate.ts
3920
3936
  var EMBED_MAX_ATTEMPTS = 4;
3921
3937
  var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
@@ -4007,15 +4023,18 @@ async function generateEmbedding(text14, options) {
4007
4023
  if (total === void 0) return embedOne(text14, options, void 0);
4008
4024
  return withDeadline((signal) => embedOne(text14, options, signal), total, "embedding");
4009
4025
  }
4010
- var inFlightByCache = /* @__PURE__ */ new WeakMap();
4026
+ var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
4011
4027
  async function embedOne(text14, options, outer) {
4012
4028
  const { cache } = options;
4013
4029
  if (!cache) return Array.from(await requestEmbedding(text14, options, outer));
4030
+ const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
4014
4031
  const cached = cache.get(text14);
4015
- if (cached) return Array.from(cached);
4032
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
4033
+ if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
4016
4034
  const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
4017
4035
  inFlightByCache.set(cache, inFlight);
4018
- const pending = inFlight.get(text14);
4036
+ const requestKey = JSON.stringify([model, text14]);
4037
+ const pending = inFlight.get(requestKey);
4019
4038
  if (pending) {
4020
4039
  try {
4021
4040
  return Array.from(await pending);
@@ -4024,13 +4043,14 @@ async function embedOne(text14, options, outer) {
4024
4043
  }
4025
4044
  }
4026
4045
  const request = requestEmbedding(text14, options, outer);
4027
- inFlight.set(text14, request);
4046
+ inFlight.set(requestKey, request);
4028
4047
  try {
4029
4048
  const embedding2 = await request;
4049
+ cachedEmbeddingModels.set(embedding2, model);
4030
4050
  cache.set(text14, embedding2);
4031
4051
  return Array.from(embedding2);
4032
4052
  } finally {
4033
- if (inFlight.get(text14) === request) inFlight.delete(text14);
4053
+ if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
4034
4054
  }
4035
4055
  }
4036
4056
  async function requestEmbedding(text14, options, outer) {
@@ -4113,13 +4133,15 @@ async function embedMany(texts, options, outer) {
4113
4133
  const { baseUrl = BASE_URL, model, batchSize, cache } = options;
4114
4134
  const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
4115
4135
  const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
4136
+ const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
4116
4137
  const results = new Array(texts.length).fill(null);
4117
4138
  const uncachedIndices = [];
4118
4139
  const uncachedTexts = [];
4119
4140
  for (let i = 0; i < texts.length; i++) {
4120
4141
  if (cache) {
4121
4142
  const cached = cache.get(texts[i]);
4122
- if (cached) {
4143
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
4144
+ if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
4123
4145
  results[i] = Array.from(cached);
4124
4146
  continue;
4125
4147
  }
@@ -4135,7 +4157,6 @@ async function embedMany(texts, options, outer) {
4135
4157
  ...taskTypeHeader(options.taskType)
4136
4158
  };
4137
4159
  if (outer?.aborted) throw outer.reason;
4138
- const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
4139
4160
  let newEmbeddings;
4140
4161
  if (uncachedTexts.length <= chunkSize) {
4141
4162
  newEmbeddings = await generateEmbeddingsBatch(
@@ -4183,6 +4204,7 @@ async function embedMany(texts, options, outer) {
4183
4204
  const f32Embedding = Float32Array.from(newEmbeddings[i]);
4184
4205
  results[uncachedIndices[i]] = Array.from(f32Embedding);
4185
4206
  if (cache) {
4207
+ cachedEmbeddingModels.set(f32Embedding, embeddingModel);
4186
4208
  cache.set(uncachedTexts[i], f32Embedding);
4187
4209
  }
4188
4210
  }
@@ -9610,7 +9632,7 @@ var MaskScopedEmbeddingCache = class extends Map {
9610
9632
  return this;
9611
9633
  }
9612
9634
  };
9613
- var scopedViews = /* @__PURE__ */ new WeakMap();
9635
+ var { scopedViews } = getEmbeddingCacheState();
9614
9636
  function maskScopedEmbeddingCache(cache, masked) {
9615
9637
  const views = scopedViews.get(cache) ?? {};
9616
9638
  scopedViews.set(cache, views);
@@ -17774,44 +17796,48 @@ async function recall(query, ctx, options = {}) {
17774
17796
  embeddingOptions,
17775
17797
  ctx.vaultCache,
17776
17798
  searchOptions
17777
- )))(query, {
17778
- limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
17779
- minSimilarity: vaultMinScore,
17780
- useFusion: true,
17781
- rerank: flags.rerank,
17782
- ...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
17783
- ...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
17784
- ...options.rerankLoadTimeoutMs !== void 0 && {
17785
- rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
17786
- },
17787
- ...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
17788
- ...options.recency && { recency: options.recency },
17789
- ...options.mmr !== void 0 && { mmr: options.mmr },
17790
- ...options.supersessionBoost !== void 0 && {
17791
- supersessionBoost: options.supersessionBoost
17792
- },
17793
- ...options.supersessionWindow !== void 0 && {
17794
- supersessionWindow: options.supersessionWindow
17795
- },
17796
- ...options.proofCountAlpha !== void 0 && {
17797
- proofCountAlpha: options.proofCountAlpha
17798
- },
17799
- ...options.bm25AdmissionDivisor !== void 0 && {
17800
- bm25AdmissionDivisor: options.bm25AdmissionDivisor
17799
+ )))(
17800
+ query,
17801
+ {
17802
+ limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
17803
+ minSimilarity: vaultMinScore,
17804
+ useFusion: true,
17805
+ rerank: flags.rerank,
17806
+ ...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
17807
+ ...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
17808
+ ...options.rerankLoadTimeoutMs !== void 0 && {
17809
+ rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
17810
+ },
17811
+ ...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
17812
+ ...options.recency && { recency: options.recency },
17813
+ ...options.mmr !== void 0 && { mmr: options.mmr },
17814
+ ...options.supersessionBoost !== void 0 && {
17815
+ supersessionBoost: options.supersessionBoost
17816
+ },
17817
+ ...options.supersessionWindow !== void 0 && {
17818
+ supersessionWindow: options.supersessionWindow
17819
+ },
17820
+ ...options.proofCountAlpha !== void 0 && {
17821
+ proofCountAlpha: options.proofCountAlpha
17822
+ },
17823
+ ...options.bm25AdmissionDivisor !== void 0 && {
17824
+ bm25AdmissionDivisor: options.bm25AdmissionDivisor
17825
+ },
17826
+ ...options.rrfK !== void 0 && { rrfK: options.rrfK },
17827
+ ...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
17828
+ ...subQueries && { subQueries },
17829
+ ...options.scopes && { scopes: options.scopes },
17830
+ ...options.folderId !== void 0 && { folderId: options.folderId },
17831
+ ...options.factTypes?.length && { factTypes: options.factTypes },
17832
+ ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
17833
+ ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
17834
+ ...entityRanking.length > 0 && { entityRanking },
17835
+ ...temporalRanking.length > 0 && { temporalRanking },
17836
+ ...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
17837
+ queryEmbedTotalTimeoutMs
17801
17838
  },
17802
- ...options.rrfK !== void 0 && { rrfK: options.rrfK },
17803
- ...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
17804
- ...subQueries && { subQueries },
17805
- ...options.scopes && { scopes: options.scopes },
17806
- ...options.folderId !== void 0 && { folderId: options.folderId },
17807
- ...options.factTypes?.length && { factTypes: options.factTypes },
17808
- ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
17809
- ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
17810
- ...entityRanking.length > 0 && { entityRanking },
17811
- ...temporalRanking.length > 0 && { temporalRanking },
17812
- ...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
17813
- queryEmbedTotalTimeoutMs
17814
- });
17839
+ options.embeddingCache
17840
+ );
17815
17841
  factResults.push(
17816
17842
  ...dedupeBy(
17817
17843
  results,
@@ -18950,10 +18976,19 @@ function createLocalMemoryStore(options) {
18950
18976
  retainOptions
18951
18977
  ),
18952
18978
  factSource: {
18953
- search: (query, searchOptions) => searchVaultMemoriesWithSize(
18979
+ search: (query, searchOptions, embeddingCache) => searchVaultMemoriesWithSize(
18954
18980
  query,
18955
18981
  vaultCtx,
18956
- { ...options.embeddingOptions, taskType: "memory_recall_embed" },
18982
+ {
18983
+ ...options.embeddingOptions,
18984
+ taskType: "memory_recall_embed",
18985
+ ...embeddingCache && !options.embeddingOptions.cache && {
18986
+ cache: maskScopedEmbeddingCache(
18987
+ embeddingCache,
18988
+ Boolean(options.embeddingOptions.maskInput)
18989
+ )
18990
+ }
18991
+ },
18957
18992
  vaultCache,
18958
18993
  searchOptions
18959
18994
  ),
@@ -19583,7 +19618,7 @@ function stored(row) {
19583
19618
  function createRemoteMemoryPipeline(options) {
19584
19619
  const { persistence, embeddingOptions } = options;
19585
19620
  const model = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
19586
- const operation = (mode) => {
19621
+ const operation = (mode, queryOptions = embeddingOptions) => {
19587
19622
  const rejectUndecryptable = (failed) => {
19588
19623
  if (!failed.length) return;
19589
19624
  if (mode === "retain")
@@ -19614,7 +19649,7 @@ function createRemoteMemoryPipeline(options) {
19614
19649
  const start = Date.now();
19615
19650
  const budgetMs = search.queryEmbedTotalTimeoutMs ?? 8e3;
19616
19651
  const embed = (texts) => generateEmbeddings(texts, {
19617
- ...embeddingOptions,
19652
+ ...queryOptions,
19618
19653
  taskType: mode === "retain" ? "memory_retain_embed" : "memory_recall_embed",
19619
19654
  totalTimeoutMs: budgetMs
19620
19655
  });
@@ -19634,7 +19669,11 @@ function createRemoteMemoryPipeline(options) {
19634
19669
  }
19635
19670
  };
19636
19671
  const [primary, facetEmbeddings] = await Promise.all([
19637
- search.queryEmbedding ?? embed([query]).then((vectors2) => vectors2[0]),
19672
+ search.queryEmbedding ?? (mode === "recall" && queryOptions.cache ? generateEmbedding(query, {
19673
+ ...queryOptions,
19674
+ taskType: "memory_recall_embed",
19675
+ totalTimeoutMs: budgetMs
19676
+ }) : embed([query]).then((vectors2) => vectors2[0])),
19638
19677
  embedFacets()
19639
19678
  ]);
19640
19679
  const queryEmbedding = storedVector(primary);
@@ -19858,15 +19897,17 @@ function createRemoteMemoryPipeline(options) {
19858
19897
  const factSource = {
19859
19898
  graphRanking: options.graphRanking,
19860
19899
  temporalRanking: options.temporalRanking,
19861
- search: async (text14, searchOptions) => {
19862
- const { prepare } = operation("recall");
19900
+ search: async (text14, searchOptions, embeddingCache) => {
19901
+ const queryOptions = {
19902
+ ...embeddingOptions,
19903
+ taskType: "memory_recall_embed",
19904
+ ...embeddingCache && !embeddingOptions.cache && {
19905
+ cache: maskScopedEmbeddingCache(embeddingCache, Boolean(embeddingOptions.maskInput))
19906
+ }
19907
+ };
19908
+ const { prepare } = operation("recall", queryOptions);
19863
19909
  const prepared = await prepare(text14, searchOptions);
19864
- const ranked = await rankPreparedVaultCandidates(
19865
- text14,
19866
- prepared,
19867
- { ...embeddingOptions, taskType: "memory_recall_embed" },
19868
- searchOptions
19869
- );
19910
+ const ranked = await rankPreparedVaultCandidates(text14, prepared, queryOptions, searchOptions);
19870
19911
  return {
19871
19912
  ...ranked,
19872
19913
  rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,