@anuma/sdk 3.8.5 → 3.9.1
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/{chunk-42Y42CAZ.mjs → chunk-YFJAHJMB.mjs} +278 -62
- package/dist/expo/index.cjs +278 -61
- package/dist/expo/index.d.mts +19 -0
- package/dist/expo/index.d.ts +19 -0
- package/dist/expo/index.mjs +1 -1
- package/dist/expo/{recall-JFZ3Z6EX.mjs → recall-KWTVD4IR.mjs} +1 -1
- package/dist/react/{chunk-NLVSQAYH.mjs → chunk-GDS7GHBF.mjs} +305 -62
- package/dist/react/index.cjs +309 -61
- package/dist/react/index.d.mts +108 -1
- package/dist/react/index.d.ts +108 -1
- package/dist/react/index.mjs +9 -1
- package/dist/react/{recall-BCEH7U2Z.mjs → recall-SBQ4LNRJ.mjs} +1 -1
- package/dist/server/{chunk-FS56IDOW.mjs → chunk-QC4WHNIJ.mjs} +278 -62
- package/dist/server/index.cjs +278 -61
- package/dist/server/index.d.mts +19 -0
- package/dist/server/index.d.ts +19 -0
- package/dist/server/index.mjs +1 -1
- package/dist/server/{recall-VDMDNQNB.mjs → recall-NLJNELJY.mjs} +1 -1
- package/package.json +2 -2
|
@@ -2531,6 +2531,108 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
2531
2531
|
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
2532
2532
|
);
|
|
2533
2533
|
}
|
|
2534
|
+
function vaultMemoryRawToRankable(raw) {
|
|
2535
|
+
return {
|
|
2536
|
+
uniqueId: raw.id,
|
|
2537
|
+
// @text coerces NULL→"" on the Model path; unsafeFetchRaw returns raw NULL, so guard.
|
|
2538
|
+
scope: raw.scope ?? "",
|
|
2539
|
+
folderId: raw.folder_id ?? null,
|
|
2540
|
+
embedding: raw.embedding ?? null,
|
|
2541
|
+
embeddingModel: raw.embedding_model ?? null,
|
|
2542
|
+
createdAt: new Date(raw.created_at),
|
|
2543
|
+
updatedAt: new Date(raw.updated_at)
|
|
2544
|
+
};
|
|
2545
|
+
}
|
|
2546
|
+
async function getVaultRankingProjectionsOp(ctx, options) {
|
|
2547
|
+
const conditions = [
|
|
2548
|
+
...baseVaultConditions(ctx, options),
|
|
2549
|
+
...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
|
|
2550
|
+
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
|
|
2551
|
+
Q3.sortBy(options?.since ? "updated_at" : "created_at", Q3.desc),
|
|
2552
|
+
...options?.limit !== null && options?.limit !== void 0 && options.limit > 0 ? [Q3.take(options.limit)] : []
|
|
2553
|
+
];
|
|
2554
|
+
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2555
|
+
return results.map(vaultMemoryRawToRankable);
|
|
2556
|
+
}
|
|
2557
|
+
function baseVaultSql(ctx) {
|
|
2558
|
+
const clauses = [
|
|
2559
|
+
'"is_deleted" = 0',
|
|
2560
|
+
'"archived_at" is null',
|
|
2561
|
+
`"trust_tier" is not 'quarantined'`,
|
|
2562
|
+
'"superseded_by" is null'
|
|
2563
|
+
];
|
|
2564
|
+
const args = [];
|
|
2565
|
+
if (ctx.userId !== void 0) {
|
|
2566
|
+
clauses.push('"user_id" = ?');
|
|
2567
|
+
args.push(ctx.userId);
|
|
2568
|
+
}
|
|
2569
|
+
return { sql: clauses.join(" and "), args };
|
|
2570
|
+
}
|
|
2571
|
+
async function getVaultCandidateKeysOp(ctx, options) {
|
|
2572
|
+
const mapRaw = (raw) => ({
|
|
2573
|
+
uniqueId: raw.id,
|
|
2574
|
+
folderId: raw.folder_id ?? null,
|
|
2575
|
+
scope: raw.scope ?? "",
|
|
2576
|
+
embeddingModel: raw.embedding_model ?? null,
|
|
2577
|
+
updatedAt: new Date(raw.updated_at)
|
|
2578
|
+
});
|
|
2579
|
+
try {
|
|
2580
|
+
const base = baseVaultSql(ctx);
|
|
2581
|
+
const clauses = [base.sql];
|
|
2582
|
+
const args = [...base.args];
|
|
2583
|
+
if (options?.scopes?.length) {
|
|
2584
|
+
clauses.push(`"scope" in (${options.scopes.map(() => "?").join(",")})`);
|
|
2585
|
+
args.push(...options.scopes);
|
|
2586
|
+
}
|
|
2587
|
+
if (options?.folderId !== void 0) {
|
|
2588
|
+
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
2589
|
+
if (options.folderId !== null) args.push(options.folderId);
|
|
2590
|
+
}
|
|
2591
|
+
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
2592
|
+
const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
2593
|
+
return rows.map(mapRaw);
|
|
2594
|
+
} catch (err) {
|
|
2595
|
+
getLogger().debug(
|
|
2596
|
+
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
2597
|
+
);
|
|
2598
|
+
const conditions = [
|
|
2599
|
+
...baseVaultConditions(ctx),
|
|
2600
|
+
...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
|
|
2601
|
+
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : []
|
|
2602
|
+
];
|
|
2603
|
+
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2604
|
+
return rows.map(mapRaw);
|
|
2605
|
+
}
|
|
2606
|
+
}
|
|
2607
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
2608
|
+
if (ids.length === 0) return [];
|
|
2609
|
+
const mapRaw = (raw) => ({
|
|
2610
|
+
uniqueId: raw.id,
|
|
2611
|
+
embedding: raw.embedding ?? null,
|
|
2612
|
+
embeddingModel: raw.embedding_model ?? null
|
|
2613
|
+
});
|
|
2614
|
+
try {
|
|
2615
|
+
const base = baseVaultSql(ctx);
|
|
2616
|
+
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
2617
|
+
const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
2618
|
+
return rows.map(mapRaw);
|
|
2619
|
+
} catch (err) {
|
|
2620
|
+
getLogger().debug(
|
|
2621
|
+
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
2622
|
+
);
|
|
2623
|
+
const rows = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx), Q3.where("id", Q3.oneOf(ids))).unsafeFetchRaw();
|
|
2624
|
+
return rows.map(mapRaw);
|
|
2625
|
+
}
|
|
2626
|
+
}
|
|
2627
|
+
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
2628
|
+
if (ids.length === 0) return [];
|
|
2629
|
+
const conditions = [...baseVaultConditions(ctx), Q3.where("id", Q3.oneOf(ids))];
|
|
2630
|
+
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2631
|
+
return mapInBatches(
|
|
2632
|
+
results,
|
|
2633
|
+
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
2634
|
+
);
|
|
2635
|
+
}
|
|
2534
2636
|
async function getAllVaultMemoryContentsOp(ctx, options) {
|
|
2535
2637
|
const results = await ctx.vaultMemoryCollection.query(...baseVaultConditions(ctx, options)).unsafeFetchRaw();
|
|
2536
2638
|
return mapInBatches(results, async (raw) => {
|
|
@@ -5349,80 +5451,97 @@ async function eagerEmbedContent(content, embeddingOptions, cache, vaultCtx, mem
|
|
|
5349
5451
|
);
|
|
5350
5452
|
}
|
|
5351
5453
|
}
|
|
5352
|
-
|
|
5353
|
-
|
|
5354
|
-
|
|
5355
|
-
|
|
5356
|
-
|
|
5357
|
-
return { results: [], vaultSize: 0, reranked: false, hadV2Head: false };
|
|
5358
|
-
}
|
|
5359
|
-
const folderId = searchOptions?.folderId;
|
|
5360
|
-
const queryOpts = {};
|
|
5361
|
-
if (scopes?.length) queryOpts.scopes = scopes;
|
|
5362
|
-
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
5363
|
-
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
5364
|
-
if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
|
|
5365
|
-
const loaded = await getAllVaultMemoriesOp(
|
|
5454
|
+
function admitVaultProjections(queryEmbedding, vectored, k) {
|
|
5455
|
+
return vectored.map((it) => ({ it, score: cosineSimilarity(queryEmbedding, it.embedding) })).sort((a, b) => b.score - a.score || b.it.updatedAt.getTime() - a.it.updatedAt.getTime()).slice(0, k).map((s) => s.it.uniqueId);
|
|
5456
|
+
}
|
|
5457
|
+
async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, queryOpts, opts) {
|
|
5458
|
+
const keys = await getVaultCandidateKeysOp(
|
|
5366
5459
|
vaultCtx,
|
|
5367
5460
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
5368
5461
|
);
|
|
5369
|
-
const
|
|
5370
|
-
if (
|
|
5371
|
-
|
|
5372
|
-
`memoryVault: ${loaded.length - memories.length}/${loaded.length} memories still encrypted (key unavailable?) \u2014 excluded from search`
|
|
5373
|
-
);
|
|
5374
|
-
}
|
|
5375
|
-
if (memories.length === 0) {
|
|
5376
|
-
return { results: [], vaultSize: loaded.length, reranked: false, hadV2Head: false };
|
|
5462
|
+
const vaultSize = keys.length;
|
|
5463
|
+
if (keys.length === 0) {
|
|
5464
|
+
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
5377
5465
|
}
|
|
5378
5466
|
const queryEmbedding = await generateEmbedding(query, embeddingOptions);
|
|
5379
5467
|
const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
5380
|
-
const
|
|
5381
|
-
const
|
|
5382
|
-
|
|
5383
|
-
|
|
5384
|
-
|
|
5385
|
-
const
|
|
5386
|
-
|
|
5387
|
-
|
|
5388
|
-
|
|
5389
|
-
|
|
5390
|
-
const modelCompatible = (
|
|
5391
|
-
if (
|
|
5468
|
+
const vectored = [];
|
|
5469
|
+
const missIds = [];
|
|
5470
|
+
const noVectorIds = [];
|
|
5471
|
+
const keyById = new Map(keys.map((k2) => [k2.uniqueId, k2]));
|
|
5472
|
+
for (const k2 of keys) {
|
|
5473
|
+
const cached = cache.get(k2.uniqueId);
|
|
5474
|
+
if (cached && cached.length === queryEmbedding.length) {
|
|
5475
|
+
vectored.push({ uniqueId: k2.uniqueId, embedding: cached, updatedAt: k2.updatedAt });
|
|
5476
|
+
continue;
|
|
5477
|
+
}
|
|
5478
|
+
const modelCompatible = (k2.embeddingModel ?? currentModel) === currentModel;
|
|
5479
|
+
if (modelCompatible) missIds.push(k2.uniqueId);
|
|
5480
|
+
else noVectorIds.push(k2.uniqueId);
|
|
5481
|
+
}
|
|
5482
|
+
if (missIds.length > 0) {
|
|
5483
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
5484
|
+
const gotVector = /* @__PURE__ */ new Set();
|
|
5485
|
+
for (const r of rows) {
|
|
5486
|
+
if (!r.embedding) continue;
|
|
5392
5487
|
try {
|
|
5393
|
-
const parsed = JSON.parse(
|
|
5488
|
+
const parsed = JSON.parse(r.embedding);
|
|
5394
5489
|
if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
|
|
5395
|
-
|
|
5396
|
-
|
|
5490
|
+
const vec = Float32Array.from(parsed);
|
|
5491
|
+
cache.set(r.uniqueId, vec);
|
|
5492
|
+
const k2 = keyById.get(r.uniqueId);
|
|
5493
|
+
vectored.push({ uniqueId: r.uniqueId, embedding: vec, updatedAt: k2.updatedAt });
|
|
5494
|
+
gotVector.add(r.uniqueId);
|
|
5397
5495
|
}
|
|
5398
5496
|
} catch {
|
|
5399
5497
|
}
|
|
5400
5498
|
}
|
|
5401
|
-
|
|
5402
|
-
uncachedTexts.push(content);
|
|
5403
|
-
uncachedIndices.push(i);
|
|
5499
|
+
for (const id of missIds) if (!gotVector.has(id)) noVectorIds.push(id);
|
|
5404
5500
|
}
|
|
5405
|
-
if (
|
|
5406
|
-
|
|
5407
|
-
|
|
5501
|
+
if (noVectorIds.length > 0) {
|
|
5502
|
+
const laneIds = noVectorIds.slice(0, opts.unembeddedCap);
|
|
5503
|
+
if (noVectorIds.length > laneIds.length) {
|
|
5504
|
+
getLogger().warn(
|
|
5505
|
+
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
5506
|
+
);
|
|
5507
|
+
}
|
|
5508
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
5509
|
+
(m) => !isEncrypted(m.content)
|
|
5408
5510
|
);
|
|
5409
|
-
|
|
5410
|
-
|
|
5411
|
-
|
|
5412
|
-
|
|
5413
|
-
cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
|
|
5414
|
-
updateVaultMemoryEmbeddingOp(
|
|
5415
|
-
vaultCtx,
|
|
5416
|
-
memories[uncachedIndices[j]].uniqueId,
|
|
5417
|
-
JSON.stringify(newEmbeddings[j]),
|
|
5418
|
-
currentModel
|
|
5419
|
-
).catch(
|
|
5420
|
-
// Silently swallow – SDK must not use console.*; embedding will be retried on next search
|
|
5421
|
-
() => {
|
|
5422
|
-
}
|
|
5511
|
+
if (laneRows.length > 0) {
|
|
5512
|
+
const laneVecs = await generateEmbeddings(
|
|
5513
|
+
laneRows.map((m) => m.content),
|
|
5514
|
+
embeddingOptions
|
|
5423
5515
|
);
|
|
5516
|
+
laneRows.forEach((m, i) => {
|
|
5517
|
+
const vec = Float32Array.from(laneVecs[i]);
|
|
5518
|
+
cache.set(m.uniqueId, vec);
|
|
5519
|
+
vectored.push({ uniqueId: m.uniqueId, embedding: vec, updatedAt: m.updatedAt });
|
|
5520
|
+
updateVaultMemoryEmbeddingOp(
|
|
5521
|
+
vaultCtx,
|
|
5522
|
+
m.uniqueId,
|
|
5523
|
+
JSON.stringify(laneVecs[i]),
|
|
5524
|
+
currentModel
|
|
5525
|
+
).catch(() => {
|
|
5526
|
+
});
|
|
5527
|
+
});
|
|
5424
5528
|
}
|
|
5425
5529
|
}
|
|
5530
|
+
const k = Math.max(opts.limit * opts.admitFactor, opts.admitFloor);
|
|
5531
|
+
const admittedIds = admitVaultProjections(queryEmbedding, vectored, k);
|
|
5532
|
+
const admissionSet = new Set(admittedIds);
|
|
5533
|
+
if (opts.forceIncludeIds) {
|
|
5534
|
+
for (const id of opts.forceIncludeIds) {
|
|
5535
|
+
if (keyById.has(id)) admissionSet.add(id);
|
|
5536
|
+
}
|
|
5537
|
+
}
|
|
5538
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
5539
|
+
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
5540
|
+
if (memories.length < admittedRows.length) {
|
|
5541
|
+
getLogger().warn(
|
|
5542
|
+
`memoryVault: ${admittedRows.length - memories.length}/${admittedRows.length} admitted memories still encrypted (key unavailable?) \u2014 excluded from projected search`
|
|
5543
|
+
);
|
|
5544
|
+
}
|
|
5426
5545
|
const embeddedItems = memories.map((m) => ({
|
|
5427
5546
|
id: m.uniqueId,
|
|
5428
5547
|
content: m.content,
|
|
@@ -5437,6 +5556,125 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
5437
5556
|
eventTimeKind: normalizeEventTimeKind(m.eventTimeKind),
|
|
5438
5557
|
factType: m.factType
|
|
5439
5558
|
}));
|
|
5559
|
+
return { memories, embeddedItems, queryEmbedding, vaultSize };
|
|
5560
|
+
}
|
|
5561
|
+
async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, cache, searchOptions) {
|
|
5562
|
+
const limit = searchOptions?.limit ?? 5;
|
|
5563
|
+
const minSimilarity = searchOptions?.minSimilarity ?? 0.1;
|
|
5564
|
+
const scopes = searchOptions?.scopes;
|
|
5565
|
+
if (!query || typeof query !== "string") {
|
|
5566
|
+
return { results: [], vaultSize: 0, reranked: false, hadV2Head: false };
|
|
5567
|
+
}
|
|
5568
|
+
const folderId = searchOptions?.folderId;
|
|
5569
|
+
const queryOpts = {};
|
|
5570
|
+
if (scopes?.length) queryOpts.scopes = scopes;
|
|
5571
|
+
if (folderId !== void 0) queryOpts.folderId = folderId;
|
|
5572
|
+
if (searchOptions?.factTypes?.length) queryOpts.factTypes = searchOptions.factTypes;
|
|
5573
|
+
if (searchOptions?.includeArchived) queryOpts.includeArchived = true;
|
|
5574
|
+
const ADMIT_FACTOR = searchOptions?.admitFactor ?? 3;
|
|
5575
|
+
const ADMIT_FLOOR = searchOptions?.admitFloor ?? 30;
|
|
5576
|
+
const UNEMBEDDED_CAP = 200;
|
|
5577
|
+
let memories;
|
|
5578
|
+
let embeddedItems;
|
|
5579
|
+
let queryEmbedding;
|
|
5580
|
+
let vaultSize;
|
|
5581
|
+
if (searchOptions?.decryptLast) {
|
|
5582
|
+
const forceIncludeIds = [
|
|
5583
|
+
...searchOptions.entityRanking ?? [],
|
|
5584
|
+
...searchOptions.temporalRanking ?? []
|
|
5585
|
+
];
|
|
5586
|
+
const corpus = await buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, queryOpts, {
|
|
5587
|
+
limit,
|
|
5588
|
+
admitFactor: ADMIT_FACTOR,
|
|
5589
|
+
admitFloor: ADMIT_FLOOR,
|
|
5590
|
+
unembeddedCap: UNEMBEDDED_CAP,
|
|
5591
|
+
...forceIncludeIds.length > 0 && { forceIncludeIds }
|
|
5592
|
+
});
|
|
5593
|
+
if (corpus.vaultSize === 0) {
|
|
5594
|
+
return { results: [], vaultSize: 0, reranked: false, hadV2Head: false };
|
|
5595
|
+
}
|
|
5596
|
+
({ memories, embeddedItems, queryEmbedding, vaultSize } = corpus);
|
|
5597
|
+
if (memories.length === 0) {
|
|
5598
|
+
return { results: [], vaultSize, reranked: false, hadV2Head: false };
|
|
5599
|
+
}
|
|
5600
|
+
} else {
|
|
5601
|
+
const loaded = await getAllVaultMemoriesOp(
|
|
5602
|
+
vaultCtx,
|
|
5603
|
+
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
5604
|
+
);
|
|
5605
|
+
vaultSize = loaded.length;
|
|
5606
|
+
memories = loaded.filter((m) => !isEncrypted(m.content));
|
|
5607
|
+
if (memories.length < loaded.length) {
|
|
5608
|
+
getLogger().warn(
|
|
5609
|
+
`memoryVault: ${loaded.length - memories.length}/${loaded.length} memories still encrypted (key unavailable?) \u2014 excluded from search`
|
|
5610
|
+
);
|
|
5611
|
+
}
|
|
5612
|
+
if (memories.length === 0) {
|
|
5613
|
+
return { results: [], vaultSize: loaded.length, reranked: false, hadV2Head: false };
|
|
5614
|
+
}
|
|
5615
|
+
queryEmbedding = await generateEmbedding(query, embeddingOptions);
|
|
5616
|
+
const currentModel = embeddingOptions.model ?? DEFAULT_API_EMBEDDING_MODEL;
|
|
5617
|
+
const uncachedTexts = [];
|
|
5618
|
+
const uncachedIndices = [];
|
|
5619
|
+
let staleReembedCount = 0;
|
|
5620
|
+
for (let i = 0; i < memories.length; i++) {
|
|
5621
|
+
const content = memories[i].content;
|
|
5622
|
+
const memoryId = memories[i].uniqueId;
|
|
5623
|
+
const cached = cache.get(memoryId);
|
|
5624
|
+
if (cached && cached.length === queryEmbedding.length) continue;
|
|
5625
|
+
if (cached) cache.delete(memoryId);
|
|
5626
|
+
const storedModel = memories[i].embeddingModel;
|
|
5627
|
+
const modelCompatible = (storedModel ?? currentModel) === currentModel;
|
|
5628
|
+
if (memories[i].embedding && modelCompatible) {
|
|
5629
|
+
try {
|
|
5630
|
+
const parsed = JSON.parse(memories[i].embedding);
|
|
5631
|
+
if (Array.isArray(parsed) && parsed.length === queryEmbedding.length) {
|
|
5632
|
+
cache.set(memoryId, Float32Array.from(parsed));
|
|
5633
|
+
continue;
|
|
5634
|
+
}
|
|
5635
|
+
} catch {
|
|
5636
|
+
}
|
|
5637
|
+
}
|
|
5638
|
+
if (memories[i].embedding && !modelCompatible) staleReembedCount++;
|
|
5639
|
+
uncachedTexts.push(content);
|
|
5640
|
+
uncachedIndices.push(i);
|
|
5641
|
+
}
|
|
5642
|
+
if (staleReembedCount > 0) {
|
|
5643
|
+
getLogger().warn(
|
|
5644
|
+
`memoryVault: re-embedding ${staleReembedCount} memories whose stored embedding model differs from the current model (${currentModel}) \u2014 embedding-model change detected`
|
|
5645
|
+
);
|
|
5646
|
+
}
|
|
5647
|
+
if (uncachedTexts.length > 0) {
|
|
5648
|
+
const newEmbeddings = await generateEmbeddings(uncachedTexts, embeddingOptions);
|
|
5649
|
+
for (let j = 0; j < uncachedTexts.length; j++) {
|
|
5650
|
+
cache.set(memories[uncachedIndices[j]].uniqueId, Float32Array.from(newEmbeddings[j]));
|
|
5651
|
+
updateVaultMemoryEmbeddingOp(
|
|
5652
|
+
vaultCtx,
|
|
5653
|
+
memories[uncachedIndices[j]].uniqueId,
|
|
5654
|
+
JSON.stringify(newEmbeddings[j]),
|
|
5655
|
+
currentModel
|
|
5656
|
+
).catch(
|
|
5657
|
+
// Silently swallow – SDK must not use console.*; embedding will be retried on next search
|
|
5658
|
+
() => {
|
|
5659
|
+
}
|
|
5660
|
+
);
|
|
5661
|
+
}
|
|
5662
|
+
}
|
|
5663
|
+
embeddedItems = memories.map((m) => ({
|
|
5664
|
+
id: m.uniqueId,
|
|
5665
|
+
content: m.content,
|
|
5666
|
+
embedding: cache.get(m.uniqueId) ?? [],
|
|
5667
|
+
createdAt: m.createdAt,
|
|
5668
|
+
updatedAt: m.updatedAt,
|
|
5669
|
+
proofCount: m.proofCount,
|
|
5670
|
+
lastObservedAt: m.lastObservedAt,
|
|
5671
|
+
eventTimeStart: m.eventTimeStart,
|
|
5672
|
+
sourceChunkIds: m.sourceChunkIds,
|
|
5673
|
+
eventTimeEnd: m.eventTimeEnd,
|
|
5674
|
+
eventTimeKind: normalizeEventTimeKind(m.eventTimeKind),
|
|
5675
|
+
factType: m.factType
|
|
5676
|
+
}));
|
|
5677
|
+
}
|
|
5440
5678
|
if (queryEmbedding.length > 0) {
|
|
5441
5679
|
const mismatched = embeddedItems.filter(
|
|
5442
5680
|
(it) => it.embedding.length > 0 && it.embedding.length !== queryEmbedding.length
|
|
@@ -5522,7 +5760,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
5522
5760
|
});
|
|
5523
5761
|
return stampTimestamps({
|
|
5524
5762
|
results: composite,
|
|
5525
|
-
vaultSize
|
|
5763
|
+
vaultSize,
|
|
5526
5764
|
reranked: rerankStats.applied,
|
|
5527
5765
|
hadV2Head: v2HeadStats.hadResults
|
|
5528
5766
|
});
|
|
@@ -5547,7 +5785,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
5547
5785
|
});
|
|
5548
5786
|
return stampTimestamps({
|
|
5549
5787
|
results: results2,
|
|
5550
|
-
vaultSize
|
|
5788
|
+
vaultSize,
|
|
5551
5789
|
reranked: rerankStats.applied,
|
|
5552
5790
|
hadV2Head: v2HeadStats.hadResults
|
|
5553
5791
|
});
|
|
@@ -5560,7 +5798,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
5560
5798
|
...searchOptions?.entityRanking && { entityRanking: searchOptions.entityRanking },
|
|
5561
5799
|
...searchOptions?.temporalRanking && { temporalRanking: searchOptions.temporalRanking }
|
|
5562
5800
|
});
|
|
5563
|
-
return stampTimestamps({ results: results2, vaultSize
|
|
5801
|
+
return stampTimestamps({ results: results2, vaultSize, hadV2Head: results2.length > 0 });
|
|
5564
5802
|
}
|
|
5565
5803
|
const results = rankVaultMemories(query, queryEmbedding, embeddedItems, {
|
|
5566
5804
|
limit,
|
|
@@ -5572,7 +5810,7 @@ async function searchVaultMemoriesWithSize(query, vaultCtx, embeddingOptions, ca
|
|
|
5572
5810
|
supersessionWindow: searchOptions.supersessionWindow
|
|
5573
5811
|
}
|
|
5574
5812
|
});
|
|
5575
|
-
return stampTimestamps({ results, vaultSize
|
|
5813
|
+
return stampTimestamps({ results, vaultSize, hadV2Head: results.length > 0 });
|
|
5576
5814
|
}
|
|
5577
5815
|
async function searchVaultMemories(query, vaultCtx, embeddingOptions, cache, searchOptions) {
|
|
5578
5816
|
const { results } = await searchVaultMemoriesWithSize(
|
|
@@ -5661,7 +5899,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
5661
5899
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
5662
5900
|
);
|
|
5663
5901
|
}
|
|
5664
|
-
const { recall: recall2 } = await import("./recall-
|
|
5902
|
+
const { recall: recall2 } = await import("./recall-SBQ4LNRJ.mjs");
|
|
5665
5903
|
const result = await recall2(
|
|
5666
5904
|
query,
|
|
5667
5905
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -6308,6 +6546,7 @@ async function recall(query, ctx, options = {}) {
|
|
|
6308
6546
|
bm25AdmissionDivisor: options.bm25AdmissionDivisor
|
|
6309
6547
|
},
|
|
6310
6548
|
...options.rrfK !== void 0 && { rrfK: options.rrfK },
|
|
6549
|
+
...options.decryptLast !== void 0 && { decryptLast: options.decryptLast },
|
|
6311
6550
|
...decomposeAvailable && {
|
|
6312
6551
|
decompose: "llm",
|
|
6313
6552
|
decomposeOptions: options.decomposeOptions
|
|
@@ -6649,6 +6888,10 @@ export {
|
|
|
6649
6888
|
createVaultMemoriesBatchOp,
|
|
6650
6889
|
getVaultMemoryOp,
|
|
6651
6890
|
getAllVaultMemoriesOp,
|
|
6891
|
+
getVaultRankingProjectionsOp,
|
|
6892
|
+
getVaultCandidateKeysOp,
|
|
6893
|
+
getVaultEmbeddingsByIdsOp,
|
|
6894
|
+
getVaultMemoriesByIdsOp,
|
|
6652
6895
|
getAllVaultMemoryContentsOp,
|
|
6653
6896
|
updateVaultMemoryOp,
|
|
6654
6897
|
setMemoryEntitiesOp,
|