@anuma/sdk 6.33.2 → 6.34.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 +1099 -293
- package/dist/expo/index.d.mts +218 -4
- package/dist/expo/index.d.ts +218 -4
- package/dist/expo/index.mjs +1095 -293
- package/dist/index.cjs +18 -6
- package/dist/index.mjs +18 -6
- package/dist/react/index.cjs +1180 -374
- package/dist/react/index.d.mts +251 -4
- package/dist/react/index.d.ts +251 -4
- package/dist/react/index.mjs +1176 -374
- package/dist/server/index.cjs +118 -86
- package/dist/server/index.d.mts +77 -3
- package/dist/server/index.d.ts +77 -3
- package/dist/server/index.mjs +118 -86
- package/dist/telemetry/index.d.mts +3 -4
- package/dist/telemetry/index.d.ts +3 -4
- package/dist/tools/selection/index.cjs +18 -6
- package/dist/tools/selection/index.mjs +18 -6
- package/package.json +1 -1
package/dist/server/index.mjs
CHANGED
|
@@ -18315,7 +18315,7 @@ async function embedOne(text12, options, outer) {
|
|
|
18315
18315
|
}
|
|
18316
18316
|
var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
18317
18317
|
var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
18318
|
-
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs) {
|
|
18318
|
+
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs, outer) {
|
|
18319
18319
|
const response = await withEmbeddingRetry(
|
|
18320
18320
|
() => withDeadline(
|
|
18321
18321
|
(signal) => postApiV1Embeddings({
|
|
@@ -18325,8 +18325,10 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
18325
18325
|
...signal && { signal }
|
|
18326
18326
|
}),
|
|
18327
18327
|
timeoutMs,
|
|
18328
|
-
"embedding batch request"
|
|
18329
|
-
|
|
18328
|
+
"embedding batch request",
|
|
18329
|
+
outer
|
|
18330
|
+
),
|
|
18331
|
+
outer
|
|
18330
18332
|
);
|
|
18331
18333
|
if (response.error) {
|
|
18332
18334
|
throw embeddingErrorFrom(response);
|
|
@@ -18344,6 +18346,11 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
18344
18346
|
}
|
|
18345
18347
|
async function generateEmbeddings(texts, options) {
|
|
18346
18348
|
if (texts.length === 0) return [];
|
|
18349
|
+
const total = options.totalTimeoutMs;
|
|
18350
|
+
if (total === void 0) return embedMany(texts, options, void 0);
|
|
18351
|
+
return withDeadline((signal) => embedMany(texts, options, signal), total, "embedding batch");
|
|
18352
|
+
}
|
|
18353
|
+
async function embedMany(texts, options, outer) {
|
|
18347
18354
|
const { baseUrl = BASE_URL, model, batchSize, cache } = options;
|
|
18348
18355
|
const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
|
|
18349
18356
|
const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
|
|
@@ -18364,7 +18371,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
18364
18371
|
if (uncachedTexts.length === 0) {
|
|
18365
18372
|
return results;
|
|
18366
18373
|
}
|
|
18367
|
-
const headers = await resolveAuthHeaders(options);
|
|
18374
|
+
const headers = await resolveAuthHeaders(options, outer);
|
|
18375
|
+
if (outer?.aborted) throw outer.reason;
|
|
18368
18376
|
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
18369
18377
|
let newEmbeddings;
|
|
18370
18378
|
if (uncachedTexts.length <= chunkSize) {
|
|
@@ -18375,7 +18383,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
18375
18383
|
embeddingModel,
|
|
18376
18384
|
options.onUsage,
|
|
18377
18385
|
options.maskInput,
|
|
18378
|
-
timeoutMs
|
|
18386
|
+
timeoutMs,
|
|
18387
|
+
outer
|
|
18379
18388
|
);
|
|
18380
18389
|
} else {
|
|
18381
18390
|
const chunks = [];
|
|
@@ -18386,6 +18395,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
18386
18395
|
let nextIndex = 0;
|
|
18387
18396
|
const worker = async () => {
|
|
18388
18397
|
while (nextIndex < chunks.length) {
|
|
18398
|
+
if (outer?.aborted) throw outer.reason;
|
|
18389
18399
|
const idx = nextIndex++;
|
|
18390
18400
|
allEmbeddings[idx] = await generateEmbeddingsBatch(
|
|
18391
18401
|
chunks[idx],
|
|
@@ -18394,7 +18404,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
18394
18404
|
embeddingModel,
|
|
18395
18405
|
options.onUsage,
|
|
18396
18406
|
options.maskInput,
|
|
18397
|
-
timeoutMs
|
|
18407
|
+
timeoutMs,
|
|
18408
|
+
outer
|
|
18398
18409
|
);
|
|
18399
18410
|
}
|
|
18400
18411
|
};
|
|
@@ -18405,6 +18416,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
18405
18416
|
await Promise.all(workers);
|
|
18406
18417
|
newEmbeddings = allEmbeddings.flat();
|
|
18407
18418
|
}
|
|
18419
|
+
if (outer?.aborted) throw outer.reason;
|
|
18408
18420
|
for (let i = 0; i < uncachedIndices.length; i++) {
|
|
18409
18421
|
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
18410
18422
|
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
@@ -29876,7 +29888,7 @@ async function rankPreparedVaultCandidates(query, prepared, embeddingOptions, se
|
|
|
29876
29888
|
if (useFusion && !embeddingsUnavailable && facetQueries) {
|
|
29877
29889
|
let subEmbeddings;
|
|
29878
29890
|
try {
|
|
29879
|
-
subEmbeddings = await generateEmbeddings(facetQueries, embeddingOptions);
|
|
29891
|
+
subEmbeddings = prepared.facetEmbeddings ?? await generateEmbeddings(facetQueries, embeddingOptions);
|
|
29880
29892
|
} catch (err) {
|
|
29881
29893
|
getLogger().warn(
|
|
29882
29894
|
"memoryVault: sub-query embedding failed \u2014 falling back to single-query ranking: " + (err instanceof Error ? err.message : String(err))
|
|
@@ -30061,6 +30073,35 @@ var DEFAULT_SCOPE = "private";
|
|
|
30061
30073
|
var DEFAULT_CONSOLIDATE_THRESHOLD = 0.55;
|
|
30062
30074
|
var DEFAULT_CONSOLIDATE_TOP_K = 20;
|
|
30063
30075
|
async function retain(content, ctx, options = {}) {
|
|
30076
|
+
return retainWithPersistence(
|
|
30077
|
+
content,
|
|
30078
|
+
{
|
|
30079
|
+
embeddingOptions: ctx.embeddingOptions,
|
|
30080
|
+
vaultCache: ctx.vaultCache,
|
|
30081
|
+
persistence: {
|
|
30082
|
+
prepare: (query, searchOptions) => prepareVaultCandidates(
|
|
30083
|
+
query,
|
|
30084
|
+
ctx.vaultCtx,
|
|
30085
|
+
ctx.embeddingOptions,
|
|
30086
|
+
ctx.vaultCache,
|
|
30087
|
+
searchOptions
|
|
30088
|
+
),
|
|
30089
|
+
get: (id) => getVaultMemoryOp(ctx.vaultCtx, id),
|
|
30090
|
+
tombstones: (_embedding, _model, scope, folderId) => getAllVaultMemoriesOp(ctx.vaultCtx, {
|
|
30091
|
+
includeDeleted: true,
|
|
30092
|
+
scopes: [scope],
|
|
30093
|
+
...folderId !== void 0 && { folderId }
|
|
30094
|
+
}),
|
|
30095
|
+
create: (input) => createVaultMemoryOp(ctx.vaultCtx, input),
|
|
30096
|
+
update: (id, patch) => updateVaultMemoryOp(ctx.vaultCtx, id, patch),
|
|
30097
|
+
supersede: (id, successor) => supersedeVaultMemoryOp(ctx.vaultCtx, id, successor),
|
|
30098
|
+
createSuperseding: (input, target) => createSupersedingMemoryOp(ctx.vaultCtx, input, target)
|
|
30099
|
+
}
|
|
30100
|
+
},
|
|
30101
|
+
options
|
|
30102
|
+
);
|
|
30103
|
+
}
|
|
30104
|
+
async function retainWithPersistence(content, ctx, options = {}) {
|
|
30064
30105
|
const trimmed = content.trim();
|
|
30065
30106
|
if (trimmed.length === 0) {
|
|
30066
30107
|
throw new Error("retain: content cannot be empty");
|
|
@@ -30073,19 +30114,13 @@ async function retain(content, ctx, options = {}) {
|
|
|
30073
30114
|
let supersedeContent;
|
|
30074
30115
|
let prepared;
|
|
30075
30116
|
if (enableAutoMerge) {
|
|
30076
|
-
prepared = await
|
|
30077
|
-
|
|
30078
|
-
|
|
30079
|
-
|
|
30080
|
-
|
|
30081
|
-
{
|
|
30082
|
-
|
|
30083
|
-
useFusion: false,
|
|
30084
|
-
scopes: [resolvedScope],
|
|
30085
|
-
includeArchived: true,
|
|
30086
|
-
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
30087
|
-
}
|
|
30088
|
-
);
|
|
30117
|
+
prepared = await ctx.persistence.prepare(trimmed, {
|
|
30118
|
+
limit: Math.max(options.consolidateTopK ?? DEFAULT_CONSOLIDATE_TOP_K, 1),
|
|
30119
|
+
useFusion: false,
|
|
30120
|
+
scopes: [resolvedScope],
|
|
30121
|
+
includeArchived: true,
|
|
30122
|
+
...options.folderId !== void 0 && { folderId: options.folderId }
|
|
30123
|
+
});
|
|
30089
30124
|
if (prepared.embeddingFailure || prepared.embeddingsUnavailable) {
|
|
30090
30125
|
throw new Error(
|
|
30091
30126
|
"retain: embeddings unavailable \u2014 refusing to auto-merge against an inert cosine lane, which would create a duplicate instead of merging into the existing memory. Retry when embeddings recover, or pass enableAutoMerge: false to force a create."
|
|
@@ -30116,7 +30151,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
30116
30151
|
);
|
|
30117
30152
|
if (matches.length > 0) {
|
|
30118
30153
|
const targetId = matches[0].uniqueId;
|
|
30119
|
-
const existing = await
|
|
30154
|
+
const existing = await ctx.persistence.get(targetId);
|
|
30120
30155
|
if (existing && !existing.supersededBy) {
|
|
30121
30156
|
const mergedSourceIds = unionStrings(
|
|
30122
30157
|
existing.sourceChunkIds ?? [],
|
|
@@ -30125,7 +30160,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
30125
30160
|
const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
|
|
30126
30161
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
30127
30162
|
const resurrect = resurrectFields(existing);
|
|
30128
|
-
const updated = await
|
|
30163
|
+
const updated = await ctx.persistence.update(targetId, {
|
|
30129
30164
|
content: existing.content,
|
|
30130
30165
|
proofCountIncrement: 1,
|
|
30131
30166
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -30152,7 +30187,8 @@ async function retain(content, ctx, options = {}) {
|
|
|
30152
30187
|
}
|
|
30153
30188
|
const contentToWrite = supersedeContent ?? trimmed;
|
|
30154
30189
|
const reusableQueryEmbedding = supersedeContent === void 0 && prepared && prepared.queryEmbedding.length > 0 ? prepared.queryEmbedding : void 0;
|
|
30155
|
-
const
|
|
30190
|
+
const generatedEmbedding = reusableQueryEmbedding ?? await generateEmbedding(contentToWrite, ctx.embeddingOptions);
|
|
30191
|
+
const embedding = ctx.normalizeEmbedding?.(generatedEmbedding) ?? generatedEmbedding;
|
|
30156
30192
|
const embeddingModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
30157
30193
|
if (options.respectTombstones) {
|
|
30158
30194
|
const tombstone = await findTombstoneMatch(embedding, embeddingModel, resolvedScope, ctx, {
|
|
@@ -30192,8 +30228,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
30192
30228
|
};
|
|
30193
30229
|
if (supersedeTargetIds.length > 0) {
|
|
30194
30230
|
const [primaryTargetId, ...restTargetIds] = supersedeTargetIds;
|
|
30195
|
-
const { created: created2, retired } = await
|
|
30196
|
-
ctx.vaultCtx,
|
|
30231
|
+
const { created: created2, retired } = await ctx.persistence.createSuperseding(
|
|
30197
30232
|
createOpts,
|
|
30198
30233
|
primaryTargetId
|
|
30199
30234
|
);
|
|
@@ -30209,11 +30244,11 @@ async function retain(content, ctx, options = {}) {
|
|
|
30209
30244
|
for (const staleId of restTargetIds) {
|
|
30210
30245
|
let ok = false;
|
|
30211
30246
|
try {
|
|
30212
|
-
ok = await
|
|
30247
|
+
ok = await ctx.persistence.supersede(staleId, created2.uniqueId) === true;
|
|
30213
30248
|
} catch {
|
|
30214
30249
|
}
|
|
30215
30250
|
if (ok) continue;
|
|
30216
|
-
const stillLive = await
|
|
30251
|
+
const stillLive = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(staleId) : ctx.persistence.get(staleId)).catch(() => null);
|
|
30217
30252
|
if (stillLive && !stillLive.supersededBy) liveLeftovers.push(staleId);
|
|
30218
30253
|
}
|
|
30219
30254
|
if (liveLeftovers.length > 0) {
|
|
@@ -30240,7 +30275,7 @@ async function retain(content, ctx, options = {}) {
|
|
|
30240
30275
|
`supersede: primary target ${primaryTargetId} retired or deleted inside the atomic write`
|
|
30241
30276
|
);
|
|
30242
30277
|
}
|
|
30243
|
-
const created = await
|
|
30278
|
+
const created = await ctx.persistence.create(createOpts);
|
|
30244
30279
|
cacheRowVector(
|
|
30245
30280
|
ctx.vaultCache,
|
|
30246
30281
|
created.uniqueId,
|
|
@@ -30259,11 +30294,7 @@ function unionStrings(a, b) {
|
|
|
30259
30294
|
return [.../* @__PURE__ */ new Set([...a, ...b])];
|
|
30260
30295
|
}
|
|
30261
30296
|
async function findTombstoneMatch(embedding, embeddingModel, scope, ctx, opts) {
|
|
30262
|
-
const rows = await
|
|
30263
|
-
includeDeleted: true,
|
|
30264
|
-
scopes: [scope],
|
|
30265
|
-
...opts.folderId !== void 0 && { folderId: opts.folderId }
|
|
30266
|
-
});
|
|
30297
|
+
const rows = await ctx.persistence.tombstones(embedding, embeddingModel, scope, opts.folderId);
|
|
30267
30298
|
let bestId = null;
|
|
30268
30299
|
let bestSim = opts.threshold;
|
|
30269
30300
|
for (const row of rows) {
|
|
@@ -30330,7 +30361,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
30330
30361
|
if (requestedIds.length === 0) return null;
|
|
30331
30362
|
const valid = [];
|
|
30332
30363
|
for (const id of requestedIds) {
|
|
30333
|
-
const existing = await
|
|
30364
|
+
const existing = await ctx.persistence.get(id);
|
|
30334
30365
|
if (existing && !existing.supersededBy) valid.push(id);
|
|
30335
30366
|
}
|
|
30336
30367
|
if (valid.length === 0) {
|
|
@@ -30342,7 +30373,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
30342
30373
|
return { supersede: valid, content: decision.content };
|
|
30343
30374
|
}
|
|
30344
30375
|
if (decision.action === "noop" && decision.targetId) {
|
|
30345
|
-
const existing = await
|
|
30376
|
+
const existing = await ctx.persistence.get(decision.targetId);
|
|
30346
30377
|
if (!existing || existing.supersededBy) {
|
|
30347
30378
|
return abandonToRace(
|
|
30348
30379
|
options,
|
|
@@ -30356,7 +30387,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
30356
30387
|
const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
|
|
30357
30388
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
30358
30389
|
const resurrect = resurrectFields(existing);
|
|
30359
|
-
const updated = await
|
|
30390
|
+
const updated = await ctx.persistence.update(decision.targetId, {
|
|
30360
30391
|
content: existing.content,
|
|
30361
30392
|
proofCountIncrement: 1,
|
|
30362
30393
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -30384,7 +30415,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
30384
30415
|
};
|
|
30385
30416
|
}
|
|
30386
30417
|
if (decision.action === "update" && decision.targetId && decision.content) {
|
|
30387
|
-
const existing = await
|
|
30418
|
+
const existing = await ctx.persistence.get(decision.targetId);
|
|
30388
30419
|
if (!existing || existing.supersededBy) {
|
|
30389
30420
|
return abandonToRace(
|
|
30390
30421
|
options,
|
|
@@ -30395,12 +30426,13 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
30395
30426
|
existing.sourceChunkIds ?? [],
|
|
30396
30427
|
options.sourceChunkIds ?? []
|
|
30397
30428
|
);
|
|
30398
|
-
const
|
|
30429
|
+
const generatedEmbedding = await generateEmbedding(decision.content, ctx.embeddingOptions);
|
|
30430
|
+
const newEmbedding = ctx.normalizeEmbedding?.(generatedEmbedding) ?? generatedEmbedding;
|
|
30399
30431
|
const consolidatedModel = ctx.embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
30400
30432
|
const eventTimeUpdate = pickEventTimeUpdate(existing, options.eventTime);
|
|
30401
30433
|
const factTypeUpdate = pickFactTypeUpdate(existing, options.factType);
|
|
30402
30434
|
const resurrect = resurrectFields(existing);
|
|
30403
|
-
const updated = await
|
|
30435
|
+
const updated = await ctx.persistence.update(decision.targetId, {
|
|
30404
30436
|
content: decision.content,
|
|
30405
30437
|
proofCountIncrement: 1,
|
|
30406
30438
|
observationSourceIds: options.sourceChunkIds,
|
|
@@ -30444,7 +30476,7 @@ async function tryConsolidate(trimmed, ctx, options, prepared) {
|
|
|
30444
30476
|
return null;
|
|
30445
30477
|
}
|
|
30446
30478
|
async function assertMergeTargetGoneOrThrow(ctx, targetId) {
|
|
30447
|
-
const stillExists = await
|
|
30479
|
+
const stillExists = await (ctx.persistence.getFresh ? ctx.persistence.getFresh(targetId) : ctx.persistence.get(targetId));
|
|
30448
30480
|
if (stillExists) {
|
|
30449
30481
|
throw new Error(`retain: merge into memory ${targetId} failed to persist`);
|
|
30450
30482
|
}
|
|
@@ -31930,7 +31962,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
31930
31962
|
if (graphLaneFailed) degraded.push("graph-lane-failed");
|
|
31931
31963
|
if (temporalLaneFailed) degraded.push("temporal-lane-failed");
|
|
31932
31964
|
if (chunksScopeRestricted) degraded.push("chunks-scope-restricted");
|
|
31933
|
-
const laneRan = types.includes("fact") && !!ctx.vaultCtx && !!ctx.vaultCache || types.includes("chunk") && !!ctx.storageCtx || chunksScopeRestricted && !!ctx.storageCtx;
|
|
31965
|
+
const laneRan = types.includes("fact") && (!!ctx.factSource || !!ctx.vaultCtx && !!ctx.vaultCache) || types.includes("chunk") && !!ctx.storageCtx || chunksScopeRestricted && !!ctx.storageCtx;
|
|
31934
31966
|
const scores = admitted.map((m) => m.score);
|
|
31935
31967
|
const minScoreApplied = factResults.length > 0 ? factFloor : chunkResults.length > 0 ? chunkFloor : factFloor >= 0 ? factFloor : chunkFloor;
|
|
31936
31968
|
const diagnostics = {
|
|
@@ -31972,7 +32004,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
31972
32004
|
return { memories: [], usedBudget, reranked: false, candidateCount: 0 };
|
|
31973
32005
|
}
|
|
31974
32006
|
const needsChunkEmbedding = types.includes("chunk") && ctx.storageCtx;
|
|
31975
|
-
const wantsTemporal = types.includes("fact") && ctx.vaultCtx;
|
|
32007
|
+
const wantsTemporal = types.includes("fact") && (ctx.factSource || ctx.vaultCtx);
|
|
31976
32008
|
const graphRefiner = flags.traverse && options.graphRefine && options.decomposeOptions ? createLlmNeighborRefiner(options.decomposeOptions) : void 0;
|
|
31977
32009
|
const queryEmbedTotalTimeoutMs = options.queryEmbedTotalTimeoutMs ?? DEFAULT_QUERY_EMBED_TOTAL_TIMEOUT_MS;
|
|
31978
32010
|
const prepStart = nowMs2();
|
|
@@ -32002,7 +32034,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
32002
32034
|
safeLane(
|
|
32003
32035
|
"graph",
|
|
32004
32036
|
() => graphLaneFailed = true,
|
|
32005
|
-
() => buildGraphLaneRanking(query, ctx, flags.traverse, {
|
|
32037
|
+
() => ctx.factSource ? ctx.factSource.graphRanking(query, flags.traverse, options) : buildGraphLaneRanking(query, ctx, flags.traverse, {
|
|
32006
32038
|
...options.maxHops !== void 0 && { maxHops: options.maxHops },
|
|
32007
32039
|
...options.entityFanout !== void 0 && { entityFanout: options.entityFanout },
|
|
32008
32040
|
...options.nodeBudget !== void 0 && { nodeBudget: options.nodeBudget },
|
|
@@ -32013,13 +32045,13 @@ async function recall(query, ctx, options = {}) {
|
|
|
32013
32045
|
wantsTemporal ? safeLane(
|
|
32014
32046
|
"temporal",
|
|
32015
32047
|
() => temporalLaneFailed = true,
|
|
32016
|
-
() => buildTemporalLaneRanking(query, ctx.vaultCtx, options.now)
|
|
32048
|
+
() => ctx.factSource ? ctx.factSource.temporalRanking(query, options.now) : buildTemporalLaneRanking(query, ctx.vaultCtx, options.now)
|
|
32017
32049
|
) : Promise.resolve([])
|
|
32018
32050
|
]);
|
|
32019
32051
|
prepMs = nowMs2() - prepStart;
|
|
32020
32052
|
graphLaneCount = entityRanking.length;
|
|
32021
32053
|
temporalLaneCount = temporalRanking.length;
|
|
32022
|
-
if (types.includes("fact") && ctx.vaultCtx && ctx.vaultCache) {
|
|
32054
|
+
if (types.includes("fact") && (ctx.factSource || ctx.vaultCtx && ctx.vaultCache)) {
|
|
32023
32055
|
const factStart = nowMs2();
|
|
32024
32056
|
const vaultMinScore = options.minScore ?? DEFAULT_FACT_MIN_SCORE;
|
|
32025
32057
|
factFloor = vaultMinScore;
|
|
@@ -32035,50 +32067,50 @@ async function recall(query, ctx, options = {}) {
|
|
|
32035
32067
|
rankedOnCosine: factRankedOnCosine,
|
|
32036
32068
|
decryptLast: factDecryptLast,
|
|
32037
32069
|
rowsDecrypted: factRowsDecrypted
|
|
32038
|
-
} = await searchVaultMemoriesWithSize(
|
|
32039
|
-
|
|
32070
|
+
} = await (ctx.factSource?.search.bind(ctx.factSource) ?? ((searchQuery, searchOptions) => searchVaultMemoriesWithSize(
|
|
32071
|
+
searchQuery,
|
|
32040
32072
|
ctx.vaultCtx,
|
|
32041
32073
|
ctx.embeddingOptions,
|
|
32042
32074
|
ctx.vaultCache,
|
|
32043
|
-
|
|
32044
|
-
|
|
32045
|
-
|
|
32046
|
-
|
|
32047
|
-
|
|
32048
|
-
|
|
32049
|
-
|
|
32050
|
-
|
|
32051
|
-
|
|
32052
|
-
|
|
32053
|
-
|
|
32054
|
-
|
|
32055
|
-
|
|
32056
|
-
|
|
32057
|
-
|
|
32058
|
-
|
|
32059
|
-
|
|
32060
|
-
|
|
32061
|
-
|
|
32062
|
-
|
|
32063
|
-
|
|
32064
|
-
|
|
32065
|
-
|
|
32066
|
-
|
|
32067
|
-
|
|
32068
|
-
|
|
32069
|
-
|
|
32070
|
-
|
|
32071
|
-
|
|
32072
|
-
|
|
32073
|
-
|
|
32074
|
-
|
|
32075
|
-
|
|
32076
|
-
|
|
32077
|
-
|
|
32078
|
-
|
|
32079
|
-
|
|
32080
|
-
|
|
32081
|
-
);
|
|
32075
|
+
searchOptions
|
|
32076
|
+
)))(query, {
|
|
32077
|
+
limit: types.includes("chunk") ? Math.max(limit * 2, 16) : limit,
|
|
32078
|
+
minSimilarity: vaultMinScore,
|
|
32079
|
+
useFusion: true,
|
|
32080
|
+
rerank: flags.rerank,
|
|
32081
|
+
...options.rerankTopN !== void 0 && { rerankTopN: options.rerankTopN },
|
|
32082
|
+
...options.ceWeight !== void 0 && { ceWeight: options.ceWeight },
|
|
32083
|
+
...options.rerankLoadTimeoutMs !== void 0 && {
|
|
32084
|
+
rerankLoadTimeoutMs: options.rerankLoadTimeoutMs
|
|
32085
|
+
},
|
|
32086
|
+
...options.recencyAlpha !== void 0 && { recencyAlpha: options.recencyAlpha },
|
|
32087
|
+
...options.recency && { recency: options.recency },
|
|
32088
|
+
...options.mmr !== void 0 && { mmr: options.mmr },
|
|
32089
|
+
...options.supersessionBoost !== void 0 && {
|
|
32090
|
+
supersessionBoost: options.supersessionBoost
|
|
32091
|
+
},
|
|
32092
|
+
...options.supersessionWindow !== void 0 && {
|
|
32093
|
+
supersessionWindow: options.supersessionWindow
|
|
32094
|
+
},
|
|
32095
|
+
...options.proofCountAlpha !== void 0 && {
|
|
32096
|
+
proofCountAlpha: options.proofCountAlpha
|
|
32097
|
+
},
|
|
32098
|
+
...options.bm25AdmissionDivisor !== void 0 && {
|
|
32099
|
+
bm25AdmissionDivisor: options.bm25AdmissionDivisor
|
|
32100
|
+
},
|
|
32101
|
+
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
32102
|
+
...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
|
|
32103
|
+
...subQueries && { subQueries },
|
|
32104
|
+
...options.scopes && { scopes: options.scopes },
|
|
32105
|
+
...options.folderId !== void 0 && { folderId: options.folderId },
|
|
32106
|
+
...options.factTypes?.length && { factTypes: options.factTypes },
|
|
32107
|
+
...options.memoryIds !== void 0 && { memoryIds: options.memoryIds },
|
|
32108
|
+
...options.factTypeWeights && { factTypeWeights: options.factTypeWeights },
|
|
32109
|
+
...entityRanking.length > 0 && { entityRanking },
|
|
32110
|
+
...temporalRanking.length > 0 && { temporalRanking },
|
|
32111
|
+
...needsChunkEmbedding && { queryEmbedding: queryEmbedding ?? [] },
|
|
32112
|
+
queryEmbedTotalTimeoutMs
|
|
32113
|
+
});
|
|
32082
32114
|
factResults.push(
|
|
32083
32115
|
...dedupeBy(
|
|
32084
32116
|
results,
|
|
@@ -523,10 +523,9 @@ interface MetricsHooksOptions {
|
|
|
523
523
|
includeErrorMessages?: boolean;
|
|
524
524
|
}
|
|
525
525
|
/**
|
|
526
|
-
* Build {@link RunHooks} that report run lifecycle, model calls, and tool
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* already swallows hook errors; we avoid double-logging here).
|
|
526
|
+
* Build {@link RunHooks} that report run lifecycle, model calls, and tool calls to `sink`; every run ends in exactly one `run.completed` or `run.failed`, and no message contents or tool arguments are emitted.
|
|
527
|
+
*
|
|
528
|
+
* @see TELEMETRY.md for event payloads and metric names.
|
|
530
529
|
*/
|
|
531
530
|
declare function createMetricsHooks(sink: TelemetrySink, opts?: MetricsHooksOptions): RunHooks;
|
|
532
531
|
|
|
@@ -523,10 +523,9 @@ interface MetricsHooksOptions {
|
|
|
523
523
|
includeErrorMessages?: boolean;
|
|
524
524
|
}
|
|
525
525
|
/**
|
|
526
|
-
* Build {@link RunHooks} that report run lifecycle, model calls, and tool
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* already swallows hook errors; we avoid double-logging here).
|
|
526
|
+
* Build {@link RunHooks} that report run lifecycle, model calls, and tool calls to `sink`; every run ends in exactly one `run.completed` or `run.failed`, and no message contents or tool arguments are emitted.
|
|
527
|
+
*
|
|
528
|
+
* @see TELEMETRY.md for event payloads and metric names.
|
|
530
529
|
*/
|
|
531
530
|
declare function createMetricsHooks(sink: TelemetrySink, opts?: MetricsHooksOptions): RunHooks;
|
|
532
531
|
|
|
@@ -1058,7 +1058,7 @@ async function embedOne(text, options, outer) {
|
|
|
1058
1058
|
}
|
|
1059
1059
|
var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
1060
1060
|
var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
1061
|
-
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs) {
|
|
1061
|
+
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs, outer) {
|
|
1062
1062
|
const response = await withEmbeddingRetry(
|
|
1063
1063
|
() => withDeadline(
|
|
1064
1064
|
(signal) => postApiV1Embeddings({
|
|
@@ -1068,8 +1068,10 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
1068
1068
|
...signal && { signal }
|
|
1069
1069
|
}),
|
|
1070
1070
|
timeoutMs,
|
|
1071
|
-
"embedding batch request"
|
|
1072
|
-
|
|
1071
|
+
"embedding batch request",
|
|
1072
|
+
outer
|
|
1073
|
+
),
|
|
1074
|
+
outer
|
|
1073
1075
|
);
|
|
1074
1076
|
if (response.error) {
|
|
1075
1077
|
throw embeddingErrorFrom(response);
|
|
@@ -1087,6 +1089,11 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
1087
1089
|
}
|
|
1088
1090
|
async function generateEmbeddings(texts, options) {
|
|
1089
1091
|
if (texts.length === 0) return [];
|
|
1092
|
+
const total = options.totalTimeoutMs;
|
|
1093
|
+
if (total === void 0) return embedMany(texts, options, void 0);
|
|
1094
|
+
return withDeadline((signal) => embedMany(texts, options, signal), total, "embedding batch");
|
|
1095
|
+
}
|
|
1096
|
+
async function embedMany(texts, options, outer) {
|
|
1090
1097
|
const { baseUrl = BASE_URL, model, batchSize, cache } = options;
|
|
1091
1098
|
const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
|
|
1092
1099
|
const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
|
|
@@ -1107,7 +1114,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
1107
1114
|
if (uncachedTexts.length === 0) {
|
|
1108
1115
|
return results;
|
|
1109
1116
|
}
|
|
1110
|
-
const headers = await resolveAuthHeaders(options);
|
|
1117
|
+
const headers = await resolveAuthHeaders(options, outer);
|
|
1118
|
+
if (outer?.aborted) throw outer.reason;
|
|
1111
1119
|
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
1112
1120
|
let newEmbeddings;
|
|
1113
1121
|
if (uncachedTexts.length <= chunkSize) {
|
|
@@ -1118,7 +1126,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
1118
1126
|
embeddingModel,
|
|
1119
1127
|
options.onUsage,
|
|
1120
1128
|
options.maskInput,
|
|
1121
|
-
timeoutMs
|
|
1129
|
+
timeoutMs,
|
|
1130
|
+
outer
|
|
1122
1131
|
);
|
|
1123
1132
|
} else {
|
|
1124
1133
|
const chunks = [];
|
|
@@ -1129,6 +1138,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
1129
1138
|
let nextIndex = 0;
|
|
1130
1139
|
const worker = async () => {
|
|
1131
1140
|
while (nextIndex < chunks.length) {
|
|
1141
|
+
if (outer?.aborted) throw outer.reason;
|
|
1132
1142
|
const idx = nextIndex++;
|
|
1133
1143
|
allEmbeddings[idx] = await generateEmbeddingsBatch(
|
|
1134
1144
|
chunks[idx],
|
|
@@ -1137,7 +1147,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
1137
1147
|
embeddingModel,
|
|
1138
1148
|
options.onUsage,
|
|
1139
1149
|
options.maskInput,
|
|
1140
|
-
timeoutMs
|
|
1150
|
+
timeoutMs,
|
|
1151
|
+
outer
|
|
1141
1152
|
);
|
|
1142
1153
|
}
|
|
1143
1154
|
};
|
|
@@ -1148,6 +1159,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
1148
1159
|
await Promise.all(workers);
|
|
1149
1160
|
newEmbeddings = allEmbeddings.flat();
|
|
1150
1161
|
}
|
|
1162
|
+
if (outer?.aborted) throw outer.reason;
|
|
1151
1163
|
for (let i = 0; i < uncachedIndices.length; i++) {
|
|
1152
1164
|
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
1153
1165
|
results[uncachedIndices[i]] = Array.from(f32Embedding);
|
|
@@ -936,7 +936,7 @@ async function embedOne(text, options, outer) {
|
|
|
936
936
|
}
|
|
937
937
|
var DEFAULT_EMBEDDING_BATCH_SIZE = 100;
|
|
938
938
|
var DEFAULT_EMBEDDING_BATCH_CONCURRENCY = 3;
|
|
939
|
-
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs) {
|
|
939
|
+
async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage, maskInput, timeoutMs, outer) {
|
|
940
940
|
const response = await withEmbeddingRetry(
|
|
941
941
|
() => withDeadline(
|
|
942
942
|
(signal) => postApiV1Embeddings({
|
|
@@ -946,8 +946,10 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
946
946
|
...signal && { signal }
|
|
947
947
|
}),
|
|
948
948
|
timeoutMs,
|
|
949
|
-
"embedding batch request"
|
|
950
|
-
|
|
949
|
+
"embedding batch request",
|
|
950
|
+
outer
|
|
951
|
+
),
|
|
952
|
+
outer
|
|
951
953
|
);
|
|
952
954
|
if (response.error) {
|
|
953
955
|
throw embeddingErrorFrom(response);
|
|
@@ -965,6 +967,11 @@ async function generateEmbeddingsBatch(texts, headers, baseUrl, model, onUsage,
|
|
|
965
967
|
}
|
|
966
968
|
async function generateEmbeddings(texts, options) {
|
|
967
969
|
if (texts.length === 0) return [];
|
|
970
|
+
const total = options.totalTimeoutMs;
|
|
971
|
+
if (total === void 0) return embedMany(texts, options, void 0);
|
|
972
|
+
return withDeadline((signal) => embedMany(texts, options, signal), total, "embedding batch");
|
|
973
|
+
}
|
|
974
|
+
async function embedMany(texts, options, outer) {
|
|
968
975
|
const { baseUrl = BASE_URL, model, batchSize, cache } = options;
|
|
969
976
|
const timeoutMs = options.timeoutMs ?? DEFAULT_EMBEDDING_REQUEST_TIMEOUT_MS;
|
|
970
977
|
const chunkSize = batchSize ?? DEFAULT_EMBEDDING_BATCH_SIZE;
|
|
@@ -985,7 +992,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
985
992
|
if (uncachedTexts.length === 0) {
|
|
986
993
|
return results;
|
|
987
994
|
}
|
|
988
|
-
const headers = await resolveAuthHeaders(options);
|
|
995
|
+
const headers = await resolveAuthHeaders(options, outer);
|
|
996
|
+
if (outer?.aborted) throw outer.reason;
|
|
989
997
|
const embeddingModel = model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
990
998
|
let newEmbeddings;
|
|
991
999
|
if (uncachedTexts.length <= chunkSize) {
|
|
@@ -996,7 +1004,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
996
1004
|
embeddingModel,
|
|
997
1005
|
options.onUsage,
|
|
998
1006
|
options.maskInput,
|
|
999
|
-
timeoutMs
|
|
1007
|
+
timeoutMs,
|
|
1008
|
+
outer
|
|
1000
1009
|
);
|
|
1001
1010
|
} else {
|
|
1002
1011
|
const chunks = [];
|
|
@@ -1007,6 +1016,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
1007
1016
|
let nextIndex = 0;
|
|
1008
1017
|
const worker = async () => {
|
|
1009
1018
|
while (nextIndex < chunks.length) {
|
|
1019
|
+
if (outer?.aborted) throw outer.reason;
|
|
1010
1020
|
const idx = nextIndex++;
|
|
1011
1021
|
allEmbeddings[idx] = await generateEmbeddingsBatch(
|
|
1012
1022
|
chunks[idx],
|
|
@@ -1015,7 +1025,8 @@ async function generateEmbeddings(texts, options) {
|
|
|
1015
1025
|
embeddingModel,
|
|
1016
1026
|
options.onUsage,
|
|
1017
1027
|
options.maskInput,
|
|
1018
|
-
timeoutMs
|
|
1028
|
+
timeoutMs,
|
|
1029
|
+
outer
|
|
1019
1030
|
);
|
|
1020
1031
|
}
|
|
1021
1032
|
};
|
|
@@ -1026,6 +1037,7 @@ async function generateEmbeddings(texts, options) {
|
|
|
1026
1037
|
await Promise.all(workers);
|
|
1027
1038
|
newEmbeddings = allEmbeddings.flat();
|
|
1028
1039
|
}
|
|
1040
|
+
if (outer?.aborted) throw outer.reason;
|
|
1029
1041
|
for (let i = 0; i < uncachedIndices.length; i++) {
|
|
1030
1042
|
const f32Embedding = Float32Array.from(newEmbeddings[i]);
|
|
1031
1043
|
results[uncachedIndices[i]] = Array.from(f32Embedding);
|