@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.
package/dist/index.cjs CHANGED
@@ -2089,6 +2089,22 @@ function taskTypeHeader(taskType) {
2089
2089
  return taskType ? { [TASK_TYPE_HEADER]: taskType } : {};
2090
2090
  }
2091
2091
 
2092
+ // src/lib/memoryEngine/embeddingCacheState.ts
2093
+ var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
2094
+ var cacheGlobal = globalThis;
2095
+ var fallbackState = {
2096
+ scopedViews: /* @__PURE__ */ new WeakMap(),
2097
+ inFlightByCache: /* @__PURE__ */ new WeakMap(),
2098
+ cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
2099
+ };
2100
+ function getEmbeddingCacheState() {
2101
+ try {
2102
+ return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
2103
+ } catch {
2104
+ return fallbackState;
2105
+ }
2106
+ }
2107
+
2092
2108
  // src/lib/memoryEngine/generate.ts
2093
2109
  var EMBED_MAX_ATTEMPTS = 4;
2094
2110
  var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
@@ -2177,15 +2193,18 @@ async function generateEmbedding(text2, options) {
2177
2193
  if (total === void 0) return embedOne(text2, options, void 0);
2178
2194
  return withDeadline((signal) => embedOne(text2, options, signal), total, "embedding");
2179
2195
  }
