@anuma/sdk 7.1.1 → 7.3.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.
- package/dist/expo/index.cjs +80 -12
- package/dist/expo/index.d.mts +17 -1
- package/dist/expo/index.d.ts +17 -1
- package/dist/expo/index.mjs +80 -12
- package/dist/memory/context.d.mts +5 -0
- package/dist/memory/context.d.ts +5 -0
- package/dist/react/index.cjs +80 -12
- package/dist/react/index.d.mts +17 -1
- package/dist/react/index.d.ts +17 -1
- package/dist/react/index.mjs +80 -12
- package/dist/server/index.cjs +59 -11
- package/dist/server/index.d.mts +13 -0
- package/dist/server/index.d.ts +13 -0
- package/dist/server/index.mjs +59 -11
- package/dist/telemetry/index.d.mts +5 -0
- package/dist/telemetry/index.d.ts +5 -0
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -31957,10 +31957,18 @@ function admitVaultProjections(queryEmbedding, vectored, k) {
|
|
|
31957
31957
|
}
|
|
31958
31958
|
async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, queryOpts, opts) {
|
|
31959
31959
|
let rowsDecrypted = 0;
|
|
31960
|
+
const keysStart = nowMs();
|
|
31960
31961
|
const keys = await getVaultCandidateKeysOp(
|
|
31961
31962
|
vaultCtx,
|
|
31962
31963
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
31963
31964
|
);
|
|
31965
|
+
const corpusStats = {
|
|
31966
|
+
keysMs: nowMs() - keysStart,
|
|
31967
|
+
embeddingsFetchMs: 0,
|
|
31968
|
+
rowsFetchMs: 0,
|
|
31969
|
+
cacheHits: 0,
|
|
31970
|
+
cacheMisses: 0
|
|
31971
|
+
};
|
|
31964
31972
|
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
31965
31973
|
const vaultSize = keys.length;
|
|
31966
31974
|
if (keys.length === 0) {
|
|
@@ -31970,7 +31978,8 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
31970
31978
|
queryEmbedding: [],
|
|
31971
31979
|
vaultSize: 0,
|
|
31972
31980
|
laneEmbedFailed: false,
|
|
31973
|
-
rowsDecrypted: 0
|
|
31981
|
+
rowsDecrypted: 0,
|
|
31982
|
+
corpusStats
|
|
31974
31983
|
};
|
|
31975
31984
|
}
|
|
31976
31985
|
const queryEmbedStart = nowMs();
|
|
@@ -31992,16 +32001,20 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
31992
32001
|
for (const k2 of keys) {
|
|
31993
32002
|
const cached = cachedRowVector(cache, k2.uniqueId, k2.updatedAt);
|
|
31994
32003
|
if (cached && cached.length === queryEmbedding.length) {
|
|
32004
|
+
corpusStats.cacheHits++;
|
|
31995
32005
|
vectored.push({ uniqueId: k2.uniqueId, embedding: cached, updatedAt: k2.updatedAt });
|
|
31996
32006
|
continue;
|
|
31997
32007
|
}
|
|
32008
|
+
corpusStats.cacheMisses++;
|
|
31998
32009
|
const modelCompatible = (k2.embeddingModel ?? currentModel) === currentModel;
|
|
31999
32010
|
if (modelCompatible) missIds.push(k2.uniqueId);
|
|
32000
32011
|
else noVectorIds.push(k2.uniqueId);
|
|
32001
32012
|
}
|
|
32002
32013
|
}
|
|
32003
32014
|
if (missIds.length > 0) {
|
|
32015
|
+
const embeddingsStart = nowMs();
|
|
32004
32016
|
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
32017
|
+
corpusStats.embeddingsFetchMs += nowMs() - embeddingsStart;
|
|
32005
32018
|
const gotVector = /* @__PURE__ */ new Set();
|
|
32006
32019
|
for (const r of rows) {
|
|
32007
32020
|
if (!r.embedding) continue;
|
|
@@ -32029,7 +32042,9 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
32029
32042
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
32030
32043
|
);
|
|
32031
32044
|
}
|
|
32045
|
+
const laneStart = nowMs();
|
|
32032
32046
|
const laneFetched = await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts);
|
|
32047
|
+
corpusStats.rowsFetchMs += nowMs() - laneStart;
|
|
32033
32048
|
rowsDecrypted += laneFetched.length;
|
|
32034
32049
|
for (const row of laneFetched) laneById.set(row.uniqueId, row);
|
|
32035
32050
|
const laneRows = laneFetched.filter((m) => !isEncrypted(m.content));
|
|
@@ -32081,7 +32096,9 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
32081
32096
|
}
|
|
32082
32097
|
}
|
|
32083
32098
|
const idsToFetch = [...admissionSet].filter((id) => !laneById.has(id));
|
|
32099
|
+
const admittedStart = nowMs();
|
|
32084
32100
|
const fetched = idsToFetch.length > 0 ? await getVaultMemoriesByIdsOp(vaultCtx, idsToFetch, hydrateOpts) : [];
|
|
32101
|
+
corpusStats.rowsFetchMs += nowMs() - admittedStart;
|
|
32085
32102
|
rowsDecrypted += fetched.length;
|
|
32086
32103
|
const admittedRows = [
|
|
32087
32104
|
...fetched,
|
|
@@ -32110,7 +32127,10 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
32110
32127
|
}
|
|
32111
32128
|
if (staleIds.length > 0) {
|
|
32112
32129
|
const contentById = new Map(memories.map((m) => [m.uniqueId, m]));
|
|
32113
|
-
|
|
32130
|
+
const staleStart = nowMs();
|
|
32131
|
+
const staleRows = await getVaultEmbeddingsByIdsOp(vaultCtx, staleIds, hydrateOpts);
|
|
32132
|
+
corpusStats.embeddingsFetchMs += nowMs() - staleStart;
|
|
32133
|
+
for (const r of staleRows) {
|
|
32114
32134
|
if (!r.embedding) continue;
|
|
32115
32135
|
try {
|
|
32116
32136
|
const parsed = JSON.parse(r.embedding);
|
|
@@ -32142,7 +32162,15 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
32142
32162
|
eventTimeKind: normalizeEventTimeKind(m.eventTimeKind),
|
|
32143
32163
|
factType: m.factType
|
|
32144
32164
|
}));
|
|
32145
|
-
return {
|
|
32165
|
+
return {
|
|
32166
|
+
memories,
|
|
32167
|
+
embeddedItems,
|
|
32168
|
+
queryEmbedding,
|
|
32169
|
+
vaultSize,
|
|
32170
|
+
laneEmbedFailed,
|
|
32171
|
+
rowsDecrypted,
|
|
32172
|
+
corpusStats
|
|
32173
|
+
};
|
|
32146
32174
|
}
|
|
32147
32175
|
async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache, searchOptions) {
|
|
32148
32176
|
if (!query || typeof query !== "string") {
|
|
@@ -32183,6 +32211,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
32183
32211
|
embeddingFailure = true;
|
|
32184
32212
|
};
|
|
32185
32213
|
const embedStats = { queryMs: 0, rowsEmbedded: 0 };
|
|
32214
|
+
let corpusStats;
|
|
32186
32215
|
if (searchOptions?.decryptLast) {
|
|
32187
32216
|
const forceIncludeIds = [
|
|
32188
32217
|
...searchOptions.entityRanking ?? [],
|
|
@@ -32203,6 +32232,7 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
32203
32232
|
onEmbeddingDegraded,
|
|
32204
32233
|
embedStats
|
|
32205
32234
|
});
|
|
32235
|
+
corpusStats = corpus.corpusStats;
|
|
32206
32236
|
if (corpus.vaultSize === 0) {
|
|
32207
32237
|
return {
|
|
32208
32238
|
memories: [],
|
|
@@ -32214,7 +32244,8 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
32214
32244
|
decryptLast: true,
|
|
32215
32245
|
rowsDecrypted: corpus.rowsDecrypted,
|
|
32216
32246
|
queryEmbedMs: embedStats.queryMs,
|
|
32217
|
-
rowsEmbedded: embedStats.rowsEmbedded
|
|
32247
|
+
rowsEmbedded: embedStats.rowsEmbedded,
|
|
32248
|
+
corpusStats
|
|
32218
32249
|
};
|
|
32219
32250
|
}
|
|
32220
32251
|
({ memories, embeddedItems, queryEmbedding, vaultSize } = corpus);
|
|
@@ -32231,7 +32262,8 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
32231
32262
|
decryptLast: true,
|
|
32232
32263
|
rowsDecrypted: corpus.rowsDecrypted,
|
|
32233
32264
|
queryEmbedMs: embedStats.queryMs,
|
|
32234
|
-
rowsEmbedded: embedStats.rowsEmbedded
|
|
32265
|
+
rowsEmbedded: embedStats.rowsEmbedded,
|
|
32266
|
+
corpusStats
|
|
32235
32267
|
};
|
|
32236
32268
|
}
|
|
32237
32269
|
} else {
|
|
@@ -32364,7 +32396,8 @@ async function prepareVaultCandidates(query, vaultCtx, embeddingOptions, cache,
|
|
|
32364
32396
|
embeddingsUnavailable,
|
|
32365
32397
|
embeddingFailure,
|
|
32366
32398
|
decryptLast: !!searchOptions?.decryptLast,
|
|
32367
|
-
rowsDecrypted
|
|
32399
|
+
rowsDecrypted,
|
|
32400
|
+
...corpusStats && { corpusStats }
|
|
32368
32401
|
};
|
|
32369
32402
|
}
|
|
32370
32403
|
async function rankPreparedVaultCandidates(query, prepared, embeddingOptions, searchOptions) {
|
|
@@ -32581,7 +32614,8 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
32581
32614
|
decryptLast: prepared.decryptLast,
|
|
32582
32615
|
rowsDecrypted: prepared.rowsDecrypted,
|
|
32583
32616
|
queryEmbedMs: prepared.queryEmbedMs,
|
|
32584
|
-
rowsEmbedded: prepared.rowsEmbedded
|
|
32617
|
+
rowsEmbedded: prepared.rowsEmbedded,
|
|
32618
|
+
...prepared.corpusStats && { corpusStats: prepared.corpusStats }
|
|
32585
32619
|
};
|
|
32586
32620
|
}
|
|
32587
32621
|
if (prepared.memories.length === 0) {
|
|
@@ -32596,7 +32630,8 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
32596
32630
|
decryptLast: prepared.decryptLast,
|
|
32597
32631
|
rowsDecrypted: prepared.rowsDecrypted,
|
|
32598
32632
|
queryEmbedMs: prepared.queryEmbedMs,
|
|
32599
|
-
rowsEmbedded: prepared.rowsEmbedded
|
|
32633
|
+
rowsEmbedded: prepared.rowsEmbedded,
|
|
32634
|
+
...prepared.corpusStats && { corpusStats: prepared.corpusStats }
|
|
32600
32635
|
};
|
|
32601
32636
|
}
|
|
32602
32637
|
const ranked = await rankPreparedVaultCandidates(
|
|
@@ -32611,7 +32646,8 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
32611
32646
|
decryptLast: prepared.decryptLast,
|
|
32612
32647
|
rowsDecrypted: prepared.rowsDecrypted,
|
|
32613
32648
|
queryEmbedMs: prepared.queryEmbedMs,
|
|
32614
|
-
rowsEmbedded: prepared.rowsEmbedded
|
|
32649
|
+
rowsEmbedded: prepared.rowsEmbedded,
|
|
32650
|
+
...prepared.corpusStats && { corpusStats: prepared.corpusStats }
|
|
32615
32651
|
};
|
|
32616
32652
|
}
|
|
32617
32653
|
async function searchVaultMemories(query, vaultCtx, embeddingOptions, cache, searchOptions) {
|
|
@@ -34626,6 +34662,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
34626
34662
|
let factLaneRankedOnCosine = false;
|
|
34627
34663
|
let decryptLastRan;
|
|
34628
34664
|
let vaultRowsDecrypted;
|
|
34665
|
+
let corpusStats;
|
|
34629
34666
|
let graphLaneCount = 0;
|
|
34630
34667
|
let temporalLaneCount = 0;
|
|
34631
34668
|
let graphLaneFailed = false;
|
|
@@ -34666,6 +34703,10 @@ async function recall(query, ctx, options = {}) {
|
|
|
34666
34703
|
...decryptLastRan !== void 0 && { decryptLast: decryptLastRan },
|
|
34667
34704
|
...vaultRowsDecrypted !== void 0 && { vaultRowsDecrypted },
|
|
34668
34705
|
...vaultRowsEmbedded !== void 0 && { vaultRowsEmbedded },
|
|
34706
|
+
...corpusStats && {
|
|
34707
|
+
vaultCacheHits: corpusStats.cacheHits,
|
|
34708
|
+
vaultCacheMisses: corpusStats.cacheMisses
|
|
34709
|
+
},
|
|
34669
34710
|
...chunkStats && {
|
|
34670
34711
|
chunkRowsScanned: chunkStats.rowsScanned,
|
|
34671
34712
|
chunkRowsFetched: chunkStats.rowsFetched,
|
|
@@ -34688,7 +34729,12 @@ async function recall(query, ctx, options = {}) {
|
|
|
34688
34729
|
rerank: rerankMs,
|
|
34689
34730
|
queryEmbed: queryEmbedMs,
|
|
34690
34731
|
chunkLane: chunkLaneMs,
|
|
34691
|
-
fuse: fuseMs
|
|
34732
|
+
fuse: fuseMs,
|
|
34733
|
+
...corpusStats && {
|
|
34734
|
+
corpusKeys: corpusStats.keysMs,
|
|
34735
|
+
corpusEmbeddingsFetch: corpusStats.embeddingsFetchMs,
|
|
34736
|
+
corpusRowsFetch: corpusStats.rowsFetchMs
|
|
34737
|
+
}
|
|
34692
34738
|
},
|
|
34693
34739
|
degraded
|
|
34694
34740
|
};
|
|
@@ -34762,7 +34808,8 @@ async function recall(query, ctx, options = {}) {
|
|
|
34762
34808
|
embeddingsUnavailable: factEmbeddingsUnavailable,
|
|
34763
34809
|
rankedOnCosine: factRankedOnCosine,
|
|
34764
34810
|
decryptLast: factDecryptLast,
|
|
34765
|
-
rowsDecrypted: factRowsDecrypted
|
|
34811
|
+
rowsDecrypted: factRowsDecrypted,
|
|
34812
|
+
corpusStats: factCorpusStats
|
|
34766
34813
|
} = await (ctx.factSource?.search.bind(ctx.factSource) ?? ((searchQuery, searchOptions) => searchVaultMemoriesWithSize(
|
|
34767
34814
|
searchQuery,
|
|
34768
34815
|
ctx.vaultCtx,
|
|
@@ -34828,6 +34875,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
34828
34875
|
factLaneRankedOnCosine = factRankedOnCosine;
|
|
34829
34876
|
decryptLastRan = factDecryptLast;
|
|
34830
34877
|
vaultRowsDecrypted = factRowsDecrypted;
|
|
34878
|
+
corpusStats = factCorpusStats;
|
|
34831
34879
|
factLaneMs = nowMs() - factStart;
|
|
34832
34880
|
}
|
|
34833
34881
|
if (chunkEmbedFailed && !factLaneRankedOnCosine) embeddingsUnavailable = true;
|
package/dist/server/index.d.mts
CHANGED
|
@@ -3538,6 +3538,13 @@ declare function eagerEmbedContent(content: string, embeddingOptions: EmbeddingO
|
|
|
3538
3538
|
* trusting it (see `vectorVersion.ts`).
|
|
3539
3539
|
*/
|
|
3540
3540
|
updatedAt?: Date): Promise<void>;
|
|
3541
|
+
interface CorpusStats {
|
|
3542
|
+
keysMs: number;
|
|
3543
|
+
embeddingsFetchMs: number;
|
|
3544
|
+
rowsFetchMs: number;
|
|
3545
|
+
cacheHits: number;
|
|
3546
|
+
cacheMisses: number;
|
|
3547
|
+
}
|
|
3541
3548
|
/**
|
|
3542
3549
|
* A single vault search result with its similarity score.
|
|
3543
3550
|
*/
|
|
@@ -3616,6 +3623,7 @@ declare function searchVaultMemoriesWithSize(query: string, vaultCtx: VaultMemor
|
|
|
3616
3623
|
*/
|
|
3617
3624
|
queryEmbedMs: number;
|
|
3618
3625
|
rowsEmbedded: number;
|
|
3626
|
+
corpusStats?: CorpusStats;
|
|
3619
3627
|
}>;
|
|
3620
3628
|
/**
|
|
3621
3629
|
* Search vault memories by semantic similarity. Returns structured results
|
|
@@ -4335,6 +4343,8 @@ interface RecallDiagnostics {
|
|
|
4335
4343
|
* LEGACY read path this batch is uncapped, so it can be the whole vault.
|
|
4336
4344
|
*/
|
|
4337
4345
|
vaultRowsEmbedded?: number;
|
|
4346
|
+
vaultCacheHits?: number;
|
|
4347
|
+
vaultCacheMisses?: number;
|
|
4338
4348
|
/** Embedded messages the chunk lane considered; absent when the lane did not run. */
|
|
4339
4349
|
chunkRowsScanned?: number;
|
|
4340
4350
|
/** Messages whose vectors the chunk lane read from storage on a cache miss. */
|
|
@@ -4437,6 +4447,9 @@ interface RecallDiagnostics {
|
|
|
4437
4447
|
chunkLane: number;
|
|
4438
4448
|
/** Cross-lane RRF fusion + provenance dedup after both lanes. */
|
|
4439
4449
|
fuse: number;
|
|
4450
|
+
corpusKeys?: number;
|
|
4451
|
+
corpusEmbeddingsFetch?: number;
|
|
4452
|
+
corpusRowsFetch?: number;
|
|
4440
4453
|
};
|
|
4441
4454
|
/** Soft-degradation signals that fired this call (empty when clean). */
|
|
4442
4455
|
degraded: RecallDegradation[];
|
package/dist/server/index.d.ts
CHANGED
|
@@ -3538,6 +3538,13 @@ declare function eagerEmbedContent(content: string, embeddingOptions: EmbeddingO
|
|
|
3538
3538
|
* trusting it (see `vectorVersion.ts`).
|
|
3539
3539
|
*/
|
|
3540
3540
|
updatedAt?: Date): Promise<void>;
|
|
3541
|
+
interface CorpusStats {
|
|
3542
|
+
keysMs: number;
|
|
3543
|
+
embeddingsFetchMs: number;
|
|
3544
|
+
rowsFetchMs: number;
|
|
3545
|
+
cacheHits: number;
|
|
3546
|
+
cacheMisses: number;
|
|
3547
|
+
}
|
|
3541
3548
|
/**
|
|
3542
3549
|
* A single vault search result with its similarity score.
|
|
3543
3550
|
*/
|
|
@@ -3616,6 +3623,7 @@ declare function searchVaultMemoriesWithSize(query: string, vaultCtx: VaultMemor
|
|
|
3616
3623
|
*/
|
|
3617
3624
|
queryEmbedMs: number;
|
|
3618
3625
|
rowsEmbedded: number;
|
|
3626
|
+
corpusStats?: CorpusStats;
|
|
3619
3627
|
}>;
|
|
3620
3628
|
/**
|
|
3621
3629
|
* Search vault memories by semantic similarity. Returns structured results
|
|
@@ -4335,6 +4343,8 @@ interface RecallDiagnostics {
|
|
|
4335
4343
|
* LEGACY read path this batch is uncapped, so it can be the whole vault.
|
|
4336
4344
|
*/
|
|
4337
4345
|
vaultRowsEmbedded?: number;
|
|
4346
|
+
vaultCacheHits?: number;
|
|
4347
|
+
vaultCacheMisses?: number;
|
|
4338
4348
|
/** Embedded messages the chunk lane considered; absent when the lane did not run. */
|
|
4339
4349
|
chunkRowsScanned?: number;
|
|
4340
4350
|
/** Messages whose vectors the chunk lane read from storage on a cache miss. */
|
|
@@ -4437,6 +4447,9 @@ interface RecallDiagnostics {
|
|
|
4437
4447
|
chunkLane: number;
|
|
4438
4448
|
/** Cross-lane RRF fusion + provenance dedup after both lanes. */
|
|
4439
4449
|
fuse: number;
|
|
4450
|
+
corpusKeys?: number;
|
|
4451
|
+
corpusEmbeddingsFetch?: number;
|
|
4452
|
+
corpusRowsFetch?: number;
|
|
4440
4453
|
};
|
|
4441
4454
|
/** Soft-degradation signals that fired this call (empty when clean). */
|
|
4442
4455
|
degraded: RecallDegradation[];
|
package/dist/server/index.mjs
CHANGED
|
@@ -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
|
-
|
|
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 {
|
|
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[];
|