@anuma/sdk 7.1.0 → 7.2.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.
@@ -30252,10 +30252,18 @@ function admitVaultProjections(queryEmbedding, vectored, k) {
30252
30252
  }
30253
30253
  async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, queryOpts, opts) {
30254
30254
  let rowsDecrypted = 0;
30255
+ const keysStart = nowMs();
30255
30256
  const keys = await getVaultCandidateKeysOp(
30256
30257
  vaultCtx,
30257
30258
  Object.keys(queryOpts).length > 0 ? queryOpts : void 0
30258
30259
  );
30260
+ const corpusStats = {
30261
+ keysMs: nowMs() - keysStart,
30262
+ embeddingsFetchMs: 0,
30263
+ rowsFetchMs: 0,
30264
+ cacheHits: 0,
30265
+ cacheMisses: 0
30266
+ };
30259
30267
  const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
30260
30268
  const vaultSize = keys.length;
30261
30269
  if (keys.length === 0) {
@@ -30265,7 +30273,8 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
30265
30273
  queryEmbedding: [],
30266
30274
  vaultSize: 0,
30267
30275
  laneEmbedFailed: false,
30268
- rowsDecrypted: 0
30276
+ rowsDecrypted: 0,
30277
+ corpusStats
30269
30278
  };
30270
30279
  }
30271
30280
  const queryEmbedStart = nowMs();
@@ -30287,16 +30296,20 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
30287
30296
  for (const k2 of keys) {
30288
30297
  const cached = cachedRowVector(cache, k2.uniqueId, k2.updatedAt);
30289
30298
  if (cached && cached.length === queryEmbedding.length) {
30299
+ corpusStats.cacheHits++;
30290
30300
  vectored.push({ uniqueId: k2.uniqueId, embedding: cached, updatedAt: k2.updatedAt });
30291
30301
  continue;
30292
30302
  }
30303
+ corpusStats.cacheMisses++;
30293
30304
  const modelCompatible = (k2.embeddingModel ?? currentModel) === currentModel;
30294
30305
  if (modelCompatible) missIds.push(k2.uniqueId);
30295
30306
  else noVectorIds.push(k2.uniqueId);
30296
30307
  }
30297
30308
  }