2180
- var inFlightByCache = /* @__PURE__ */ new WeakMap();
2196
+ var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
2181
2197
  async function embedOne(text2, options, outer) {
2182
2198
  const { cache } = options;
2183
2199
  if (!cache) return Array.from(await requestEmbedding(text2, options, outer));
2200
+ const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
2184
2201
  const cached = cache.get(text2);
2185
- if (cached) return Array.from(cached);
2202
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
2203
+ if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
2186
2204
  const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
2187
2205
  inFlightByCache.set(cache, inFlight);
2188
- const pending = inFlight.get(text2);
2206
+ const requestKey = JSON.stringify([model, text2]);
2207
+ const pending = inFlight.get(requestKey);
2189
2208
  if (pending) {
2190
2209
  try {
2191
2210
  return Array.from(await pending);
@@ -2194,13 +2213,14 @@ async function embedOne(text2, options, outer) {
2194
2213
  }
2195
2214
  }
2196
2215
  const request = requestEmbedding(text2, options, outer);
2197
- inFlight.set(text2, request);
2216
+ inFlight.set(requestKey, request);
2198
2217
  try {
2199
2218
  const embedding = await request;
2219
+ cachedEmbeddingModels.set(embedding, model);
2200
2220
  cache.set(text2, embedding);
2201
2221
  return Array.from(embedding);
2202
2222
  } finally {
2203
- if (inFlight.get(text2) === request) inFlight.delete(text2);
2223
+ if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
2204
2224
  }
2205
2225
  }
2206
2226
  async function requestEmbedding(text2, options, outer) {
@@ -2283,13 +2303,15 @@ async function embedMany(texts, options, outer) {
2283
2303
  const { baseUrl = BASE_URL, model, batchSize, cache } = options;
2284
2304
  const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
2285
2305
  const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
2306
+ const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
2286
2307
  const results = new Array(texts.length).fill(null);
2287
2308
  const uncachedIndices = [];
2288
2309
  const uncachedTexts = [];
2289
2310
  for (let i = 0; i < texts.length; i++) {
2290
2311
  if (cache) {
2291
2312
  const cached = cache.get(texts[i]);
2292
- if (cached) {
2313
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
2314
+ if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
2293
2315
  results[i] = Array.from(cached);
2294
2316
  continue;
2295
2317
  }
@@ -2305,7 +2327,6 @@ async function embedMany(texts, options, outer) {
2305
2327
  ...taskTypeHeader(options.taskType)
2306
2328
  };
2307
2329
  if (outer?.aborted) throw outer.reason;
2308
- const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
2309
2330
  let newEmbeddings;
2310
2331
  if (uncachedTexts.length <= chunkSize) {
2311
2332
  newEmbeddings = await generateEmbeddingsBatch(
@@ -2353,6 +2374,7 @@ async function embedMany(texts, options, outer) {
2353
2374
  const f32Embedding = Float32Array.from(newEmbeddings[i]);
2354
2375
  results[uncachedIndices[i]] = Array.from(f32Embedding);
2355
2376
  if (cache) {
2377
+ cachedEmbeddingModels.set(f32Embedding, embeddingModel);
2356
2378
  cache.set(uncachedTexts[i], f32Embedding);
2357
2379
  }
2358
2380
  }
package/dist/index.mjs CHANGED
@@ -1885,6 +1885,22 @@ function taskTypeHeader(taskType) {
1885
1885
  return taskType ? { [TASK_TYPE_HEADER]: taskType } : {};
1886
1886
  }
1887
1887
 
1888
+ // src/lib/memoryEngine/embeddingCacheState.ts
1889
+ var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
1890
+ var cacheGlobal = globalThis;
1891
+ var fallbackState = {
1892
+ scopedViews: /* @__PURE__ */ new WeakMap(),
1893
+ inFlightByCache: /* @__PURE__ */ new WeakMap(),
1894
+ cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
1895
+ };
1896
+ function getEmbeddingCacheState() {
1897
+ try {
1898
+ return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
1899
+ } catch {
1900
+ return fallbackState;
1901
+ }
1902
+ }
1903
+
1888
1904
  // src/lib/memoryEngine/generate.ts
1889
1905
  var EMBED_MAX_ATTEMPTS = 4;
1890
1906
  var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
@@ -1973,15 +1989,18 @@ async function generateEmbedding(text2, options) {
1973
1989
  if (total === void 0) return embedOne(text2, options, void 0);
1974
1990
  return withDeadline((signal) => embedOne(text2, options, signal), total, "embedding");
1975
1991
  }
1976
- var inFlightByCache = /* @__PURE__ */ new WeakMap();
1992
+ var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
1977
1993
  async function embedOne(text2, options, outer) {
1978
1994
  const { cache } = options;
1979
1995
  if (!cache) return Array.from(await requestEmbedding(text2, options, outer));
1996
+ const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
1980
1997
  const cached = cache.get(text2);
1981
- if (cached) return Array.from(cached);
1998
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
1999
+ if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
1982
2000
  const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
1983
2001
  inFlightByCache.set(cache, inFlight);
1984
- const pending = inFlight.get(text2);
2002
+ const requestKey = JSON.stringify([model, text2]);
2003
+ const pending = inFlight.get(requestKey);
1985
2004
  if (pending) {
1986
2005
  try {
1987
2006
  return Array.from(await pending);
@@ -1990,13 +2009,14 @@ async function embedOne(text2, options, outer) {
1990
2009
  }
1991
2010
  }
1992
2011
  const request = requestEmbedding(text2, options, outer);
1993
- inFlight.set(text2, request);
2012
+ inFlight.set(requestKey, request);
1994
2013
  try {
1995
2014
  const embedding = await request;
2015
+ cachedEmbeddingModels.set(embedding, model);
1996
2016
  cache.set(text2, embedding);
1997
2017
  return Array.from(embedding);
1998
2018
  } finally {
1999
- if (inFlight.get(text2) === request) inFlight.delete(text2);
2019
+ if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
2000
2020
  }
2001
2021
  }
2002
2022
  async function requestEmbedding(text2, options, outer) {
@@ -2079,13 +2099,15 @@ async function embedMany(texts, options, outer) {
2079
2099
  const { baseUrl = BASE_URL, model, batchSize, cache } = options;
2080
2100
  const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
2081
2101
  const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
2102
+ const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
2082
2103
  const results = new Array(texts.length).fill(null);
2083
2104
  const uncachedIndices = [];
2084
2105
  const uncachedTexts = [];
2085
2106
  for (let i = 0; i < texts.length; i++) {
2086
2107
  if (cache) {
2087
2108
  const cached = cache.get(texts[i]);
2088
- if (cached) {
2109
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
2110
+ if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
2089
2111
  results[i] = Array.from(cached);
2090
2112
  continue;
2091
2113
  }
@@ -2101,7 +2123,6 @@ async function embedMany(texts, options, outer) {
2101
2123
  ...taskTypeHeader(options.taskType)
2102
2124
  };
2103
2125
  if (outer?.aborted) throw outer.reason;
2104
- const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
2105
2126
  let newEmbeddings;
2106
2127
  if (uncachedTexts.length <= chunkSize) {
2107
2128
  newEmbeddings = await generateEmbeddingsBatch(
@@ -2149,6 +2170,7 @@ async function embedMany(texts, options, outer) {
2149
2170
  const f32Embedding = Float32Array.from(newEmbeddings[i]);
2150
2171
  results[uncachedIndices[i]] = Array.from(f32Embedding);
2151
2172
  if (cache) {
2173
+ cachedEmbeddingModels.set(f32Embedding, embeddingModel);
2152
2174
  cache.set(uncachedTexts[i], f32Embedding);
2153
2175
  }
2154
2176
  }
@@ -6319,6 +6319,24 @@ var deleteApiV1WalletsBindingByAddress = (options) => (options.client ?? client)
6319
6319
  // src/lib/memoryEngine/generate.ts
6320
6320
  init_clientConfig();
6321
6321
  init_taskType();
6322
+
6323
+ // src/lib/memoryEngine/embeddingCacheState.ts
6324
+ var EMBEDDING_CACHE_STATE_KEY = /* @__PURE__ */ Symbol.for("@anuma/sdk/embedding-cache/v1");
6325
+ var cacheGlobal = globalThis;
6326
+ var fallbackState = {
6327
+ scopedViews: /* @__PURE__ */ new WeakMap(),
6328
+ inFlightByCache: /* @__PURE__ */ new WeakMap(),
6329
+ cachedEmbeddingModels: /* @__PURE__ */ new WeakMap()
6330
+ };
6331
+ function getEmbeddingCacheState() {
6332
+ try {
6333
+ return cacheGlobal[EMBEDDING_CACHE_STATE_KEY] ?? (cacheGlobal[EMBEDDING_CACHE_STATE_KEY] = fallbackState);
6334
+ } catch {
6335
+ return fallbackState;
6336
+ }
6337
+ }
6338
+
6339
+ // src/lib/memoryEngine/generate.ts
6322
6340
  var EMBED_MAX_ATTEMPTS = 4;
6323
6341
  var DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS = 15e3;
6324
6342
  var DEFAULT_EMBEDDING_TOKEN_TIMEOUT_MS = 1e4;
@@ -6409,15 +6427,18 @@ async function generateEmbedding(text14, options) {
6409
6427
  if (total === void 0) return embedOne(text14, options, void 0);
6410
6428
  return withDeadline((signal) => embedOne(text14, options, signal), total, "embedding");
6411
6429
  }
6412
- var inFlightByCache = /* @__PURE__ */ new WeakMap();
6430
+ var { inFlightByCache, cachedEmbeddingModels } = getEmbeddingCacheState();
6413
6431
  async function embedOne(text14, options, outer) {
6414
6432
  const { cache } = options;
6415
6433
  if (!cache) return Array.from(await requestEmbedding(text14, options, outer));
6434
+ const model = options.model ?? DEFAULT_API_EMBEDDING_MODEL;
6416
6435
  const cached = cache.get(text14);
6417
- if (cached) return Array.from(cached);
6436
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
6437
+ if (cached && (cachedModel === void 0 || cachedModel === model)) return Array.from(cached);
6418
6438
  const inFlight = inFlightByCache.get(cache) ?? /* @__PURE__ */ new Map();
6419
6439
  inFlightByCache.set(cache, inFlight);
6420
- const pending = inFlight.get(text14);
6440
+ const requestKey = JSON.stringify([model, text14]);
6441
+ const pending = inFlight.get(requestKey);
6421
6442
  if (pending) {
6422
6443
  try {
6423
6444
  return Array.from(await pending);
@@ -6426,13 +6447,14 @@ async function embedOne(text14, options, outer) {
6426
6447
  }
6427
6448
  }
6428
6449
  const request = requestEmbedding(text14, options, outer);
6429
- inFlight.set(text14, request);
6450
+ inFlight.set(requestKey, request);
6430
6451
  try {
6431
6452
  const embedding2 = await request;
6453
+ cachedEmbeddingModels.set(embedding2, model);
6432
6454
  cache.set(text14, embedding2);
6433
6455
  return Array.from(embedding2);
6434
6456
  } finally {
6435
- if (inFlight.get(text14) === request) inFlight.delete(text14);
6457
+ if (inFlight.get(requestKey) === request) inFlight.delete(requestKey);
6436
6458
  }
6437
6459
  }
6438
6460
  async function requestEmbedding(text14, options, outer) {
@@ -6515,13 +6537,15 @@ async function embedMany(texts, options, outer) {
6515
6537
  const { baseUrl = BASE_URL, model, batchSize, cache } = options;
6516
6538
  const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
6517
6539
  const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
6540
+ const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
6518
6541
  const results = new Array(texts.length).fill(null);
6519
6542
  const uncachedIndices = [];
6520
6543
  const uncachedTexts = [];
6521
6544
  for (let i = 0; i < texts.length; i++) {
6522
6545
  if (cache) {
6523
6546
  const cached = cache.get(texts[i]);
6524
- if (cached) {
6547
+ const cachedModel = cached && cachedEmbeddingModels.get(cached);
6548
+ if (cached && (cachedModel === void 0 || cachedModel === embeddingModel)) {
6525
6549
  results[i] = Array.from(cached);
6526
6550
  continue;
6527
6551
  }
@@ -6537,7 +6561,6 @@ async function embedMany(texts, options, outer) {
6537
6561
  ...taskTypeHeader(options.taskType)
6538
6562
  };
6539
6563
  if (outer?.aborted) throw outer.reason;
6540
- const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
6541
6564
  let newEmbeddings;
6542
6565
  if (uncachedTexts.length <= chunkSize) {
6543
6566
  newEmbeddings = await generateEmbeddingsBatch(
@@ -6585,6 +6608,7 @@ async function embedMany(texts, options, outer) {
6585
6608
  const f32Embedding = Float32Array.from(newEmbeddings[i]);
6586
6609
  results[uncachedIndices[i]] = Array.from(f32Embedding);
6587
6610
  if (cache) {
6611
+ cachedEmbeddingModels.set(f32Embedding, embeddingModel);
6588
6612
  cache.set(uncachedTexts[i], f32Embedding);
6589
6613
  }
6590
6614
  }
@@ -21280,7 +21304,7 @@ var MaskScopedEmbeddingCache = class extends Map {
21280
21304
  return this;
21281
21305
  }
21282
21306
  };
21283
- var scopedViews = /* @__PURE__ */ new WeakMap();
21307
+ var { scopedViews } = getEmbeddingCacheState();
21284
21308
  function maskScopedEmbeddingCache(cache, masked) {
21285
21309
  const views = scopedViews.get(cache) ?? {};
21286
21310
  scopedViews.set(cache, views);
@@ -21705,44 +21729,48 @@ async function recall(query, ctx, options = {}) {
21705
21729
  embeddingOptions,
21706
21730
  ctx.vaultCache,
21707
21731
  searchOptions
21708
- )))(query, {
21709
- limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
21710
- minSimilarity: vaultMinScore,
21711
- useFusion: true,
21712
- rerank: flags.rerank,
21713
- ...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
21714
- ...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
21715
- ...options.rerankLoadTimeoutMs !== void 0 && {
21716
- rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
21717
- },
21718
- ...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
21719
- ...options.recency && { recency: options.recency },
21720
- ...options.mmr !== void 0 && { mmr: options.mmr },
21721
- ...options.supersessionBoost !== void 0 && {
21722
- supersessionBoost: options.supersessionBoost
21723
- },
21724
- ...options.supersessionWindow !== void 0 && {
21725
- supersessionWindow: options.supersessionWindow
21726
- },
21727
- ...options.proofCountAlpha !== void 0 && {
21728
- proofCountAlpha: options.proofCountAlpha
21729
- },
21730
- ...options.bm25AdmissionDivisor !== void 0 && {
21731
- bm25AdmissionDivisor: options.bm25AdmissionDivisor
21732
+ )))(
21733
+ query,
21734
+ {
21735
+ limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
21736
+ minSimilarity: vaultMinScore,
21737
+ useFusion: true,
21738
+ rerank: flags.rerank,
21739
+ ...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
21740
+ ...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
21741
+ ...options.rerankLoadTimeoutMs !== void 0 && {
21742
+ rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
21743
+ },
21744
+ ...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
21745
+ ...options.recency && { recency: options.recency },
21746
+ ...options.mmr !== void 0 && { mmr: options.mmr },
21747
+ ...options.supersessionBoost !== void 0 && {
21748
+ supersessionBoost: options.supersessionBoost
21749
+ },
21750
+ ...options.supersessionWindow !== void 0 && {
21751
+ supersessionWindow: options.supersessionWindow
21752
+ },
21753
+ ...options.proofCountAlpha !== void 0 && {
21754
+ proofCountAlpha: options.proofCountAlpha
21755
+ },
21756
+ ...options.bm25AdmissionDivisor !== void 0 && {
21757
+ bm25AdmissionDivisor: options.bm25AdmissionDivisor
21758
+ },
21759
+ ...options.rrfK !== void 0 && { rrfK: options.rrfK },
21760
+ ...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
21761
+ ...subQueries && { subQueries },
21762
+ ...options.scopes && { scopes: options.scopes },
21763
+ ...options.folderId !== void 0 && { folderId: options.folderId },
21764
+ ...options.factTypes?.length && { factTypes: options.factTypes },
21765
+ ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
21766
+ ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
21767
+ ...entityRanking.length > 0 && { entityRanking },
21768
+ ...temporalRanking.length > 0 && { temporalRanking },
21769
+ ...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
21770
+ queryEmbedTotalTimeoutMs
21732
21771
  },
21733
- ...options.rrfK !== void 0 && { rrfK: options.rrfK },
21734
- ...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
21735
- ...subQueries && { subQueries },
21736
- ...options.scopes && { scopes: options.scopes },
21737
- ...options.folderId !== void 0 && { folderId: options.folderId },
21738
- ...options.factTypes?.length && { factTypes: options.factTypes },
21739
- ...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
21740
- ...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
21741
- ...entityRanking.length > 0 && { entityRanking },
21742
- ...temporalRanking.length > 0 && { temporalRanking },
21743
- ...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
21744
- queryEmbedTotalTimeoutMs
21745
- });
21772
+ options.embeddingCache
21773
+ );
21746
21774
  factResults.push(
21747
21775
  ...dedupeBy(
21748
21776
  results,
@@ -22889,10 +22917,19 @@ function createLocalMemoryStore(options) {
22889
22917
  retainOptions
22890
22918
  ),
22891
22919
  factSource: {
22892
- search: (query, searchOptions) => searchVaultMemoriesWithSize(
22920
+ search: (query, searchOptions, embeddingCache) => searchVaultMemoriesWithSize(
22893
22921
  query,
22894
22922
  vaultCtx,
22895
- { ...options.embeddingOptions, taskType: "memory_recall_embed" },
22923
+ {
22924
+ ...options.embeddingOptions,
22925
+ taskType: "memory_recall_embed",
22926
+ ...embeddingCache && !options.embeddingOptions.cache && {
22927
+ cache: maskScopedEmbeddingCache(
22928
+ embeddingCache,
22929
+ Boolean(options.embeddingOptions.maskInput)
22930
+ )
22931
+ }
22932
+ },
22896
22933
  vaultCache,
22897
22934
  searchOptions
22898
22935
  ),
@@ -23524,7 +23561,7 @@ function stored(row) {
23524
23561
  function createRemoteMemoryPipeline(options) {
23525
23562
  const { persistence, embeddingOptions } = options;
23526
23563
  const model = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
23527
- const operation = (mode) => {
23564
+ const operation = (mode, queryOptions = embeddingOptions) => {
23528
23565
  const rejectUndecryptable = (failed) => {
23529
23566
  if (!failed.length) return;
23530
23567
  if (mode === "retain")
@@ -23555,7 +23592,7 @@ function createRemoteMemoryPipeline(options) {
23555
23592
  const start = Date.now();
23556
23593
  const budgetMs = search.queryEmbedTotalTimeoutMs ?? 8e3;
23557
23594
  const embed = (texts) => generateEmbeddings(texts, {
23558
- ...embeddingOptions,
23595
+ ...queryOptions,
23559
23596
  taskType: mode === "retain" ? "memory_retain_embed" : "memory_recall_embed",
23560
23597
  totalTimeoutMs: budgetMs
23561
23598
  });
@@ -23575,7 +23612,11 @@ function createRemoteMemoryPipeline(options) {
23575
23612
  }
23576
23613
  };
23577
23614
  const [primary, facetEmbeddings] = await Promise.all([
23578
- search.queryEmbedding ?? embed([query]).then((vectors2) => vectors2[0]),
23615
+ search.queryEmbedding ?? (mode === "recall" && queryOptions.cache ? generateEmbedding(query, {
23616
+ ...queryOptions,
23617
+ taskType: "memory_recall_embed",
23618
+ totalTimeoutMs: budgetMs
23619
+ }) : embed([query]).then((vectors2) => vectors2[0])),
23579
23620
  embedFacets()
23580
23621
  ]);
23581
23622
  const queryEmbedding = storedVector(primary);
@@ -23799,15 +23840,17 @@ function createRemoteMemoryPipeline(options) {
23799
23840
  const factSource = {
23800
23841
  graphRanking: options.graphRanking,
23801
23842
  temporalRanking: options.temporalRanking,
23802
- search: async (text14, searchOptions) => {
23803
- const { prepare } = operation("recall");
23843
+ search: async (text14, searchOptions, embeddingCache) => {
23844
+ const queryOptions = {
23845
+ ...embeddingOptions,
23846
+ taskType: "memory_recall_embed",
23847
+ ...embeddingCache && !embeddingOptions.cache && {
23848
+ cache: maskScopedEmbeddingCache(embeddingCache, Boolean(embeddingOptions.maskInput))
23849
+ }
23850
+ };
23851
+ const { prepare } = operation("recall", queryOptions);
23804
23852
  const prepared = await prepare(text14, searchOptions);
23805
- const ranked = await rankPreparedVaultCandidates(
23806
- text14,
23807
- prepared,
23808
- { ...embeddingOptions, taskType: "memory_recall_embed" },
23809
- searchOptions
23810
- );
23853
+ const ranked = await rankPreparedVaultCandidates(text14, prepared, queryOptions, searchOptions);
23811
23854
  return {
23812
23855
  ...ranked,
23813
23856
  rankedOnCosine: prepared.memories.length > 0 && !prepared.embeddingsUnavailable,
@@ -5021,7 +5021,7 @@ interface RecallOptions {
5021
5021
  }
5022
5022
  /** A fact source supplies bounded candidates; recall owns ranking and result handling. */
5023
5023
  interface RecallFactSource {
5024
- search: (query: string, options?: MemoryVaultSearchOptions) => ReturnType<typeof searchVaultMemoriesWithSize>;
5024
+ search: (query: string, options?: MemoryVaultSearchOptions, embeddingCache?: Map<string, Float32Array>) => ReturnType<typeof searchVaultMemoriesWithSize>;
5025
5025
  graphRanking: (query: string, traverse: boolean, options: RecallOptions) => Promise<string[]>;
5026
5026
  temporalRanking: (query: string, now?: number) => Promise<string[]>;
5027
5027
  }
@@ -13898,13 +13898,6 @@ type UseChatResult = BaseUseChatResult & {
13898
13898
  */
13899
13899
  declare function useChat(options?: UseChatOptions): UseChatResult;
13900
13900
 
13901
- /**
13902
- * Namespacing for a caller-shared embedding cache.
13903
- *
13904
- * Lives here, next to the `embeddingCache` send-arg it serves, rather than in either platform hook:
13905
- * react and expo both thread the option through their own send paths, and a copy per platform is how
13906
- * the two drift.
13907
- */
13908
13901
  declare function maskScopedEmbeddingCache(cache: Map<string, Float32Array>, masked: boolean): Map<string, Float32Array>;
13909
13902
 
13910
13903
  /**
@@ -5021,7 +5021,7 @@ interface RecallOptions {
5021
5021
  }
5022
5022
  /** A fact source supplies bounded candidates; recall owns ranking and result handling. */
5023
5023
  interface RecallFactSource {
5024
- search: (query: string, options?: MemoryVaultSearchOptions) => ReturnType<typeof searchVaultMemoriesWithSize>;
5024
+ search: (query: string, options?: MemoryVaultSearchOptions, embeddingCache?: Map<string, Float32Array>) => ReturnType<typeof searchVaultMemoriesWithSize>;
5025
5025
  graphRanking: (query: string, traverse: boolean, options: RecallOptions) => Promise<string[]>;
5026
5026
  temporalRanking: (query: string, now?: number) => Promise<string[]>;
5027
5027
  }
@@ -13898,13 +13898,6 @@ type UseChatResult = BaseUseChatResult & {
13898
13898
  */
13899
13899
  declare function useChat(options?: UseChatOptions): UseChatResult;
13900
13900
 
13901
- /**
13902
- * Namespacing for a caller-shared embedding cache.
13903
- *
13904
- * Lives here, next to the `embeddingCache` send-arg it serves, rather than in either platform hook:
13905
- * react and expo both thread the option through their own send paths, and a copy per platform is how
13906
- * the two drift.
13907
- */
13908
13901
  declare function maskScopedEmbeddingCache(cache: Map<string, Float32Array>, masked: boolean): Map<string, Float32Array>;
13909
13902
 
13910
13903
  /**