@anuma/sdk 3.9.2 → 3.9.4
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-YFJAHJMB.mjs → chunk-4VXLX7SL.mjs} +71 -15
- package/dist/expo/index.cjs +71 -15
- package/dist/expo/index.mjs +1 -1
- package/dist/expo/{recall-KWTVD4IR.mjs → recall-XGRLGIEH.mjs} +1 -1
- package/dist/react/{chunk-GDS7GHBF.mjs → chunk-P5ED24DP.mjs} +71 -15
- package/dist/react/index.cjs +71 -15
- package/dist/react/index.d.mts +25 -2
- package/dist/react/index.d.ts +25 -2
- package/dist/react/index.mjs +1 -1
- package/dist/react/{recall-SBQ4LNRJ.mjs → recall-F33QYRYU.mjs} +1 -1
- package/dist/server/{chunk-QC4WHNIJ.mjs → chunk-FJFPCJRI.mjs} +71 -15
- package/dist/server/index.cjs +71 -15
- package/dist/server/index.mjs +1 -1
- package/dist/server/{recall-NLJNELJY.mjs → recall-23VTTAEG.mjs} +1 -1
- package/package.json +1 -1
|
@@ -2381,10 +2381,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
2381
2381
|
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
2382
2382
|
);
|
|
2383
2383
|
}
|
|
2384
|
-
function baseVaultSql(ctx) {
|
|
2384
|
+
function baseVaultSql(ctx, options) {
|
|
2385
2385
|
const clauses = [
|
|
2386
2386
|
'"is_deleted" = 0',
|
|
2387
|
-
'
|
|
2387
|
+
// Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
|
|
2388
|
+
// excluding archived rows, so every existing caller is unchanged.
|
|
2389
|
+
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
2388
2390
|
`"trust_tier" is not 'quarantined'`,
|
|
2389
2391
|
'"superseded_by" is null'
|
|
2390
2392
|
];
|
|
@@ -2404,7 +2406,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
2404
2406
|
updatedAt: new Date(raw.updated_at)
|
|
2405
2407
|
});
|
|
2406
2408
|
try {
|
|
2407
|
-
const base = baseVaultSql(ctx
|
|
2409
|
+
const base = baseVaultSql(ctx, {
|
|
2410
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2411
|
+
});
|
|
2408
2412
|
const clauses = [base.sql];
|
|
2409
2413
|
const args = [...base.args];
|
|
2410
2414
|
if (options?.scopes?.length) {
|
|
@@ -2415,6 +2419,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
2415
2419
|
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
2416
2420
|
if (options.folderId !== null) args.push(options.folderId);
|
|
2417
2421
|
}
|
|
2422
|
+
if (options?.factTypes?.length) {
|
|
2423
|
+
clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
|
|
2424
|
+
args.push(...options.factTypes);
|
|
2425
|
+
}
|
|
2418
2426
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
2419
2427
|
const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
2420
2428
|
return rows.map(mapRaw);
|
|
@@ -2423,15 +2431,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
2423
2431
|
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
2424
2432
|
);
|
|
2425
2433
|
const conditions = [
|
|
2426
|
-
...baseVaultConditions(ctx
|
|
2434
|
+
...baseVaultConditions(ctx, {
|
|
2435
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2436
|
+
}),
|
|
2427
2437
|
...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
|
|
2428
|
-
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : []
|
|
2438
|
+
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
|
|
2439
|
+
...options?.factTypes?.length ? [Q3.where("fact_type", Q3.oneOf(options.factTypes))] : []
|
|
2429
2440
|
];
|
|
2430
2441
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2431
2442
|
return rows.map(mapRaw);
|
|
2432
2443
|
}
|
|
2433
2444
|
}
|
|
2434
|
-
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
2445
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
2435
2446
|
if (ids.length === 0) return [];
|
|
2436
2447
|
const mapRaw = (raw) => ({
|
|
2437
2448
|
uniqueId: raw.id,
|
|
@@ -2439,7 +2450,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
2439
2450
|
embeddingModel: raw.embedding_model ?? null
|
|
2440
2451
|
});
|
|
2441
2452
|
try {
|
|
2442
|
-
const base = baseVaultSql(ctx
|
|
2453
|
+
const base = baseVaultSql(ctx, {
|
|
2454
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2455
|
+
});
|
|
2443
2456
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
2444
2457
|
const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
2445
2458
|
return rows.map(mapRaw);
|
|
@@ -2447,13 +2460,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
2447
2460
|
getLogger().debug(
|
|
2448
2461
|
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
2449
2462
|
);
|
|
2450
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
2463
|
+
const rows = await ctx.vaultMemoryCollection.query(
|
|
2464
|
+
...baseVaultConditions(ctx, {
|
|
2465
|
+
...options?.includeArchived !== void 0 && {
|
|
2466
|
+
includeArchived: options.includeArchived
|
|
2467
|
+
}
|
|
2468
|
+
}),
|
|
2469
|
+
Q3.where("id", Q3.oneOf(ids))
|
|
2470
|
+
).unsafeFetchRaw();
|
|
2451
2471
|
return rows.map(mapRaw);
|
|
2452
2472
|
}
|
|
2453
2473
|
}
|
|
2454
|
-
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
2474
|
+
async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
2455
2475
|
if (ids.length === 0) return [];
|
|
2456
|
-
const conditions = [
|
|
2476
|
+
const conditions = [
|
|
2477
|
+
...baseVaultConditions(ctx, {
|
|
2478
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2479
|
+
}),
|
|
2480
|
+
Q3.where("id", Q3.oneOf(ids))
|
|
2481
|
+
];
|
|
2457
2482
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2458
2483
|
return mapInBatches(
|
|
2459
2484
|
results,
|
|
@@ -5158,6 +5183,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5158
5183
|
vaultCtx,
|
|
5159
5184
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
5160
5185
|
);
|
|
5186
|
+
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
5161
5187
|
const vaultSize = keys.length;
|
|
5162
5188
|
if (keys.length === 0) {
|
|
5163
5189
|
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
@@ -5179,7 +5205,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5179
5205
|
else noVectorIds.push(k2.uniqueId);
|
|
5180
5206
|
}
|
|
5181
5207
|
if (missIds.length > 0) {
|
|
5182
|
-
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
5208
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
5183
5209
|
const gotVector = /* @__PURE__ */ new Set();
|
|
5184
5210
|
for (const r of rows) {
|
|
5185
5211
|
if (!r.embedding) continue;
|
|
@@ -5204,7 +5230,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5204
5230
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
5205
5231
|
);
|
|
5206
5232
|
}
|
|
5207
|
-
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
5233
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
|
|
5208
5234
|
(m) => !isEncrypted(m.content)
|
|
5209
5235
|
);
|
|
5210
5236
|
if (laneRows.length > 0) {
|
|
@@ -5234,7 +5260,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5234
5260
|
if (keyById.has(id)) admissionSet.add(id);
|
|
5235
5261
|
}
|
|
5236
5262
|
}
|
|
5237
|
-
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
5263
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
|
|
5238
5264
|
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
5239
5265
|
if (memories.length < admittedRows.length) {
|
|
5240
5266
|
getLogger().warn(
|
|
@@ -5598,7 +5624,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
5598
5624
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
5599
5625
|
);
|
|
5600
5626
|
}
|
|
5601
|
-
const { recall: recall2 } = await import("./recall-
|
|
5627
|
+
const { recall: recall2 } = await import("./recall-XGRLGIEH.mjs");
|
|
5602
5628
|
const result = await recall2(
|
|
5603
5629
|
query,
|
|
5604
5630
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -5691,6 +5717,18 @@ var STOPWORDS2 = new Set(
|
|
|
5691
5717
|
].map((w) => w.toLowerCase())
|
|
5692
5718
|
);
|
|
5693
5719
|
var ENTITY_REGEX = /\b\p{Lu}[\p{L}'-]{2,}(?:\s+\p{Lu}[\p{L}'-]+){0,2}\b/gu;
|
|
5720
|
+
var FALLBACK_ONLY_STOPWORDS = "a an and or but nor not if then than because so too also just very really about above after again against all am any anyone anybody anything are around as at be been being before behind below between both by can cannot could currently did do does doing done down during each ever every everybody everyone everything few find finds finding for from get gets getting go goes going gone got had has have having he help her here hers him his hmm i in into is it its knew know knows later like liked likes live lived lives living look looked looking looks made make makes may me meet meets might mine more most must my near need needed needs never nobody nothing now of off okay on once only onto other our ours out over own people person please recently said same say says see seen shall she should since some somebody someone something soon still such talk tell tells thank that the their theirs them there these they think thinks this those thought through to today told tomorrow under until up us want wanted wants was we went were which while will with without work worked working works would yeah year years yep yesterday you your yours aren't can't couldn't didn't doesn't don't hadn't hasn't haven't he's how's i'd i'll i'm i've isn't it's let's she's shouldn't that's there's they're they've wasn't we're we've weren't what's when's where's who's why's won't wouldn't you'll you're you've".split(" ");
|
|
5721
|
+
var FALLBACK_STOPWORDS = /* @__PURE__ */ new Set([...STOPWORDS2, ...FALLBACK_ONLY_STOPWORDS]);
|
|
5722
|
+
var MAX_FALLBACK_CANDIDATES = 12;
|
|
5723
|
+
var MAX_FALLBACK_TOKENS = 3;
|
|
5724
|
+
function hasMeaningfulCandidate(candidates) {
|
|
5725
|
+
for (const candidate of candidates) {
|
|
5726
|
+
if (!candidate.split(/\s+/).every((token) => FALLBACK_STOPWORDS.has(token))) {
|
|
5727
|
+
return true;
|
|
5728
|
+
}
|
|
5729
|
+
}
|
|
5730
|
+
return false;
|
|
5731
|
+
}
|
|
5694
5732
|
function extractQueryEntities(query) {
|
|
5695
5733
|
if (!query) return [];
|
|
5696
5734
|
const matches = query.matchAll(ENTITY_REGEX);
|
|
@@ -5706,7 +5744,25 @@ function extractQueryEntities(query) {
|
|
|
5706
5744
|
seen.add(candidate);
|
|
5707
5745
|
}
|
|
5708
5746
|
}
|
|
5709
|
-
return [...seen];
|
|
5747
|
+
if (hasMeaningfulCandidate(seen)) return [...seen];
|
|
5748
|
+
return [.../* @__PURE__ */ new Set([...extractFallbackCandidates(query), ...seen])];
|
|
5749
|
+
}
|
|
5750
|
+
function extractFallbackCandidates(query) {
|
|
5751
|
+
const tokens = (query.match(/\p{L}[\p{L}'-]*/gu) ?? []).map(normalizeEntityName);
|
|
5752
|
+
const out = [];
|
|
5753
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5754
|
+
for (let n = 1; n <= MAX_FALLBACK_TOKENS; n++) {
|
|
5755
|
+
for (let start = 0; start + n <= tokens.length; start++) {
|
|
5756
|
+
const gram = tokens.slice(start, start + n);
|
|
5757
|
+
if (gram.some((t) => t.length < 2 || FALLBACK_STOPWORDS.has(t))) continue;
|
|
5758
|
+
const candidate = gram.join(" ");
|
|
5759
|
+
if (seen.has(candidate)) continue;
|
|
5760
|
+
seen.add(candidate);
|
|
5761
|
+
out.push(candidate);
|
|
5762
|
+
if (out.length >= MAX_FALLBACK_CANDIDATES) return out;
|
|
5763
|
+
}
|
|
5764
|
+
}
|
|
5765
|
+
return out;
|
|
5710
5766
|
}
|
|
5711
5767
|
|
|
5712
5768
|
// src/lib/memory/graphTraversal.ts
|
package/dist/expo/index.cjs
CHANGED
|
@@ -4622,10 +4622,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
4622
4622
|
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
4623
4623
|
);
|
|
4624
4624
|
}
|
|
4625
|
-
function baseVaultSql(ctx) {
|
|
4625
|
+
function baseVaultSql(ctx, options) {
|
|
4626
4626
|
const clauses = [
|
|
4627
4627
|
'"is_deleted" = 0',
|
|
4628
|
-
'
|
|
4628
|
+
// Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
|
|
4629
|
+
// excluding archived rows, so every existing caller is unchanged.
|
|
4630
|
+
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
4629
4631
|
`"trust_tier" is not 'quarantined'`,
|
|
4630
4632
|
'"superseded_by" is null'
|
|
4631
4633
|
];
|
|
@@ -4645,7 +4647,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
4645
4647
|
updatedAt: new Date(raw.updated_at)
|
|
4646
4648
|
});
|
|
4647
4649
|
try {
|
|
4648
|
-
const base = baseVaultSql(ctx
|
|
4650
|
+
const base = baseVaultSql(ctx, {
|
|
4651
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4652
|
+
});
|
|
4649
4653
|
const clauses = [base.sql];
|
|
4650
4654
|
const args = [...base.args];
|
|
4651
4655
|
if (options?.scopes?.length) {
|
|
@@ -4656,6 +4660,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
4656
4660
|
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
4657
4661
|
if (options.folderId !== null) args.push(options.folderId);
|
|
4658
4662
|
}
|
|
4663
|
+
if (options?.factTypes?.length) {
|
|
4664
|
+
clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
|
|
4665
|
+
args.push(...options.factTypes);
|
|
4666
|
+
}
|
|
4659
4667
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
4660
4668
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb9.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
4661
4669
|
return rows.map(mapRaw);
|
|
@@ -4664,15 +4672,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
4664
4672
|
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
4665
4673
|
);
|
|
4666
4674
|
const conditions = [
|
|
4667
|
-
...baseVaultConditions(ctx
|
|
4675
|
+
...baseVaultConditions(ctx, {
|
|
4676
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4677
|
+
}),
|
|
4668
4678
|
...options?.scopes?.length ? [import_watermelondb9.Q.where("scope", import_watermelondb9.Q.oneOf(options.scopes))] : [],
|
|
4669
|
-
...options?.folderId !== void 0 ? [import_watermelondb9.Q.where("folder_id", options.folderId)] : []
|
|
4679
|
+
...options?.folderId !== void 0 ? [import_watermelondb9.Q.where("folder_id", options.folderId)] : [],
|
|
4680
|
+
...options?.factTypes?.length ? [import_watermelondb9.Q.where("fact_type", import_watermelondb9.Q.oneOf(options.factTypes))] : []
|
|
4670
4681
|
];
|
|
4671
4682
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
4672
4683
|
return rows.map(mapRaw);
|
|
4673
4684
|
}
|
|
4674
4685
|
}
|
|
4675
|
-
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
4686
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
4676
4687
|
if (ids.length === 0) return [];
|
|
4677
4688
|
const mapRaw = (raw) => ({
|
|
4678
4689
|
uniqueId: raw.id,
|
|
@@ -4680,7 +4691,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
4680
4691
|
embeddingModel: raw.embedding_model ?? null
|
|
4681
4692
|
});
|
|
4682
4693
|
try {
|
|
4683
|
-
const base = baseVaultSql(ctx
|
|
4694
|
+
const base = baseVaultSql(ctx, {
|
|
4695
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4696
|
+
});
|
|
4684
4697
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
4685
4698
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb9.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
4686
4699
|
return rows.map(mapRaw);
|
|
@@ -4688,13 +4701,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
4688
4701
|
getLogger().debug(
|
|
4689
4702
|
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
4690
4703
|
);
|
|
4691
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
4704
|
+
const rows = await ctx.vaultMemoryCollection.query(
|
|
4705
|
+
...baseVaultConditions(ctx, {
|
|
4706
|
+
...options?.includeArchived !== void 0 && {
|
|
4707
|
+
includeArchived: options.includeArchived
|
|
4708
|
+
}
|
|
4709
|
+
}),
|
|
4710
|
+
import_watermelondb9.Q.where("id", import_watermelondb9.Q.oneOf(ids))
|
|
4711
|
+
).unsafeFetchRaw();
|
|
4692
4712
|
return rows.map(mapRaw);
|
|
4693
4713
|
}
|
|
4694
4714
|
}
|
|
4695
|
-
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
4715
|
+
async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
4696
4716
|
if (ids.length === 0) return [];
|
|
4697
|
-
const conditions = [
|
|
4717
|
+
const conditions = [
|
|
4718
|
+
...baseVaultConditions(ctx, {
|
|
4719
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4720
|
+
}),
|
|
4721
|
+
import_watermelondb9.Q.where("id", import_watermelondb9.Q.oneOf(ids))
|
|
4722
|
+
];
|
|
4698
4723
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
4699
4724
|
return mapInBatches(
|
|
4700
4725
|
results,
|
|
@@ -5855,6 +5880,14 @@ var init_lruCache = __esm({
|
|
|
5855
5880
|
});
|
|
5856
5881
|
|
|
5857
5882
|
// src/lib/memory/queryEntities.ts
|
|
5883
|
+
function hasMeaningfulCandidate(candidates) {
|
|
5884
|
+
for (const candidate of candidates) {
|
|
5885
|
+
if (!candidate.split(/\s+/).every((token) => FALLBACK_STOPWORDS.has(token))) {
|
|
5886
|
+
return true;
|
|
5887
|
+
}
|
|
5888
|
+
}
|
|
5889
|
+
return false;
|
|
5890
|
+
}
|
|
5858
5891
|
function extractQueryEntities(query) {
|
|
5859
5892
|
if (!query) return [];
|
|
5860
5893
|
const matches = query.matchAll(ENTITY_REGEX);
|
|
@@ -5870,9 +5903,27 @@ function extractQueryEntities(query) {
|
|
|
5870
5903
|
seen.add(candidate);
|
|
5871
5904
|
}
|
|
5872
5905
|
}
|
|
5873
|
-
return [...seen];
|
|
5906
|
+
if (hasMeaningfulCandidate(seen)) return [...seen];
|
|
5907
|
+
return [.../* @__PURE__ */ new Set([...extractFallbackCandidates(query), ...seen])];
|
|
5908
|
+
}
|
|
5909
|
+
function extractFallbackCandidates(query) {
|
|
5910
|
+
const tokens = (query.match(/\p{L}[\p{L}'-]*/gu) ?? []).map(normalizeEntityName);
|
|
5911
|
+
const out = [];
|
|
5912
|
+
const seen = /* @__PURE__ */ new Set();
|
|
5913
|
+
for (let n = 1; n <= MAX_FALLBACK_TOKENS; n++) {
|
|
5914
|
+
for (let start = 0; start + n <= tokens.length; start++) {
|
|
5915
|
+
const gram = tokens.slice(start, start + n);
|
|
5916
|
+
if (gram.some((t) => t.length < 2 || FALLBACK_STOPWORDS.has(t))) continue;
|
|
5917
|
+
const candidate = gram.join(" ");
|
|
5918
|
+
if (seen.has(candidate)) continue;
|
|
5919
|
+
seen.add(candidate);
|
|
5920
|
+
out.push(candidate);
|
|
5921
|
+
if (out.length >= MAX_FALLBACK_CANDIDATES) return out;
|
|
5922
|
+
}
|
|
5923
|
+
}
|
|
5924
|
+
return out;
|
|
5874
5925
|
}
|
|
5875
|
-
var STOPWORDS2, ENTITY_REGEX;
|
|
5926
|
+
var STOPWORDS2, ENTITY_REGEX, FALLBACK_ONLY_STOPWORDS, FALLBACK_STOPWORDS, MAX_FALLBACK_CANDIDATES, MAX_FALLBACK_TOKENS;
|
|
5876
5927
|
var init_queryEntities = __esm({
|
|
5877
5928
|
"src/lib/memory/queryEntities.ts"() {
|
|
5878
5929
|
"use strict";
|
|
@@ -5924,6 +5975,10 @@ var init_queryEntities = __esm({
|
|
|
5924
5975
|
].map((w) => w.toLowerCase())
|
|
5925
5976
|
);
|
|
5926
5977
|
ENTITY_REGEX = /\b\p{Lu}[\p{L}'-]{2,}(?:\s+\p{Lu}[\p{L}'-]+){0,2}\b/gu;
|
|
5978
|
+
FALLBACK_ONLY_STOPWORDS = "a an and or but nor not if then than because so too also just very really about above after again against all am any anyone anybody anything are around as at be been being before behind below between both by can cannot could currently did do does doing done down during each ever every everybody everyone everything few find finds finding for from get gets getting go goes going gone got had has have having he help her here hers him his hmm i in into is it its knew know knows later like liked likes live lived lives living look looked looking looks made make makes may me meet meets might mine more most must my near need needed needs never nobody nothing now of off okay on once only onto other our ours out over own people person please recently said same say says see seen shall she should since some somebody someone something soon still such talk tell tells thank that the their theirs them there these they think thinks this those thought through to today told tomorrow under until up us want wanted wants was we went were which while will with without work worked working works would yeah year years yep yesterday you your yours aren't can't couldn't didn't doesn't don't hadn't hasn't haven't he's how's i'd i'll i'm i've isn't it's let's she's shouldn't that's there's they're they've wasn't we're we've weren't what's when's where's who's why's won't wouldn't you'll you're you've".split(" ");
|
|
5979
|
+
FALLBACK_STOPWORDS = /* @__PURE__ */ new Set([...STOPWORDS2, ...FALLBACK_ONLY_STOPWORDS]);
|
|
5980
|
+
MAX_FALLBACK_CANDIDATES = 12;
|
|
5981
|
+
MAX_FALLBACK_TOKENS = 3;
|
|
5927
5982
|
}
|
|
5928
5983
|
});
|
|
5929
5984
|
|
|
@@ -7277,6 +7332,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7277
7332
|
vaultCtx,
|
|
7278
7333
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
7279
7334
|
);
|
|
7335
|
+
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
7280
7336
|
const vaultSize = keys.length;
|
|
7281
7337
|
if (keys.length === 0) {
|
|
7282
7338
|
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
@@ -7298,7 +7354,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7298
7354
|
else noVectorIds.push(k2.uniqueId);
|
|
7299
7355
|
}
|
|
7300
7356
|
if (missIds.length > 0) {
|
|
7301
|
-
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
7357
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
7302
7358
|
const gotVector = /* @__PURE__ */ new Set();
|
|
7303
7359
|
for (const r of rows) {
|
|
7304
7360
|
if (!r.embedding) continue;
|
|
@@ -7323,7 +7379,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7323
7379
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
7324
7380
|
);
|
|
7325
7381
|
}
|
|
7326
|
-
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
7382
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
|
|
7327
7383
|
(m) => !isEncrypted(m.content)
|
|
7328
7384
|
);
|
|
7329
7385
|
if (laneRows.length > 0) {
|
|
@@ -7353,7 +7409,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7353
7409
|
if (keyById.has(id)) admissionSet.add(id);
|
|
7354
7410
|
}
|
|
7355
7411
|
}
|
|
7356
|
-
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
7412
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
|
|
7357
7413
|
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
7358
7414
|
if (memories.length < admittedRows.length) {
|
|
7359
7415
|
getLogger().warn(
|
package/dist/expo/index.mjs
CHANGED
|
@@ -2554,10 +2554,12 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
2554
2554
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2555
2555
|
return results.map(vaultMemoryRawToRankable);
|
|
2556
2556
|
}
|
|
2557
|
-
function baseVaultSql(ctx) {
|
|
2557
|
+
function baseVaultSql(ctx, options) {
|
|
2558
2558
|
const clauses = [
|
|
2559
2559
|
'"is_deleted" = 0',
|
|
2560
|
-
'
|
|
2560
|
+
// Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
|
|
2561
|
+
// excluding archived rows, so every existing caller is unchanged.
|
|
2562
|
+
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
2561
2563
|
`"trust_tier" is not 'quarantined'`,
|
|
2562
2564
|
'"superseded_by" is null'
|
|
2563
2565
|
];
|
|
@@ -2577,7 +2579,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
2577
2579
|
updatedAt: new Date(raw.updated_at)
|
|
2578
2580
|
});
|
|
2579
2581
|
try {
|
|
2580
|
-
const base = baseVaultSql(ctx
|
|
2582
|
+
const base = baseVaultSql(ctx, {
|
|
2583
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2584
|
+
});
|
|
2581
2585
|
const clauses = [base.sql];
|
|
2582
2586
|
const args = [...base.args];
|
|
2583
2587
|
if (options?.scopes?.length) {
|
|
@@ -2588,6 +2592,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
2588
2592
|
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
2589
2593
|
if (options.folderId !== null) args.push(options.folderId);
|
|
2590
2594
|
}
|
|
2595
|
+
if (options?.factTypes?.length) {
|
|
2596
|
+
clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
|
|
2597
|
+
args.push(...options.factTypes);
|
|
2598
|
+
}
|
|
2591
2599
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
2592
2600
|
const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
2593
2601
|
return rows.map(mapRaw);
|
|
@@ -2596,15 +2604,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
2596
2604
|
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
2597
2605
|
);
|
|
2598
2606
|
const conditions = [
|
|
2599
|
-
...baseVaultConditions(ctx
|
|
2607
|
+
...baseVaultConditions(ctx, {
|
|
2608
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2609
|
+
}),
|
|
2600
2610
|
...options?.scopes?.length ? [Q3.where("scope", Q3.oneOf(options.scopes))] : [],
|
|
2601
|
-
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : []
|
|
2611
|
+
...options?.folderId !== void 0 ? [Q3.where("folder_id", options.folderId)] : [],
|
|
2612
|
+
...options?.factTypes?.length ? [Q3.where("fact_type", Q3.oneOf(options.factTypes))] : []
|
|
2602
2613
|
];
|
|
2603
2614
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2604
2615
|
return rows.map(mapRaw);
|
|
2605
2616
|
}
|
|
2606
2617
|
}
|
|
2607
|
-
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
2618
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
2608
2619
|
if (ids.length === 0) return [];
|
|
2609
2620
|
const mapRaw = (raw) => ({
|
|
2610
2621
|
uniqueId: raw.id,
|
|
@@ -2612,7 +2623,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
2612
2623
|
embeddingModel: raw.embedding_model ?? null
|
|
2613
2624
|
});
|
|
2614
2625
|
try {
|
|
2615
|
-
const base = baseVaultSql(ctx
|
|
2626
|
+
const base = baseVaultSql(ctx, {
|
|
2627
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2628
|
+
});
|
|
2616
2629
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
2617
2630
|
const rows = await ctx.vaultMemoryCollection.query(Q3.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
2618
2631
|
return rows.map(mapRaw);
|
|
@@ -2620,13 +2633,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
2620
2633
|
getLogger().debug(
|
|
2621
2634
|
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
2622
2635
|
);
|
|
2623
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
2636
|
+
const rows = await ctx.vaultMemoryCollection.query(
|
|
2637
|
+
...baseVaultConditions(ctx, {
|
|
2638
|
+
...options?.includeArchived !== void 0 && {
|
|
2639
|
+
includeArchived: options.includeArchived
|
|
2640
|
+
}
|
|
2641
|
+
}),
|
|
2642
|
+
Q3.where("id", Q3.oneOf(ids))
|
|
2643
|
+
).unsafeFetchRaw();
|
|
2624
2644
|
return rows.map(mapRaw);
|
|
2625
2645
|
}
|
|
2626
2646
|
}
|
|
2627
|
-
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
2647
|
+
async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
2628
2648
|
if (ids.length === 0) return [];
|
|
2629
|
-
const conditions = [
|
|
2649
|
+
const conditions = [
|
|
2650
|
+
...baseVaultConditions(ctx, {
|
|
2651
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
2652
|
+
}),
|
|
2653
|
+
Q3.where("id", Q3.oneOf(ids))
|
|
2654
|
+
];
|
|
2630
2655
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
2631
2656
|
return mapInBatches(
|
|
2632
2657
|
results,
|
|
@@ -5459,6 +5484,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5459
5484
|
vaultCtx,
|
|
5460
5485
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
5461
5486
|
);
|
|
5487
|
+
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
5462
5488
|
const vaultSize = keys.length;
|
|
5463
5489
|
if (keys.length === 0) {
|
|
5464
5490
|
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
@@ -5480,7 +5506,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5480
5506
|
else noVectorIds.push(k2.uniqueId);
|
|
5481
5507
|
}
|
|
5482
5508
|
if (missIds.length > 0) {
|
|
5483
|
-
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
5509
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
5484
5510
|
const gotVector = /* @__PURE__ */ new Set();
|
|
5485
5511
|
for (const r of rows) {
|
|
5486
5512
|
if (!r.embedding) continue;
|
|
@@ -5505,7 +5531,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5505
5531
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
5506
5532
|
);
|
|
5507
5533
|
}
|
|
5508
|
-
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
5534
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
|
|
5509
5535
|
(m) => !isEncrypted(m.content)
|
|
5510
5536
|
);
|
|
5511
5537
|
if (laneRows.length > 0) {
|
|
@@ -5535,7 +5561,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
5535
5561
|
if (keyById.has(id)) admissionSet.add(id);
|
|
5536
5562
|
}
|
|
5537
5563
|
}
|
|
5538
|
-
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
5564
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
|
|
5539
5565
|
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
5540
5566
|
if (memories.length < admittedRows.length) {
|
|
5541
5567
|
getLogger().warn(
|
|
@@ -5899,7 +5925,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
5899
5925
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
5900
5926
|
);
|
|
5901
5927
|
}
|
|
5902
|
-
const { recall: recall2 } = await import("./recall-
|
|
5928
|
+
const { recall: recall2 } = await import("./recall-F33QYRYU.mjs");
|
|
5903
5929
|
const result = await recall2(
|
|
5904
5930
|
query,
|
|
5905
5931
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -5992,6 +6018,18 @@ var STOPWORDS2 = new Set(
|
|
|
5992
6018
|
].map((w) => w.toLowerCase())
|
|
5993
6019
|
);
|
|
5994
6020
|
var ENTITY_REGEX = /\b\p{Lu}[\p{L}'-]{2,}(?:\s+\p{Lu}[\p{L}'-]+){0,2}\b/gu;
|
|
6021
|
+
var FALLBACK_ONLY_STOPWORDS = "a an and or but nor not if then than because so too also just very really about above after again against all am any anyone anybody anything are around as at be been being before behind below between both by can cannot could currently did do does doing done down during each ever every everybody everyone everything few find finds finding for from get gets getting go goes going gone got had has have having he help her here hers him his hmm i in into is it its knew know knows later like liked likes live lived lives living look looked looking looks made make makes may me meet meets might mine more most must my near need needed needs never nobody nothing now of off okay on once only onto other our ours out over own people person please recently said same say says see seen shall she should since some somebody someone something soon still such talk tell tells thank that the their theirs them there these they think thinks this those thought through to today told tomorrow under until up us want wanted wants was we went were which while will with without work worked working works would yeah year years yep yesterday you your yours aren't can't couldn't didn't doesn't don't hadn't hasn't haven't he's how's i'd i'll i'm i've isn't it's let's she's shouldn't that's there's they're they've wasn't we're we've weren't what's when's where's who's why's won't wouldn't you'll you're you've".split(" ");
|
|
6022
|
+
var FALLBACK_STOPWORDS = /* @__PURE__ */ new Set([...STOPWORDS2, ...FALLBACK_ONLY_STOPWORDS]);
|
|
6023
|
+
var MAX_FALLBACK_CANDIDATES = 12;
|
|
6024
|
+
var MAX_FALLBACK_TOKENS = 3;
|
|
6025
|
+
function hasMeaningfulCandidate(candidates) {
|
|
6026
|
+
for (const candidate of candidates) {
|
|
6027
|
+
if (!candidate.split(/\s+/).every((token) => FALLBACK_STOPWORDS.has(token))) {
|
|
6028
|
+
return true;
|
|
6029
|
+
}
|
|
6030
|
+
}
|
|
6031
|
+
return false;
|
|
6032
|
+
}
|
|
5995
6033
|
function extractQueryEntities(query) {
|
|
5996
6034
|
if (!query) return [];
|
|
5997
6035
|
const matches = query.matchAll(ENTITY_REGEX);
|
|
@@ -6007,7 +6045,25 @@ function extractQueryEntities(query) {
|
|
|
6007
6045
|
seen.add(candidate);
|
|
6008
6046
|
}
|
|
6009
6047
|
}
|
|
6010
|
-
return [...seen];
|
|
6048
|
+
if (hasMeaningfulCandidate(seen)) return [...seen];
|
|
6049
|
+
return [.../* @__PURE__ */ new Set([...extractFallbackCandidates(query), ...seen])];
|
|
6050
|
+
}
|
|
6051
|
+
function extractFallbackCandidates(query) {
|
|
6052
|
+
const tokens = (query.match(/\p{L}[\p{L}'-]*/gu) ?? []).map(normalizeEntityName);
|
|
6053
|
+
const out = [];
|
|
6054
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6055
|
+
for (let n = 1; n <= MAX_FALLBACK_TOKENS; n++) {
|
|
6056
|
+
for (let start = 0; start + n <= tokens.length; start++) {
|
|
6057
|
+
const gram = tokens.slice(start, start + n);
|
|
6058
|
+
if (gram.some((t) => t.length < 2 || FALLBACK_STOPWORDS.has(t))) continue;
|
|
6059
|
+
const candidate = gram.join(" ");
|
|
6060
|
+
if (seen.has(candidate)) continue;
|
|
6061
|
+
seen.add(candidate);
|
|
6062
|
+
out.push(candidate);
|
|
6063
|
+
if (out.length >= MAX_FALLBACK_CANDIDATES) return out;
|
|
6064
|
+
}
|
|
6065
|
+
}
|
|
6066
|
+
return out;
|
|
6011
6067
|
}
|
|
6012
6068
|
|
|
6013
6069
|
// src/lib/memory/graphTraversal.ts
|
package/dist/react/index.cjs
CHANGED
|
@@ -4866,10 +4866,12 @@ async function getVaultRankingProjectionsOp(ctx, options) {
|
|
|
4866
4866
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
4867
4867
|
return results.map(vaultMemoryRawToRankable);
|
|
4868
4868
|
}
|
|
4869
|
-
function baseVaultSql(ctx) {
|
|
4869
|
+
function baseVaultSql(ctx, options) {
|
|
4870
4870
|
const clauses = [
|
|
4871
4871
|
'"is_deleted" = 0',
|
|
4872
|
-
'
|
|
4872
|
+
// Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
|
|
4873
|
+
// excluding archived rows, so every existing caller is unchanged.
|
|
4874
|
+
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
4873
4875
|
`"trust_tier" is not 'quarantined'`,
|
|
4874
4876
|
'"superseded_by" is null'
|
|
4875
4877
|
];
|
|
@@ -4889,7 +4891,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
4889
4891
|
updatedAt: new Date(raw.updated_at)
|
|
4890
4892
|
});
|
|
4891
4893
|
try {
|
|
4892
|
-
const base = baseVaultSql(ctx
|
|
4894
|
+
const base = baseVaultSql(ctx, {
|
|
4895
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4896
|
+
});
|
|
4893
4897
|
const clauses = [base.sql];
|
|
4894
4898
|
const args = [...base.args];
|
|
4895
4899
|
if (options?.scopes?.length) {
|
|
@@ -4900,6 +4904,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
4900
4904
|
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
4901
4905
|
if (options.folderId !== null) args.push(options.folderId);
|
|
4902
4906
|
}
|
|
4907
|
+
if (options?.factTypes?.length) {
|
|
4908
|
+
clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
|
|
4909
|
+
args.push(...options.factTypes);
|
|
4910
|
+
}
|
|
4903
4911
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
4904
4912
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb10.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
4905
4913
|
return rows.map(mapRaw);
|
|
@@ -4908,15 +4916,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
4908
4916
|
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
4909
4917
|
);
|
|
4910
4918
|
const conditions = [
|
|
4911
|
-
...baseVaultConditions(ctx
|
|
4919
|
+
...baseVaultConditions(ctx, {
|
|
4920
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4921
|
+
}),
|
|
4912
4922
|
...options?.scopes?.length ? [import_watermelondb10.Q.where("scope", import_watermelondb10.Q.oneOf(options.scopes))] : [],
|
|
4913
|
-
...options?.folderId !== void 0 ? [import_watermelondb10.Q.where("folder_id", options.folderId)] : []
|
|
4923
|
+
...options?.folderId !== void 0 ? [import_watermelondb10.Q.where("folder_id", options.folderId)] : [],
|
|
4924
|
+
...options?.factTypes?.length ? [import_watermelondb10.Q.where("fact_type", import_watermelondb10.Q.oneOf(options.factTypes))] : []
|
|
4914
4925
|
];
|
|
4915
4926
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
4916
4927
|
return rows.map(mapRaw);
|
|
4917
4928
|
}
|
|
4918
4929
|
}
|
|
4919
|
-
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
4930
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
4920
4931
|
if (ids.length === 0) return [];
|
|
4921
4932
|
const mapRaw = (raw) => ({
|
|
4922
4933
|
uniqueId: raw.id,
|
|
@@ -4924,7 +4935,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
4924
4935
|
embeddingModel: raw.embedding_model ?? null
|
|
4925
4936
|
});
|
|
4926
4937
|
try {
|
|
4927
|
-
const base = baseVaultSql(ctx
|
|
4938
|
+
const base = baseVaultSql(ctx, {
|
|
4939
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4940
|
+
});
|
|
4928
4941
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
4929
4942
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb10.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
4930
4943
|
return rows.map(mapRaw);
|
|
@@ -4932,13 +4945,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
4932
4945
|
getLogger().debug(
|
|
4933
4946
|
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
4934
4947
|
);
|
|
4935
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
4948
|
+
const rows = await ctx.vaultMemoryCollection.query(
|
|
4949
|
+
...baseVaultConditions(ctx, {
|
|
4950
|
+
...options?.includeArchived !== void 0 && {
|
|
4951
|
+
includeArchived: options.includeArchived
|
|
4952
|
+
}
|
|
4953
|
+
}),
|
|
4954
|
+
import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(ids))
|
|
4955
|
+
).unsafeFetchRaw();
|
|
4936
4956
|
return rows.map(mapRaw);
|
|
4937
4957
|
}
|
|
4938
4958
|
}
|
|
4939
|
-
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
4959
|
+
async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
4940
4960
|
if (ids.length === 0) return [];
|
|
4941
|
-
const conditions = [
|
|
4961
|
+
const conditions = [
|
|
4962
|
+
...baseVaultConditions(ctx, {
|
|
4963
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
4964
|
+
}),
|
|
4965
|
+
import_watermelondb10.Q.where("id", import_watermelondb10.Q.oneOf(ids))
|
|
4966
|
+
];
|
|
4942
4967
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
4943
4968
|
return mapInBatches(
|
|
4944
4969
|
results,
|
|
@@ -6156,6 +6181,14 @@ var init_lruCache = __esm({
|
|
|
6156
6181
|
});
|
|
6157
6182
|
|
|
6158
6183
|
// src/lib/memory/queryEntities.ts
|
|
6184
|
+
function hasMeaningfulCandidate(candidates) {
|
|
6185
|
+
for (const candidate of candidates) {
|
|
6186
|
+
if (!candidate.split(/\s+/).every((token) => FALLBACK_STOPWORDS.has(token))) {
|
|
6187
|
+
return true;
|
|
6188
|
+
}
|
|
6189
|
+
}
|
|
6190
|
+
return false;
|
|
6191
|
+
}
|
|
6159
6192
|
function extractQueryEntities(query) {
|
|
6160
6193
|
if (!query) return [];
|
|
6161
6194
|
const matches = query.matchAll(ENTITY_REGEX);
|
|
@@ -6171,9 +6204,27 @@ function extractQueryEntities(query) {
|
|
|
6171
6204
|
seen.add(candidate);
|
|
6172
6205
|
}
|
|
6173
6206
|
}
|
|
6174
|
-
return [...seen];
|
|
6207
|
+
if (hasMeaningfulCandidate(seen)) return [...seen];
|
|
6208
|
+
return [.../* @__PURE__ */ new Set([...extractFallbackCandidates(query), ...seen])];
|
|
6209
|
+
}
|
|
6210
|
+
function extractFallbackCandidates(query) {
|
|
6211
|
+
const tokens = (query.match(/\p{L}[\p{L}'-]*/gu) ?? []).map(normalizeEntityName);
|
|
6212
|
+
const out = [];
|
|
6213
|
+
const seen = /* @__PURE__ */ new Set();
|
|
6214
|
+
for (let n = 1; n <= MAX_FALLBACK_TOKENS; n++) {
|
|
6215
|
+
for (let start = 0; start + n <= tokens.length; start++) {
|
|
6216
|
+
const gram = tokens.slice(start, start + n);
|
|
6217
|
+
if (gram.some((t) => t.length < 2 || FALLBACK_STOPWORDS.has(t))) continue;
|
|
6218
|
+
const candidate = gram.join(" ");
|
|
6219
|
+
if (seen.has(candidate)) continue;
|
|
6220
|
+
seen.add(candidate);
|
|
6221
|
+
out.push(candidate);
|
|
6222
|
+
if (out.length >= MAX_FALLBACK_CANDIDATES) return out;
|
|
6223
|
+
}
|
|
6224
|
+
}
|
|
6225
|
+
return out;
|
|
6175
6226
|
}
|
|
6176
|
-
var STOPWORDS2, ENTITY_REGEX;
|
|
6227
|
+
var STOPWORDS2, ENTITY_REGEX, FALLBACK_ONLY_STOPWORDS, FALLBACK_STOPWORDS, MAX_FALLBACK_CANDIDATES, MAX_FALLBACK_TOKENS;
|
|
6177
6228
|
var init_queryEntities = __esm({
|
|
6178
6229
|
"src/lib/memory/queryEntities.ts"() {
|
|
6179
6230
|
"use strict";
|
|
@@ -6225,6 +6276,10 @@ var init_queryEntities = __esm({
|
|
|
6225
6276
|
].map((w) => w.toLowerCase())
|
|
6226
6277
|
);
|
|
6227
6278
|
ENTITY_REGEX = /\b\p{Lu}[\p{L}'-]{2,}(?:\s+\p{Lu}[\p{L}'-]+){0,2}\b/gu;
|
|
6279
|
+
FALLBACK_ONLY_STOPWORDS = "a an and or but nor not if then than because so too also just very really about above after again against all am any anyone anybody anything are around as at be been being before behind below between both by can cannot could currently did do does doing done down during each ever every everybody everyone everything few find finds finding for from get gets getting go goes going gone got had has have having he help her here hers him his hmm i in into is it its knew know knows later like liked likes live lived lives living look looked looking looks made make makes may me meet meets might mine more most must my near need needed needs never nobody nothing now of off okay on once only onto other our ours out over own people person please recently said same say says see seen shall she should since some somebody someone something soon still such talk tell tells thank that the their theirs them there these they think thinks this those thought through to today told tomorrow under until up us want wanted wants was we went were which while will with without work worked working works would yeah year years yep yesterday you your yours aren't can't couldn't didn't doesn't don't hadn't hasn't haven't he's how's i'd i'll i'm i've isn't it's let's she's shouldn't that's there's they're they've wasn't we're we've weren't what's when's where's who's why's won't wouldn't you'll you're you've".split(" ");
|
|
6280
|
+
FALLBACK_STOPWORDS = /* @__PURE__ */ new Set([...STOPWORDS2, ...FALLBACK_ONLY_STOPWORDS]);
|
|
6281
|
+
MAX_FALLBACK_CANDIDATES = 12;
|
|
6282
|
+
MAX_FALLBACK_TOKENS = 3;
|
|
6228
6283
|
}
|
|
6229
6284
|
});
|
|
6230
6285
|
|
|
@@ -7578,6 +7633,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7578
7633
|
vaultCtx,
|
|
7579
7634
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
7580
7635
|
);
|
|
7636
|
+
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
7581
7637
|
const vaultSize = keys.length;
|
|
7582
7638
|
if (keys.length === 0) {
|
|
7583
7639
|
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
@@ -7599,7 +7655,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7599
7655
|
else noVectorIds.push(k2.uniqueId);
|
|
7600
7656
|
}
|
|
7601
7657
|
if (missIds.length > 0) {
|
|
7602
|
-
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
7658
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
7603
7659
|
const gotVector = /* @__PURE__ */ new Set();
|
|
7604
7660
|
for (const r of rows) {
|
|
7605
7661
|
if (!r.embedding) continue;
|
|
@@ -7624,7 +7680,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7624
7680
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
7625
7681
|
);
|
|
7626
7682
|
}
|
|
7627
|
-
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
7683
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
|
|
7628
7684
|
(m) => !isEncrypted(m.content)
|
|
7629
7685
|
);
|
|
7630
7686
|
if (laneRows.length > 0) {
|
|
@@ -7654,7 +7710,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
7654
7710
|
if (keyById.has(id)) admissionSet.add(id);
|
|
7655
7711
|
}
|
|
7656
7712
|
}
|
|
7657
|
-
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
7713
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
|
|
7658
7714
|
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
7659
7715
|
if (memories.length < admittedRows.length) {
|
|
7660
7716
|
getLogger().warn(
|
package/dist/react/index.d.mts
CHANGED
|
@@ -7243,6 +7243,16 @@ interface VaultCandidateKey {
|
|
|
7243
7243
|
declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, options?: {
|
|
7244
7244
|
scopes?: string[];
|
|
7245
7245
|
folderId?: string | null;
|
|
7246
|
+
/**
|
|
7247
|
+
* Typed memory (PR1) — restrict to these fact types. Omit for no filter.
|
|
7248
|
+
* MUST stay in step with `getAllVaultMemoriesOp`: this op backs the
|
|
7249
|
+
* decrypt-last search path, and the two paths are meant to return the same
|
|
7250
|
+
* candidate set for the same query. Dropping it here made typed recall
|
|
7251
|
+
* silently path-dependent (#779).
|
|
7252
|
+
*/
|
|
7253
|
+
factTypes?: string[];
|
|
7254
|
+
/** Include archived (decayed) memories. Default `false`, as elsewhere. */
|
|
7255
|
+
includeArchived?: boolean;
|
|
7246
7256
|
}): Promise<VaultCandidateKey[]>;
|
|
7247
7257
|
/**
|
|
7248
7258
|
* Column-projected embedding lookup for a KNOWN set of ids — id + embedding +
|
|
@@ -7252,7 +7262,16 @@ declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, opti
|
|
|
7252
7262
|
* OPFS-SQLite, falling back to the standard Q query + unsafeFetchRaw on
|
|
7253
7263
|
* LokiJS (Q.unsafeSqlQuery throws there).
|
|
7254
7264
|
*/
|
|
7255
|
-
declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]
|
|
7265
|
+
declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
|
|
7266
|
+
/**
|
|
7267
|
+
* Must match whatever admitted these ids. The caller has already filtered the
|
|
7268
|
+
* candidate set; re-applying a DEFAULT-ON exclusion here silently deletes rows
|
|
7269
|
+
* it deliberately admitted — which is how archived rows passed the key scan
|
|
7270
|
+
* and then vanished at hydration (#779).
|
|
7271
|
+
*/
|
|
7272
|
+
options?: {
|
|
7273
|
+
includeArchived?: boolean;
|
|
7274
|
+
}): Promise<Array<{
|
|
7256
7275
|
uniqueId: string;
|
|
7257
7276
|
embedding: string | null;
|
|
7258
7277
|
embeddingModel: string | null;
|
|
@@ -7270,7 +7289,11 @@ declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, id
|
|
|
7270
7289
|
* excluded exactly as they are from recall — a caller can pass any id list and
|
|
7271
7290
|
* only its own live rows come back.
|
|
7272
7291
|
*/
|
|
7273
|
-
declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]
|
|
7292
|
+
declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
|
|
7293
|
+
/** See {@link getVaultEmbeddingsByIdsOp} — must match what admitted these ids. */
|
|
7294
|
+
options?: {
|
|
7295
|
+
includeArchived?: boolean;
|
|
7296
|
+
}): Promise<StoredVaultMemory[]>;
|
|
7274
7297
|
declare function getAllVaultMemoryContentsOp(ctx: VaultMemoryOperationsContext, options?: {
|
|
7275
7298
|
since?: Date;
|
|
7276
7299
|
}): Promise<string[]>;
|
package/dist/react/index.d.ts
CHANGED
|
@@ -7243,6 +7243,16 @@ interface VaultCandidateKey {
|
|
|
7243
7243
|
declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, options?: {
|
|
7244
7244
|
scopes?: string[];
|
|
7245
7245
|
folderId?: string | null;
|
|
7246
|
+
/**
|
|
7247
|
+
* Typed memory (PR1) — restrict to these fact types. Omit for no filter.
|
|
7248
|
+
* MUST stay in step with `getAllVaultMemoriesOp`: this op backs the
|
|
7249
|
+
* decrypt-last search path, and the two paths are meant to return the same
|
|
7250
|
+
* candidate set for the same query. Dropping it here made typed recall
|
|
7251
|
+
* silently path-dependent (#779).
|
|
7252
|
+
*/
|
|
7253
|
+
factTypes?: string[];
|
|
7254
|
+
/** Include archived (decayed) memories. Default `false`, as elsewhere. */
|
|
7255
|
+
includeArchived?: boolean;
|
|
7246
7256
|
}): Promise<VaultCandidateKey[]>;
|
|
7247
7257
|
/**
|
|
7248
7258
|
* Column-projected embedding lookup for a KNOWN set of ids — id + embedding +
|
|
@@ -7252,7 +7262,16 @@ declare function getVaultCandidateKeysOp(ctx: VaultMemoryOperationsContext, opti
|
|
|
7252
7262
|
* OPFS-SQLite, falling back to the standard Q query + unsafeFetchRaw on
|
|
7253
7263
|
* LokiJS (Q.unsafeSqlQuery throws there).
|
|
7254
7264
|
*/
|
|
7255
|
-
declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]
|
|
7265
|
+
declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
|
|
7266
|
+
/**
|
|
7267
|
+
* Must match whatever admitted these ids. The caller has already filtered the
|
|
7268
|
+
* candidate set; re-applying a DEFAULT-ON exclusion here silently deletes rows
|
|
7269
|
+
* it deliberately admitted — which is how archived rows passed the key scan
|
|
7270
|
+
* and then vanished at hydration (#779).
|
|
7271
|
+
*/
|
|
7272
|
+
options?: {
|
|
7273
|
+
includeArchived?: boolean;
|
|
7274
|
+
}): Promise<Array<{
|
|
7256
7275
|
uniqueId: string;
|
|
7257
7276
|
embedding: string | null;
|
|
7258
7277
|
embeddingModel: string | null;
|
|
@@ -7270,7 +7289,11 @@ declare function getVaultEmbeddingsByIdsOp(ctx: VaultMemoryOperationsContext, id
|
|
|
7270
7289
|
* excluded exactly as they are from recall — a caller can pass any id list and
|
|
7271
7290
|
* only its own live rows come back.
|
|
7272
7291
|
*/
|
|
7273
|
-
declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[]
|
|
7292
|
+
declare function getVaultMemoriesByIdsOp(ctx: VaultMemoryOperationsContext, ids: string[],
|
|
7293
|
+
/** See {@link getVaultEmbeddingsByIdsOp} — must match what admitted these ids. */
|
|
7294
|
+
options?: {
|
|
7295
|
+
includeArchived?: boolean;
|
|
7296
|
+
}): Promise<StoredVaultMemory[]>;
|
|
7274
7297
|
declare function getAllVaultMemoryContentsOp(ctx: VaultMemoryOperationsContext, options?: {
|
|
7275
7298
|
since?: Date;
|
|
7276
7299
|
}): Promise<string[]>;
|
package/dist/react/index.mjs
CHANGED
|
@@ -16583,10 +16583,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
16583
16583
|
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
16584
16584
|
);
|
|
16585
16585
|
}
|
|
16586
|
-
function baseVaultSql(ctx) {
|
|
16586
|
+
function baseVaultSql(ctx, options) {
|
|
16587
16587
|
const clauses = [
|
|
16588
16588
|
'"is_deleted" = 0',
|
|
16589
|
-
'
|
|
16589
|
+
// Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
|
|
16590
|
+
// excluding archived rows, so every existing caller is unchanged.
|
|
16591
|
+
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
16590
16592
|
`"trust_tier" is not 'quarantined'`,
|
|
16591
16593
|
'"superseded_by" is null'
|
|
16592
16594
|
];
|
|
@@ -16606,7 +16608,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
16606
16608
|
updatedAt: new Date(raw.updated_at)
|
|
16607
16609
|
});
|
|
16608
16610
|
try {
|
|
16609
|
-
const base = baseVaultSql(ctx
|
|
16611
|
+
const base = baseVaultSql(ctx, {
|
|
16612
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
16613
|
+
});
|
|
16610
16614
|
const clauses = [base.sql];
|
|
16611
16615
|
const args = [...base.args];
|
|
16612
16616
|
if (options?.scopes?.length) {
|
|
@@ -16617,6 +16621,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
16617
16621
|
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
16618
16622
|
if (options.folderId !== null) args.push(options.folderId);
|
|
16619
16623
|
}
|
|
16624
|
+
if (options?.factTypes?.length) {
|
|
16625
|
+
clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
|
|
16626
|
+
args.push(...options.factTypes);
|
|
16627
|
+
}
|
|
16620
16628
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
16621
16629
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb3.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
16622
16630
|
return rows.map(mapRaw);
|
|
@@ -16625,15 +16633,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
16625
16633
|
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
16626
16634
|
);
|
|
16627
16635
|
const conditions = [
|
|
16628
|
-
...baseVaultConditions(ctx
|
|
16636
|
+
...baseVaultConditions(ctx, {
|
|
16637
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
16638
|
+
}),
|
|
16629
16639
|
...options?.scopes?.length ? [import_watermelondb3.Q.where("scope", import_watermelondb3.Q.oneOf(options.scopes))] : [],
|
|
16630
|
-
...options?.folderId !== void 0 ? [import_watermelondb3.Q.where("folder_id", options.folderId)] : []
|
|
16640
|
+
...options?.folderId !== void 0 ? [import_watermelondb3.Q.where("folder_id", options.folderId)] : [],
|
|
16641
|
+
...options?.factTypes?.length ? [import_watermelondb3.Q.where("fact_type", import_watermelondb3.Q.oneOf(options.factTypes))] : []
|
|
16631
16642
|
];
|
|
16632
16643
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
16633
16644
|
return rows.map(mapRaw);
|
|
16634
16645
|
}
|
|
16635
16646
|
}
|
|
16636
|
-
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
16647
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
16637
16648
|
if (ids.length === 0) return [];
|
|
16638
16649
|
const mapRaw = (raw) => ({
|
|
16639
16650
|
uniqueId: raw.id,
|
|
@@ -16641,7 +16652,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
16641
16652
|
embeddingModel: raw.embedding_model ?? null
|
|
16642
16653
|
});
|
|
16643
16654
|
try {
|
|
16644
|
-
const base = baseVaultSql(ctx
|
|
16655
|
+
const base = baseVaultSql(ctx, {
|
|
16656
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
16657
|
+
});
|
|
16645
16658
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
16646
16659
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb3.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
16647
16660
|
return rows.map(mapRaw);
|
|
@@ -16649,13 +16662,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
16649
16662
|
getLogger().debug(
|
|
16650
16663
|
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
16651
16664
|
);
|
|
16652
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
16665
|
+
const rows = await ctx.vaultMemoryCollection.query(
|
|
16666
|
+
...baseVaultConditions(ctx, {
|
|
16667
|
+
...options?.includeArchived !== void 0 && {
|
|
16668
|
+
includeArchived: options.includeArchived
|
|
16669
|
+
}
|
|
16670
|
+
}),
|
|
16671
|
+
import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))
|
|
16672
|
+
).unsafeFetchRaw();
|
|
16653
16673
|
return rows.map(mapRaw);
|
|
16654
16674
|
}
|
|
16655
16675
|
}
|
|
16656
|
-
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
16676
|
+
async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
16657
16677
|
if (ids.length === 0) return [];
|
|
16658
|
-
const conditions = [
|
|
16678
|
+
const conditions = [
|
|
16679
|
+
...baseVaultConditions(ctx, {
|
|
16680
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
16681
|
+
}),
|
|
16682
|
+
import_watermelondb3.Q.where("id", import_watermelondb3.Q.oneOf(ids))
|
|
16683
|
+
];
|
|
16659
16684
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
16660
16685
|
return mapInBatches(
|
|
16661
16686
|
results,
|
|
@@ -19349,6 +19374,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
19349
19374
|
vaultCtx,
|
|
19350
19375
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
19351
19376
|
);
|
|
19377
|
+
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
19352
19378
|
const vaultSize = keys.length;
|
|
19353
19379
|
if (keys.length === 0) {
|
|
19354
19380
|
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
@@ -19370,7 +19396,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
19370
19396
|
else noVectorIds.push(k2.uniqueId);
|
|
19371
19397
|
}
|
|
19372
19398
|
if (missIds.length > 0) {
|
|
19373
|
-
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
19399
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
19374
19400
|
const gotVector = /* @__PURE__ */ new Set();
|
|
19375
19401
|
for (const r of rows) {
|
|
19376
19402
|
if (!r.embedding) continue;
|
|
@@ -19395,7 +19421,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
19395
19421
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
19396
19422
|
);
|
|
19397
19423
|
}
|
|
19398
|
-
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
19424
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
|
|
19399
19425
|
(m) => !isEncrypted(m.content)
|
|
19400
19426
|
);
|
|
19401
19427
|
if (laneRows.length > 0) {
|
|
@@ -19425,7 +19451,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
19425
19451
|
if (keyById.has(id)) admissionSet.add(id);
|
|
19426
19452
|
}
|
|
19427
19453
|
}
|
|
19428
|
-
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
19454
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
|
|
19429
19455
|
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
19430
19456
|
if (memories.length < admittedRows.length) {
|
|
19431
19457
|
getLogger().warn(
|
|
@@ -19789,7 +19815,7 @@ function createMemoryVaultSearchTool(vaultCtx, embeddingOptions, cache, searchOp
|
|
|
19789
19815
|
legacy.map((r) => ({ id: r.uniqueId, content: r.content, score: r.similarity }))
|
|
19790
19816
|
);
|
|
19791
19817
|
}
|
|
19792
|
-
const { recall: recall2 } = await import("./recall-
|
|
19818
|
+
const { recall: recall2 } = await import("./recall-23VTTAEG.mjs");
|
|
19793
19819
|
const result = await recall2(
|
|
19794
19820
|
query,
|
|
19795
19821
|
{ vaultCtx, embeddingOptions, vaultCache: cache },
|
|
@@ -19882,6 +19908,18 @@ var STOPWORDS2 = new Set(
|
|
|
19882
19908
|
].map((w) => w.toLowerCase())
|
|
19883
19909
|
);
|
|
19884
19910
|
var ENTITY_REGEX = /\b\p{Lu}[\p{L}'-]{2,}(?:\s+\p{Lu}[\p{L}'-]+){0,2}\b/gu;
|
|
19911
|
+
var FALLBACK_ONLY_STOPWORDS = "a an and or but nor not if then than because so too also just very really about above after again against all am any anyone anybody anything are around as at be been being before behind below between both by can cannot could currently did do does doing done down during each ever every everybody everyone everything few find finds finding for from get gets getting go goes going gone got had has have having he help her here hers him his hmm i in into is it its knew know knows later like liked likes live lived lives living look looked looking looks made make makes may me meet meets might mine more most must my near need needed needs never nobody nothing now of off okay on once only onto other our ours out over own people person please recently said same say says see seen shall she should since some somebody someone something soon still such talk tell tells thank that the their theirs them there these they think thinks this those thought through to today told tomorrow under until up us want wanted wants was we went were which while will with without work worked working works would yeah year years yep yesterday you your yours aren't can't couldn't didn't doesn't don't hadn't hasn't haven't he's how's i'd i'll i'm i've isn't it's let's she's shouldn't that's there's they're they've wasn't we're we've weren't what's when's where's who's why's won't wouldn't you'll you're you've".split(" ");
|
|
19912
|
+
var FALLBACK_STOPWORDS = /* @__PURE__ */ new Set([...STOPWORDS2, ...FALLBACK_ONLY_STOPWORDS]);
|
|
19913
|
+
var MAX_FALLBACK_CANDIDATES = 12;
|
|
19914
|
+
var MAX_FALLBACK_TOKENS = 3;
|
|
19915
|
+
function hasMeaningfulCandidate(candidates) {
|
|
19916
|
+
for (const candidate of candidates) {
|
|
19917
|
+
if (!candidate.split(/\s+/).every((token) => FALLBACK_STOPWORDS.has(token))) {
|
|
19918
|
+
return true;
|
|
19919
|
+
}
|
|
19920
|
+
}
|
|
19921
|
+
return false;
|
|
19922
|
+
}
|
|
19885
19923
|
function extractQueryEntities(query) {
|
|
19886
19924
|
if (!query) return [];
|
|
19887
19925
|
const matches = query.matchAll(ENTITY_REGEX);
|
|
@@ -19897,7 +19935,25 @@ function extractQueryEntities(query) {
|
|
|
19897
19935
|
seen.add(candidate);
|
|
19898
19936
|
}
|
|
19899
19937
|
}
|
|
19900
|
-
return [...seen];
|
|
19938
|
+
if (hasMeaningfulCandidate(seen)) return [...seen];
|
|
19939
|
+
return [.../* @__PURE__ */ new Set([...extractFallbackCandidates(query), ...seen])];
|
|
19940
|
+
}
|
|
19941
|
+
function extractFallbackCandidates(query) {
|
|
19942
|
+
const tokens = (query.match(/\p{L}[\p{L}'-]*/gu) ?? []).map(normalizeEntityName);
|
|
19943
|
+
const out = [];
|
|
19944
|
+
const seen = /* @__PURE__ */ new Set();
|
|
19945
|
+
for (let n = 1; n <= MAX_FALLBACK_TOKENS; n++) {
|
|
19946
|
+
for (let start = 0; start + n <= tokens.length; start++) {
|
|
19947
|
+
const gram = tokens.slice(start, start + n);
|
|
19948
|
+
if (gram.some((t) => t.length < 2 || FALLBACK_STOPWORDS.has(t))) continue;
|
|
19949
|
+
const candidate = gram.join(" ");
|
|
19950
|
+
if (seen.has(candidate)) continue;
|
|
19951
|
+
seen.add(candidate);
|
|
19952
|
+
out.push(candidate);
|
|
19953
|
+
if (out.length >= MAX_FALLBACK_CANDIDATES) return out;
|
|
19954
|
+
}
|
|
19955
|
+
}
|
|
19956
|
+
return out;
|
|
19901
19957
|
}
|
|
19902
19958
|
|
|
19903
19959
|
// src/lib/memory/graphTraversal.ts
|
package/dist/server/index.cjs
CHANGED
|
@@ -17389,10 +17389,12 @@ async function getAllVaultMemoriesOp(ctx, options) {
|
|
|
17389
17389
|
(raw) => vaultMemoryRawToStored(raw, ctx.walletAddress, ctx.signMessage, ctx.embeddedWalletSigner)
|
|
17390
17390
|
);
|
|
17391
17391
|
}
|
|
17392
|
-
function baseVaultSql(ctx) {
|
|
17392
|
+
function baseVaultSql(ctx, options) {
|
|
17393
17393
|
const clauses = [
|
|
17394
17394
|
'"is_deleted" = 0',
|
|
17395
|
-
'
|
|
17395
|
+
// Mirrors `baseVaultConditions`' `includeArchived` branch. Defaults to
|
|
17396
|
+
// excluding archived rows, so every existing caller is unchanged.
|
|
17397
|
+
...options?.includeArchived ? [] : ['"archived_at" is null'],
|
|
17396
17398
|
`"trust_tier" is not 'quarantined'`,
|
|
17397
17399
|
'"superseded_by" is null'
|
|
17398
17400
|
];
|
|
@@ -17412,7 +17414,9 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
17412
17414
|
updatedAt: new Date(raw.updated_at)
|
|
17413
17415
|
});
|
|
17414
17416
|
try {
|
|
17415
|
-
const base = baseVaultSql(ctx
|
|
17417
|
+
const base = baseVaultSql(ctx, {
|
|
17418
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
17419
|
+
});
|
|
17416
17420
|
const clauses = [base.sql];
|
|
17417
17421
|
const args = [...base.args];
|
|
17418
17422
|
if (options?.scopes?.length) {
|
|
@@ -17423,6 +17427,10 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
17423
17427
|
clauses.push(options.folderId === null ? '"folder_id" is null' : '"folder_id" = ?');
|
|
17424
17428
|
if (options.folderId !== null) args.push(options.folderId);
|
|
17425
17429
|
}
|
|
17430
|
+
if (options?.factTypes?.length) {
|
|
17431
|
+
clauses.push(`"fact_type" in (${options.factTypes.map(() => "?").join(",")})`);
|
|
17432
|
+
args.push(...options.factTypes);
|
|
17433
|
+
}
|
|
17426
17434
|
const sql = `select "id", "scope", "folder_id", "embedding_model", "updated_at" from "memory_vault" where ${clauses.join(" and ")}`;
|
|
17427
17435
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb17.Q.unsafeSqlQuery(sql, args)).unsafeFetchRaw();
|
|
17428
17436
|
return rows.map(mapRaw);
|
|
@@ -17431,15 +17439,18 @@ async function getVaultCandidateKeysOp(ctx, options) {
|
|
|
17431
17439
|
"memoryVault: getVaultCandidateKeysOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
17432
17440
|
);
|
|
17433
17441
|
const conditions = [
|
|
17434
|
-
...baseVaultConditions(ctx
|
|
17442
|
+
...baseVaultConditions(ctx, {
|
|
17443
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
17444
|
+
}),
|
|
17435
17445
|
...options?.scopes?.length ? [import_watermelondb17.Q.where("scope", import_watermelondb17.Q.oneOf(options.scopes))] : [],
|
|
17436
|
-
...options?.folderId !== void 0 ? [import_watermelondb17.Q.where("folder_id", options.folderId)] : []
|
|
17446
|
+
...options?.folderId !== void 0 ? [import_watermelondb17.Q.where("folder_id", options.folderId)] : [],
|
|
17447
|
+
...options?.factTypes?.length ? [import_watermelondb17.Q.where("fact_type", import_watermelondb17.Q.oneOf(options.factTypes))] : []
|
|
17437
17448
|
];
|
|
17438
17449
|
const rows = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
17439
17450
|
return rows.map(mapRaw);
|
|
17440
17451
|
}
|
|
17441
17452
|
}
|
|
17442
|
-
async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
17453
|
+
async function getVaultEmbeddingsByIdsOp(ctx, ids, options) {
|
|
17443
17454
|
if (ids.length === 0) return [];
|
|
17444
17455
|
const mapRaw = (raw) => ({
|
|
17445
17456
|
uniqueId: raw.id,
|
|
@@ -17447,7 +17458,9 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
17447
17458
|
embeddingModel: raw.embedding_model ?? null
|
|
17448
17459
|
});
|
|
17449
17460
|
try {
|
|
17450
|
-
const base = baseVaultSql(ctx
|
|
17461
|
+
const base = baseVaultSql(ctx, {
|
|
17462
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
17463
|
+
});
|
|
17451
17464
|
const sql = `select "id", "embedding", "embedding_model" from "memory_vault" where ${base.sql} and "id" in (${ids.map(() => "?").join(",")})`;
|
|
17452
17465
|
const rows = await ctx.vaultMemoryCollection.query(import_watermelondb17.Q.unsafeSqlQuery(sql, [...base.args, ...ids])).unsafeFetchRaw();
|
|
17453
17466
|
return rows.map(mapRaw);
|
|
@@ -17455,13 +17468,25 @@ async function getVaultEmbeddingsByIdsOp(ctx, ids) {
|
|
|
17455
17468
|
getLogger().debug(
|
|
17456
17469
|
"memoryVault: getVaultEmbeddingsByIdsOp projected SQL unavailable, using full-load fallback: " + (err instanceof Error ? err.message : String(err))
|
|
17457
17470
|
);
|
|
17458
|
-
const rows = await ctx.vaultMemoryCollection.query(
|
|
17471
|
+
const rows = await ctx.vaultMemoryCollection.query(
|
|
17472
|
+
...baseVaultConditions(ctx, {
|
|
17473
|
+
...options?.includeArchived !== void 0 && {
|
|
17474
|
+
includeArchived: options.includeArchived
|
|
17475
|
+
}
|
|
17476
|
+
}),
|
|
17477
|
+
import_watermelondb17.Q.where("id", import_watermelondb17.Q.oneOf(ids))
|
|
17478
|
+
).unsafeFetchRaw();
|
|
17459
17479
|
return rows.map(mapRaw);
|
|
17460
17480
|
}
|
|
17461
17481
|
}
|
|
17462
|
-
async function getVaultMemoriesByIdsOp(ctx, ids) {
|
|
17482
|
+
async function getVaultMemoriesByIdsOp(ctx, ids, options) {
|
|
17463
17483
|
if (ids.length === 0) return [];
|
|
17464
|
-
const conditions = [
|
|
17484
|
+
const conditions = [
|
|
17485
|
+
...baseVaultConditions(ctx, {
|
|
17486
|
+
...options?.includeArchived !== void 0 && { includeArchived: options.includeArchived }
|
|
17487
|
+
}),
|
|
17488
|
+
import_watermelondb17.Q.where("id", import_watermelondb17.Q.oneOf(ids))
|
|
17489
|
+
];
|
|
17465
17490
|
const results = await ctx.vaultMemoryCollection.query(...conditions).unsafeFetchRaw();
|
|
17466
17491
|
return mapInBatches(
|
|
17467
17492
|
results,
|
|
@@ -20028,6 +20053,14 @@ var init_lruCache = __esm({
|
|
|
20028
20053
|
});
|
|
20029
20054
|
|
|
20030
20055
|
// src/lib/memory/queryEntities.ts
|
|
20056
|
+
function hasMeaningfulCandidate(candidates) {
|
|
20057
|
+
for (const candidate of candidates) {
|
|
20058
|
+
if (!candidate.split(/\s+/).every((token) => FALLBACK_STOPWORDS.has(token))) {
|
|
20059
|
+
return true;
|
|
20060
|
+
}
|
|
20061
|
+
}
|
|
20062
|
+
return false;
|
|
20063
|
+
}
|
|
20031
20064
|
function extractQueryEntities(query) {
|
|
20032
20065
|
if (!query) return [];
|
|
20033
20066
|
const matches = query.matchAll(ENTITY_REGEX);
|
|
@@ -20043,9 +20076,27 @@ function extractQueryEntities(query) {
|
|
|
20043
20076
|
seen.add(candidate);
|
|
20044
20077
|
}
|
|
20045
20078
|
}
|
|
20046
|
-
return [...seen];
|
|
20079
|
+
if (hasMeaningfulCandidate(seen)) return [...seen];
|
|
20080
|
+
return [.../* @__PURE__ */ new Set([...extractFallbackCandidates(query), ...seen])];
|
|
20081
|
+
}
|
|
20082
|
+
function extractFallbackCandidates(query) {
|
|
20083
|
+
const tokens = (query.match(/\p{L}[\p{L}'-]*/gu) ?? []).map(normalizeEntityName);
|
|
20084
|
+
const out = [];
|
|
20085
|
+
const seen = /* @__PURE__ */ new Set();
|
|
20086
|
+
for (let n = 1; n <= MAX_FALLBACK_TOKENS; n++) {
|
|
20087
|
+
for (let start = 0; start + n <= tokens.length; start++) {
|
|
20088
|
+
const gram = tokens.slice(start, start + n);
|
|
20089
|
+
if (gram.some((t) => t.length < 2 || FALLBACK_STOPWORDS.has(t))) continue;
|
|
20090
|
+
const candidate = gram.join(" ");
|
|
20091
|
+
if (seen.has(candidate)) continue;
|
|
20092
|
+
seen.add(candidate);
|
|
20093
|
+
out.push(candidate);
|
|
20094
|
+
if (out.length >= MAX_FALLBACK_CANDIDATES) return out;
|
|
20095
|
+
}
|
|
20096
|
+
}
|
|
20097
|
+
return out;
|
|
20047
20098
|
}
|
|
20048
|
-
var STOPWORDS2, ENTITY_REGEX;
|
|
20099
|
+
var STOPWORDS2, ENTITY_REGEX, FALLBACK_ONLY_STOPWORDS, FALLBACK_STOPWORDS, MAX_FALLBACK_CANDIDATES, MAX_FALLBACK_TOKENS;
|
|
20049
20100
|
var init_queryEntities = __esm({
|
|
20050
20101
|
"src/lib/memory/queryEntities.ts"() {
|
|
20051
20102
|
"use strict";
|
|
@@ -20097,6 +20148,10 @@ var init_queryEntities = __esm({
|
|
|
20097
20148
|
].map((w) => w.toLowerCase())
|
|
20098
20149
|
);
|
|
20099
20150
|
ENTITY_REGEX = /\b\p{Lu}[\p{L}'-]{2,}(?:\s+\p{Lu}[\p{L}'-]+){0,2}\b/gu;
|
|
20151
|
+
FALLBACK_ONLY_STOPWORDS = "a an and or but nor not if then than because so too also just very really about above after again against all am any anyone anybody anything are around as at be been being before behind below between both by can cannot could currently did do does doing done down during each ever every everybody everyone everything few find finds finding for from get gets getting go goes going gone got had has have having he help her here hers him his hmm i in into is it its knew know knows later like liked likes live lived lives living look looked looking looks made make makes may me meet meets might mine more most must my near need needed needs never nobody nothing now of off okay on once only onto other our ours out over own people person please recently said same say says see seen shall she should since some somebody someone something soon still such talk tell tells thank that the their theirs them there these they think thinks this those thought through to today told tomorrow under until up us want wanted wants was we went were which while will with without work worked working works would yeah year years yep yesterday you your yours aren't can't couldn't didn't doesn't don't hadn't hasn't haven't he's how's i'd i'll i'm i've isn't it's let's she's shouldn't that's there's they're they've wasn't we're we've weren't what's when's where's who's why's won't wouldn't you'll you're you've".split(" ");
|
|
20152
|
+
FALLBACK_STOPWORDS = /* @__PURE__ */ new Set([...STOPWORDS2, ...FALLBACK_ONLY_STOPWORDS]);
|
|
20153
|
+
MAX_FALLBACK_CANDIDATES = 12;
|
|
20154
|
+
MAX_FALLBACK_TOKENS = 3;
|
|
20100
20155
|
}
|
|
20101
20156
|
});
|
|
20102
20157
|
|
|
@@ -21450,6 +21505,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
21450
21505
|
vaultCtx,
|
|
21451
21506
|
Object.keys(queryOpts).length > 0 ? queryOpts : void 0
|
|
21452
21507
|
);
|
|
21508
|
+
const hydrateOpts = queryOpts.includeArchived ? { includeArchived: true } : void 0;
|
|
21453
21509
|
const vaultSize = keys.length;
|
|
21454
21510
|
if (keys.length === 0) {
|
|
21455
21511
|
return { memories: [], embeddedItems: [], queryEmbedding: [], vaultSize: 0 };
|
|
@@ -21471,7 +21527,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
21471
21527
|
else noVectorIds.push(k2.uniqueId);
|
|
21472
21528
|
}
|
|
21473
21529
|
if (missIds.length > 0) {
|
|
21474
|
-
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds);
|
|
21530
|
+
const rows = await getVaultEmbeddingsByIdsOp(vaultCtx, missIds, hydrateOpts);
|
|
21475
21531
|
const gotVector = /* @__PURE__ */ new Set();
|
|
21476
21532
|
for (const r of rows) {
|
|
21477
21533
|
if (!r.embedding) continue;
|
|
@@ -21496,7 +21552,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
21496
21552
|
`memoryVault: projected search un-embedded lane capped at ${laneIds.length}/${noVectorIds.length}`
|
|
21497
21553
|
);
|
|
21498
21554
|
}
|
|
21499
|
-
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds)).filter(
|
|
21555
|
+
const laneRows = (await getVaultMemoriesByIdsOp(vaultCtx, laneIds, hydrateOpts)).filter(
|
|
21500
21556
|
(m) => !isEncrypted(m.content)
|
|
21501
21557
|
);
|
|
21502
21558
|
if (laneRows.length > 0) {
|
|
@@ -21526,7 +21582,7 @@ async function buildProjectedCorpus(query, vaultCtx, embeddingOptions, cache, qu
|
|
|
21526
21582
|
if (keyById.has(id)) admissionSet.add(id);
|
|
21527
21583
|
}
|
|
21528
21584
|
}
|
|
21529
|
-
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet]);
|
|
21585
|
+
const admittedRows = await getVaultMemoriesByIdsOp(vaultCtx, [...admissionSet], hydrateOpts);
|
|
21530
21586
|
const memories = admittedRows.filter((m) => !isEncrypted(m.content));
|
|
21531
21587
|
if (memories.length < admittedRows.length) {
|
|
21532
21588
|
getLogger().warn(
|
package/dist/server/index.mjs
CHANGED