30298
30309
  if (missIds.length > 0) {
30310
+ const embeddingsStart = nowMs();
30299
30311
  const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
30312
+ corpusStats.embeddingsFetchMs += nowMs() - embeddingsStart;
30300
30313
  const gotVector = /* @__PURE__ */ new Set();
30301
30314
  for (const r of rows) {
30302
30315
  if (!r.embedding) continue;
@@ -30324,7 +30337,9 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
30324
30337
  `memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
30325
30338
  );
30326
30339
  }
30340
+ const laneStart = nowMs();
30327
30341
  const laneFetched = await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts);
30342
+ corpusStats.rowsFetchMs += nowMs() - laneStart;
30328
30343
  rowsDecrypted += laneFetched.length;
30329
30344
  for (const row of laneFetched) laneById.set(row.uniqueId, row);
30330
30345
  const laneRows = laneFetched.filter((m) => !isEncrypted(m.content));
@@ -30376,7 +30391,9 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
30376
30391
  }
30377
30392
  }
30378
30393
  const idsToFetch = [...admissionSet].filter((id) => !laneById.has(id));
30394
+ const admittedStart = nowMs();
30379
30395
  const fetched = idsToFetch.length > 0 ? await getVaultMemoriesByIdsOp(vaultCtx, idsToFetch, hydrateOpts) : [];
30396
+ corpusStats.rowsFetchMs += nowMs() - admittedStart;
30380
30397
  rowsDecrypted += fetched.length;
30381
30398
  const admittedRows = [
30382
30399
  ...fetched,
@@ -30405,7 +30422,10 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
30405
30422
  }
30406
30423
  if (staleIds.length > 0) {
30407
30424
  const contentById = new Map(memories.map((m) => [m.uniqueId, m]));
30408
- for (const r of await getVaultEmbeddingsByIdsOp(vaultCtx, staleIds, hydrateOpts)) {
30425
+ const staleStart = nowMs();
30426
+ const staleRows = await getVaultEmbeddingsByIdsOp(vaultCtx, staleIds, hydrateOpts);
30427
+ corpusStats.embeddingsFetchMs += nowMs() - staleStart;
30428
+ for (const r of staleRows) {
30409
30429
  if (!r.embedding) continue;
30410
30430
  try {
30411
30431
  const parsed = JSON.parse(r.embedding);
@@ -30437,7 +30457,15 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
30437
30457
  eventTimeKind: normalizeEventTimeKind(m.eventTimeKind),
30438
30458
  factType: m.factType
30439
30459
  }));
30440
- return { memories, embeddedItems, queryEmbedding, vaultSize, laneEmbedFailed, rowsDecrypted };
30460
+ return {
30461
+ memories,
30462
+ embeddedItems,
30463
+ queryEmbedding,
30464
+ vaultSize,
30465
+ laneEmbedFailed,
30466
+ rowsDecrypted,
30467
+ corpusStats
30468
+ };
30441
30469
  }
30442
30470
  async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache, searchOptions) {
30443
30471
  if (!query || typeof query !== "string") {
@@ -30478,6 +30506,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
30478
30506
  embeddingFailure = true;
30479
30507
  };
30480
30508
  const embedStats = { queryMs: 0, rowsEmbedded: 0 };
30509
+ let corpusStats;
30481
30510
  if (searchOptions?.decryptLast) {
30482
30511
  const forceIncludeIds = [
30483
30512
  ...searchOptions.entityRanking ?? [],
@@ -30498,6 +30527,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
30498
30527
  onEmbeddingDegraded,
30499
30528
  embedStats
30500
30529
  });
30530
+ corpusStats = corpus.corpusStats;
30501
30531
  if (corpus.vaultSize === 0) {
30502
30532
  return {
30503
30533
  memories: [],
@@ -30509,7 +30539,8 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
30509
30539
  decryptLast: true,
30510
30540
  rowsDecrypted: corpus.rowsDecrypted,
30511
30541
  queryEmbedMs: embedStats.queryMs,
30512
- rowsEmbedded: embedStats.rowsEmbedded
30542
+ rowsEmbedded: embedStats.rowsEmbedded,
30543
+ corpusStats
30513
30544
  };
30514
30545
  }
30515
30546
  ({ memories, embeddedItems, queryEmbedding, vaultSize } = corpus);
@@ -30526,7 +30557,8 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
30526
30557
  decryptLast: true,
30527
30558
  rowsDecrypted: corpus.rowsDecrypted,
30528
30559
  queryEmbedMs: embedStats.queryMs,
30529
- rowsEmbedded: embedStats.rowsEmbedded
30560
+ rowsEmbedded: embedStats.rowsEmbedded,
30561
+ corpusStats
30530
30562
  };
30531
30563
  }
30532
30564
  } else {
@@ -30659,7 +30691,8 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
30659
30691
  embeddingsUnavailable,
30660
30692
  embeddingFailure,
30661
30693
  decryptLast: !!searchOptions?.decryptLast,
30662
- rowsDecrypted
30694
+ rowsDecrypted,
30695
+ ...corpusStats && { corpusStats }
30663
30696
  };
30664
30697
  }
30665
30698
  async function rankPreparedVaultCandidates(query, prepared, embeddingOptions, searchOptions) {
@@ -30876,7 +30909,8 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
30876
30909
  decryptLast: prepared.decryptLast,
30877
30910
  rowsDecrypted: prepared.rowsDecrypted,
30878
30911
  queryEmbedMs: prepared.queryEmbedMs,
30879
- rowsEmbedded: prepared.rowsEmbedded
30912
+ rowsEmbedded: prepared.rowsEmbedded,
30913
+ ...prepared.corpusStats && { corpusStats: prepared.corpusStats }
30880
30914
  };
30881
30915
  }
30882
30916
  if (prepared.memories.length === 0) {
@@ -30891,7 +30925,8 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
30891
30925
  decryptLast: prepared.decryptLast,
30892
30926
  rowsDecrypted: prepared.rowsDecrypted,
30893
30927
  queryEmbedMs: prepared.queryEmbedMs,
30894
- rowsEmbedded: prepared.rowsEmbedded
30928
+ rowsEmbedded: prepared.rowsEmbedded,
30929
+ ...prepared.corpusStats && { corpusStats: prepared.corpusStats }
30895
30930
  };
30896
30931
  }
30897
30932
  const ranked = await rankPreparedVaultCandidates(
@@ -30906,7 +30941,8 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
30906
30941
  decryptLast: prepared.decryptLast,
30907
30942
  rowsDecrypted: prepared.rowsDecrypted,
30908
30943
  queryEmbedMs: prepared.queryEmbedMs,
30909
- rowsEmbedded: prepared.rowsEmbedded
30944
+ rowsEmbedded: prepared.rowsEmbedded,
30945
+ ...prepared.corpusStats && { corpusStats: prepared.corpusStats }
30910
30946
  };
30911
30947
  }
30912
30948
  async function searchVaultMemories(query, vaultCtx, embeddingOptions, cache, searchOptions) {
@@ -32907,6 +32943,7 @@ async function recall(query, ctx, options = {}) {
32907
32943
  let factLaneRankedOnCosine = false;
32908
32944
  let decryptLastRan;
32909
32945
  let vaultRowsDecrypted;
32946
+ let corpusStats;
32910
32947
  let graphLaneCount = 0;
32911
32948
  let temporalLaneCount = 0;
32912
32949
  let graphLaneFailed = false;
@@ -32947,6 +32984,10 @@ async function recall(query, ctx, options = {}) {
32947
32984
  ...decryptLastRan !== void 0 && { decryptLast: decryptLastRan },
32948
32985
  ...vaultRowsDecrypted !== void 0 && { vaultRowsDecrypted },
32949
32986
  ...vaultRowsEmbedded !== void 0 && { vaultRowsEmbedded },
32987
+ ...corpusStats && {
32988
+ vaultCacheHits: corpusStats.cacheHits,
32989
+ vaultCacheMisses: corpusStats.cacheMisses
32990
+ },
32950
32991
  ...chunkStats && {
32951
32992
  chunkRowsScanned: chunkStats.rowsScanned,
32952
32993
  chunkRowsFetched: chunkStats.rowsFetched,
@@ -32969,7 +33010,12 @@ async function recall(query, ctx, options = {}) {
32969
33010
  rerank: rerankMs,
32970
33011
  queryEmbed: queryEmbedMs,
32971
33012
  chunkLane: chunkLaneMs,
32972
- fuse: fuseMs
33013
+ fuse: fuseMs,
33014
+ ...corpusStats && {
33015
+ corpusKeys: corpusStats.keysMs,
33016
+ corpusEmbeddingsFetch: corpusStats.embeddingsFetchMs,
33017
+ corpusRowsFetch: corpusStats.rowsFetchMs
33018
+ }
32973
33019
  },
32974
33020
  degraded
32975
33021
  };
@@ -33043,7 +33089,8 @@ async function recall(query, ctx, options = {}) {
33043
33089
  embeddingsUnavailable: factEmbeddingsUnavailable,
33044
33090
  rankedOnCosine: factRankedOnCosine,
33045
33091
  decryptLast: factDecryptLast,
33046
- rowsDecrypted: factRowsDecrypted
33092
+ rowsDecrypted: factRowsDecrypted,
33093
+ corpusStats: factCorpusStats
33047
33094
  } = await (ctx.factSource?.search.bind(ctx.factSource) ?? ((searchQuery, searchOptions) => searchVaultMemoriesWithSize(
33048
33095
  searchQuery,
33049
33096
  ctx.vaultCtx,
@@ -33109,6 +33156,7 @@ async function recall(query, ctx, options = {}) {
33109
33156
  factLaneRankedOnCosine = factRankedOnCosine;
33110
33157
  decryptLastRan = factDecryptLast;
33111
33158
  vaultRowsDecrypted = factRowsDecrypted;
33159
+ corpusStats = factCorpusStats;
33112
33160
  factLaneMs = nowMs() - factStart;
33113
33161
  }
33114
33162
  if (chunkEmbedFailed && !factLaneRankedOnCosine) embeddingsUnavailable = true;
@@ -332,6 +332,8 @@ interface RecallDiagnostics {
332
332
  * LEGACY read path this batch is uncapped, so it can be the whole vault.
333
333
  */
334
334
  vaultRowsEmbedded?: number;
335
+ vaultCacheHits?: number;
336
+ vaultCacheMisses?: number;
335
337
  /** Embedded messages the chunk lane considered; absent when the lane did not run. */
336
338
  chunkRowsScanned?: number;
337
339
  /** Messages whose vectors the chunk lane read from storage on a cache miss. */
@@ -434,6 +436,9 @@ interface RecallDiagnostics {
434
436
  chunkLane: number;
435
437
  /** Cross-lane RRF fusion + provenance dedup after both lanes. */
436
438
  fuse: number;
439
+ corpusKeys?: number;
440
+ corpusEmbeddingsFetch?: number;
441
+ corpusRowsFetch?: number;
437
442
  };
438
443
  /** Soft-degradation signals that fired this call (empty when clean). */
439
444
  degraded: RecallDegradation[];
@@ -332,6 +332,8 @@ interface RecallDiagnostics {
332
332
  * LEGACY read path this batch is uncapped, so it can be the whole vault.
333
333
  */
334
334
  vaultRowsEmbedded?: number;
335
+ vaultCacheHits?: number;
336
+ vaultCacheMisses?: number;
335
337
  /** Embedded messages the chunk lane considered; absent when the lane did not run. */
336
338
  chunkRowsScanned?: number;
337
339
  /** Messages whose vectors the chunk lane read from storage on a cache miss. */
@@ -434,6 +436,9 @@ interface RecallDiagnostics {
434
436
  chunkLane: number;
435
437
  /** Cross-lane RRF fusion + provenance dedup after both lanes. */
436
438
  fuse: number;
439
+ corpusKeys?: number;
440
+ corpusEmbeddingsFetch?: number;
441
+ corpusRowsFetch?: number;
437
442
  };
438
443
  /** Soft-degradation signals that fired this call (empty when clean). */
439
444
  degraded: RecallDegradation[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@anuma/sdk",
3
- "version": "7.1.0",
3
+ "version": "7.2.0",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.mjs",