@exulu/backend 5.1.0 → 5.1.2
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/{chunk-MUR4WZLA.js → chunk-37MKZIH2.js} +69 -10
- package/dist/{convert-exulu-tools-to-ai-sdk-tools-IFENSB7J.js → convert-exulu-tools-to-ai-sdk-tools-BNDHJH7B.js} +1 -1
- package/dist/index.cjs +96 -17
- package/dist/index.js +27 -7
- package/ee/agentic-retrieval/pipeline/prefilter.test.ts +123 -0
- package/ee/agentic-retrieval/pipeline/prefilter.ts +112 -8
- package/ee/workers.ts +16 -0
- package/package.json +1 -1
|
@@ -1723,7 +1723,7 @@ var ExuluTool = class _ExuluTool {
|
|
|
1723
1723
|
if (!agent) {
|
|
1724
1724
|
throw new Error("Agent not found.");
|
|
1725
1725
|
}
|
|
1726
|
-
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-
|
|
1726
|
+
const { convertExuluToolsToAiSdkTools: convertExuluToolsToAiSdkTools2 } = await import("./convert-exulu-tools-to-ai-sdk-tools-BNDHJH7B.js");
|
|
1727
1727
|
const tools = await convertExuluToolsToAiSdkTools2(
|
|
1728
1728
|
[this],
|
|
1729
1729
|
[],
|
|
@@ -2375,6 +2375,7 @@ function itemMatchesIdentifierToken(itemName, tokens) {
|
|
|
2375
2375
|
const normName = normalizeFileName(itemName).toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
2376
2376
|
return tokens.some((t) => normName.includes(t));
|
|
2377
2377
|
}
|
|
2378
|
+
var stripSeparators = (s) => s.toLowerCase().replace(/[-_\.\s]/g, "");
|
|
2378
2379
|
function applyRewrites(question, rewrites) {
|
|
2379
2380
|
const out = /* @__PURE__ */ new Set();
|
|
2380
2381
|
for (const rule of rewrites) {
|
|
@@ -2387,6 +2388,8 @@ function applyRewrites(question, rewrites) {
|
|
|
2387
2388
|
}
|
|
2388
2389
|
|
|
2389
2390
|
// ee/agentic-retrieval/pipeline/prefilter.ts
|
|
2391
|
+
var SUPPLEMENT_MIN_TOKEN_LENGTH = 4;
|
|
2392
|
+
var SUPPLEMENT_BUDGET = 15;
|
|
2390
2393
|
var itemCaches = {};
|
|
2391
2394
|
var ensureItemsCache = async ({
|
|
2392
2395
|
cacheKey,
|
|
@@ -2396,12 +2399,21 @@ var ensureItemsCache = async ({
|
|
|
2396
2399
|
}) => {
|
|
2397
2400
|
if (!itemCaches[cacheKey] || Date.now() - itemCaches[cacheKey].tsp.getTime() > 5 * 60 * 1e3 || itemCaches[cacheKey].items.length === 0) {
|
|
2398
2401
|
const result = await context.getItems({ fields, filters: [] });
|
|
2399
|
-
const normalizedItems = result.map((item) =>
|
|
2400
|
-
|
|
2401
|
-
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2402
|
+
const normalizedItems = result.map((item) => {
|
|
2403
|
+
const normalized = normalize(item);
|
|
2404
|
+
return {
|
|
2405
|
+
name: item.name,
|
|
2406
|
+
id: item.id,
|
|
2407
|
+
external_id: item.external_id,
|
|
2408
|
+
normalized,
|
|
2409
|
+
// Separator-free form used only by the supplementary pass in
|
|
2410
|
+
// fuzzyPrefilter. Deliberately NOT added to the Fuse index or keys:
|
|
2411
|
+
// changing what Fuse scores reshuffles which items win the result cap,
|
|
2412
|
+
// which cost 22 regressions against 6 improvements when measured over
|
|
2413
|
+
// positively-rated production cases.
|
|
2414
|
+
stripped: stripSeparators(normalized ?? item.name ?? "")
|
|
2415
|
+
};
|
|
2416
|
+
});
|
|
2405
2417
|
itemCaches[cacheKey] = {
|
|
2406
2418
|
cacheKey,
|
|
2407
2419
|
items: normalizedItems,
|
|
@@ -2445,7 +2457,8 @@ async function fuzzyPrefilter({
|
|
|
2445
2457
|
fields,
|
|
2446
2458
|
normalize,
|
|
2447
2459
|
cutoff = DEFAULT_PREFILTER_CUTOFF,
|
|
2448
|
-
limit
|
|
2460
|
+
limit,
|
|
2461
|
+
supplementSeparatorVariants = false
|
|
2449
2462
|
}) {
|
|
2450
2463
|
const cache2 = await ensureItemsCache({ cacheKey, context, fields, normalize });
|
|
2451
2464
|
if (!relevantKeywords?.length) {
|
|
@@ -2536,6 +2549,44 @@ async function fuzzyPrefilter({
|
|
|
2536
2549
|
name: result2.item.name,
|
|
2537
2550
|
id: result2.item.id
|
|
2538
2551
|
}));
|
|
2552
|
+
const supplementTokens = !supplementSeparatorVariants ? [] : [
|
|
2553
|
+
...new Set(
|
|
2554
|
+
uniqueKeywords.filter((k) => /[-_.]/.test(k)).map((k) => stripSeparators(k)).filter((t) => t.length >= SUPPLEMENT_MIN_TOKEN_LENGTH)
|
|
2555
|
+
)
|
|
2556
|
+
].sort((a, b) => b.length - a.length);
|
|
2557
|
+
if (supplementTokens.length > 0) {
|
|
2558
|
+
const seen = new Set(prefiltered.map((p) => p.id));
|
|
2559
|
+
const candidates = cache2.items.filter(
|
|
2560
|
+
(item) => item.id && !seen.has(item.id) && supplementTokens.some((t) => (item.stripped ?? "").includes(t))
|
|
2561
|
+
).map((item, idx) => {
|
|
2562
|
+
const nameStripped = stripSeparators(item.name ?? "");
|
|
2563
|
+
return {
|
|
2564
|
+
item,
|
|
2565
|
+
idx,
|
|
2566
|
+
nameMatch: supplementTokens.some((t) => nameStripped.includes(t)) ? 0 : 1,
|
|
2567
|
+
nameLength: (item.name ?? "").length
|
|
2568
|
+
};
|
|
2569
|
+
}).sort(
|
|
2570
|
+
(a, b) => a.nameMatch - b.nameMatch || a.nameLength - b.nameLength || a.idx - b.idx
|
|
2571
|
+
);
|
|
2572
|
+
const supplement = [];
|
|
2573
|
+
for (const { item } of candidates) {
|
|
2574
|
+
if (supplement.length >= SUPPLEMENT_BUDGET) break;
|
|
2575
|
+
if (!item.id || seen.has(item.id)) continue;
|
|
2576
|
+
seen.add(item.id);
|
|
2577
|
+
supplement.push({
|
|
2578
|
+
key: item.external_id ?? item.id,
|
|
2579
|
+
name: item.name ?? item.external_id ?? item.id,
|
|
2580
|
+
id: item.id
|
|
2581
|
+
});
|
|
2582
|
+
}
|
|
2583
|
+
if (supplement.length > 0) {
|
|
2584
|
+
console.log(
|
|
2585
|
+
`[EXULU pipeline] fuzzyPrefilter: +${supplement.length} separator-insensitive supplement(s) for [${supplementTokens.join(", ")}]`
|
|
2586
|
+
);
|
|
2587
|
+
prefiltered.push(...supplement);
|
|
2588
|
+
}
|
|
2589
|
+
}
|
|
2539
2590
|
console.log(
|
|
2540
2591
|
`[EXULU pipeline] fuzzyPrefilter: ${prefiltered.length} result(s) for [${uniqueKeywords.join(", ")}]`
|
|
2541
2592
|
);
|
|
@@ -2594,7 +2645,10 @@ async function resolveIdentifierPins({
|
|
|
2594
2645
|
const matched = set.strategy === "exact" ? await exactTokenPrefilter({ ...common, tokens: output.matches }) : await fuzzyPrefilter({
|
|
2595
2646
|
...common,
|
|
2596
2647
|
relevantKeywords: output.matches,
|
|
2597
|
-
cutoff: DEFAULT_PREFILTER_CUTOFF
|
|
2648
|
+
cutoff: DEFAULT_PREFILTER_CUTOFF,
|
|
2649
|
+
// Identifier pins are a hard id-whitelist over filenames,
|
|
2650
|
+
// which is exactly the case the supplement exists for.
|
|
2651
|
+
supplementSeparatorVariants: true
|
|
2598
2652
|
});
|
|
2599
2653
|
if (!matched.length) return;
|
|
2600
2654
|
const target = pinsByContext.get(ctxId) ?? /* @__PURE__ */ new Set();
|
|
@@ -6847,6 +6901,10 @@ var captureCodeEmbedder = (context) => {
|
|
|
6847
6901
|
return codeEmbedders.get(context);
|
|
6848
6902
|
};
|
|
6849
6903
|
var codeEmbedderFor = (context) => codeEmbedders.has(context) ? codeEmbedders.get(context) : context.embedder;
|
|
6904
|
+
var contextEmbedderInfoFor = async (context, deps = {}) => {
|
|
6905
|
+
const resolve4 = deps.resolve ?? resolveContextEmbedder;
|
|
6906
|
+
return resolve4({ id: context.id, embedder: codeEmbedderFor(context) });
|
|
6907
|
+
};
|
|
6850
6908
|
var willEmbedOnQueue = async (context, overrideQueue) => {
|
|
6851
6909
|
if (overrideQueue) {
|
|
6852
6910
|
return registeredQueues().some((q) => q.queue?.name === overrideQueue);
|
|
@@ -14840,11 +14898,12 @@ export {
|
|
|
14840
14898
|
exuluApp,
|
|
14841
14899
|
setEmbedderSetting,
|
|
14842
14900
|
clearEmbedderSetting,
|
|
14843
|
-
resolveContextEmbedder,
|
|
14844
14901
|
captureCodeEmbedder,
|
|
14845
14902
|
codeEmbedderFor,
|
|
14903
|
+
contextEmbedderInfoFor,
|
|
14846
14904
|
willEmbedOnQueue,
|
|
14847
14905
|
hydrateContextEmbedders,
|
|
14906
|
+
refreshContextEmbeddersIfStale,
|
|
14848
14907
|
updateStatistic,
|
|
14849
14908
|
resolveSearchQueryTexts,
|
|
14850
14909
|
chooseFullTextQuery,
|
package/dist/index.cjs
CHANGED
|
@@ -3623,7 +3623,7 @@ var init_embedder_settings = __esm({
|
|
|
3623
3623
|
});
|
|
3624
3624
|
|
|
3625
3625
|
// src/exulu/hydrate-embedders.ts
|
|
3626
|
-
var registeredQueues, defaultDeps, codeEmbedders, captureCodeEmbedder, codeEmbedderFor, willEmbedOnQueue, hydrateContextEmbedders, REFRESH_INTERVAL_MS, lastRefresh, refreshContextEmbeddersIfStale;
|
|
3626
|
+
var registeredQueues, defaultDeps, codeEmbedders, captureCodeEmbedder, codeEmbedderFor, contextEmbedderInfoFor, willEmbedOnQueue, hydrateContextEmbedders, REFRESH_INTERVAL_MS, lastRefresh, refreshContextEmbeddersIfStale;
|
|
3627
3627
|
var init_hydrate_embedders = __esm({
|
|
3628
3628
|
"src/exulu/hydrate-embedders.ts"() {
|
|
3629
3629
|
"use strict";
|
|
@@ -3649,6 +3649,10 @@ var init_hydrate_embedders = __esm({
|
|
|
3649
3649
|
return codeEmbedders.get(context);
|
|
3650
3650
|
};
|
|
3651
3651
|
codeEmbedderFor = (context) => codeEmbedders.has(context) ? codeEmbedders.get(context) : context.embedder;
|
|
3652
|
+
contextEmbedderInfoFor = async (context, deps = {}) => {
|
|
3653
|
+
const resolve8 = deps.resolve ?? resolveContextEmbedder;
|
|
3654
|
+
return resolve8({ id: context.id, embedder: codeEmbedderFor(context) });
|
|
3655
|
+
};
|
|
3652
3656
|
willEmbedOnQueue = async (context, overrideQueue) => {
|
|
3653
3657
|
if (overrideQueue) {
|
|
3654
3658
|
return registeredQueues().some((q) => q.queue?.name === overrideQueue);
|
|
@@ -14048,7 +14052,7 @@ function applyRewrites(question, rewrites) {
|
|
|
14048
14052
|
}
|
|
14049
14053
|
return [...out];
|
|
14050
14054
|
}
|
|
14051
|
-
var normalizeFileName;
|
|
14055
|
+
var normalizeFileName, stripSeparators;
|
|
14052
14056
|
var init_text_utils = __esm({
|
|
14053
14057
|
"ee/agentic-retrieval/pipeline/text-utils.ts"() {
|
|
14054
14058
|
"use strict";
|
|
@@ -14064,6 +14068,7 @@ var init_text_utils = __esm({
|
|
|
14064
14068
|
normalized = normalized.replace(/ +/g, " ").trim();
|
|
14065
14069
|
return normalized;
|
|
14066
14070
|
};
|
|
14071
|
+
stripSeparators = (s) => s.toLowerCase().replace(/[-_\.\s]/g, "");
|
|
14067
14072
|
}
|
|
14068
14073
|
});
|
|
14069
14074
|
|
|
@@ -14102,7 +14107,8 @@ async function fuzzyPrefilter({
|
|
|
14102
14107
|
fields,
|
|
14103
14108
|
normalize,
|
|
14104
14109
|
cutoff = DEFAULT_PREFILTER_CUTOFF,
|
|
14105
|
-
limit
|
|
14110
|
+
limit,
|
|
14111
|
+
supplementSeparatorVariants = false
|
|
14106
14112
|
}) {
|
|
14107
14113
|
const cache2 = await ensureItemsCache({ cacheKey, context, fields, normalize });
|
|
14108
14114
|
if (!relevantKeywords?.length) {
|
|
@@ -14193,6 +14199,44 @@ async function fuzzyPrefilter({
|
|
|
14193
14199
|
name: result2.item.name,
|
|
14194
14200
|
id: result2.item.id
|
|
14195
14201
|
}));
|
|
14202
|
+
const supplementTokens = !supplementSeparatorVariants ? [] : [
|
|
14203
|
+
...new Set(
|
|
14204
|
+
uniqueKeywords.filter((k) => /[-_.]/.test(k)).map((k) => stripSeparators(k)).filter((t) => t.length >= SUPPLEMENT_MIN_TOKEN_LENGTH)
|
|
14205
|
+
)
|
|
14206
|
+
].sort((a, b) => b.length - a.length);
|
|
14207
|
+
if (supplementTokens.length > 0) {
|
|
14208
|
+
const seen = new Set(prefiltered.map((p) => p.id));
|
|
14209
|
+
const candidates = cache2.items.filter(
|
|
14210
|
+
(item) => item.id && !seen.has(item.id) && supplementTokens.some((t) => (item.stripped ?? "").includes(t))
|
|
14211
|
+
).map((item, idx) => {
|
|
14212
|
+
const nameStripped = stripSeparators(item.name ?? "");
|
|
14213
|
+
return {
|
|
14214
|
+
item,
|
|
14215
|
+
idx,
|
|
14216
|
+
nameMatch: supplementTokens.some((t) => nameStripped.includes(t)) ? 0 : 1,
|
|
14217
|
+
nameLength: (item.name ?? "").length
|
|
14218
|
+
};
|
|
14219
|
+
}).sort(
|
|
14220
|
+
(a, b) => a.nameMatch - b.nameMatch || a.nameLength - b.nameLength || a.idx - b.idx
|
|
14221
|
+
);
|
|
14222
|
+
const supplement = [];
|
|
14223
|
+
for (const { item } of candidates) {
|
|
14224
|
+
if (supplement.length >= SUPPLEMENT_BUDGET) break;
|
|
14225
|
+
if (!item.id || seen.has(item.id)) continue;
|
|
14226
|
+
seen.add(item.id);
|
|
14227
|
+
supplement.push({
|
|
14228
|
+
key: item.external_id ?? item.id,
|
|
14229
|
+
name: item.name ?? item.external_id ?? item.id,
|
|
14230
|
+
id: item.id
|
|
14231
|
+
});
|
|
14232
|
+
}
|
|
14233
|
+
if (supplement.length > 0) {
|
|
14234
|
+
console.log(
|
|
14235
|
+
`[EXULU pipeline] fuzzyPrefilter: +${supplement.length} separator-insensitive supplement(s) for [${supplementTokens.join(", ")}]`
|
|
14236
|
+
);
|
|
14237
|
+
prefiltered.push(...supplement);
|
|
14238
|
+
}
|
|
14239
|
+
}
|
|
14196
14240
|
console.log(
|
|
14197
14241
|
`[EXULU pipeline] fuzzyPrefilter: ${prefiltered.length} result(s) for [${uniqueKeywords.join(", ")}]`
|
|
14198
14242
|
);
|
|
@@ -14236,7 +14280,10 @@ async function resolveIdentifierPins({
|
|
|
14236
14280
|
const matched = set.strategy === "exact" ? await exactTokenPrefilter({ ...common, tokens: output.matches }) : await fuzzyPrefilter({
|
|
14237
14281
|
...common,
|
|
14238
14282
|
relevantKeywords: output.matches,
|
|
14239
|
-
cutoff: DEFAULT_PREFILTER_CUTOFF
|
|
14283
|
+
cutoff: DEFAULT_PREFILTER_CUTOFF,
|
|
14284
|
+
// Identifier pins are a hard id-whitelist over filenames,
|
|
14285
|
+
// which is exactly the case the supplement exists for.
|
|
14286
|
+
supplementSeparatorVariants: true
|
|
14240
14287
|
});
|
|
14241
14288
|
if (!matched.length) return;
|
|
14242
14289
|
const target = pinsByContext.get(ctxId) ?? /* @__PURE__ */ new Set();
|
|
@@ -14262,7 +14309,7 @@ async function resolveIdentifierPins({
|
|
|
14262
14309
|
);
|
|
14263
14310
|
return { pinsByContext, exactPinsByContext, steps };
|
|
14264
14311
|
}
|
|
14265
|
-
var import_fuse, import_zod12, itemCaches, ensureItemsCache, FUZZY_EXTRACTION_PROMPT, EXACT_EXTRACTION_PROMPT;
|
|
14312
|
+
var import_fuse, import_zod12, SUPPLEMENT_MIN_TOKEN_LENGTH, SUPPLEMENT_BUDGET, itemCaches, ensureItemsCache, FUZZY_EXTRACTION_PROMPT, EXACT_EXTRACTION_PROMPT;
|
|
14266
14313
|
var init_prefilter = __esm({
|
|
14267
14314
|
"ee/agentic-retrieval/pipeline/prefilter.ts"() {
|
|
14268
14315
|
"use strict";
|
|
@@ -14272,6 +14319,8 @@ var init_prefilter = __esm({
|
|
|
14272
14319
|
init_micro_call();
|
|
14273
14320
|
init_text_utils();
|
|
14274
14321
|
init_config3();
|
|
14322
|
+
SUPPLEMENT_MIN_TOKEN_LENGTH = 4;
|
|
14323
|
+
SUPPLEMENT_BUDGET = 15;
|
|
14275
14324
|
itemCaches = {};
|
|
14276
14325
|
ensureItemsCache = async ({
|
|
14277
14326
|
cacheKey,
|
|
@@ -14281,12 +14330,21 @@ var init_prefilter = __esm({
|
|
|
14281
14330
|
}) => {
|
|
14282
14331
|
if (!itemCaches[cacheKey] || Date.now() - itemCaches[cacheKey].tsp.getTime() > 5 * 60 * 1e3 || itemCaches[cacheKey].items.length === 0) {
|
|
14283
14332
|
const result = await context.getItems({ fields, filters: [] });
|
|
14284
|
-
const normalizedItems = result.map((item) =>
|
|
14285
|
-
|
|
14286
|
-
|
|
14287
|
-
|
|
14288
|
-
|
|
14289
|
-
|
|
14333
|
+
const normalizedItems = result.map((item) => {
|
|
14334
|
+
const normalized = normalize(item);
|
|
14335
|
+
return {
|
|
14336
|
+
name: item.name,
|
|
14337
|
+
id: item.id,
|
|
14338
|
+
external_id: item.external_id,
|
|
14339
|
+
normalized,
|
|
14340
|
+
// Separator-free form used only by the supplementary pass in
|
|
14341
|
+
// fuzzyPrefilter. Deliberately NOT added to the Fuse index or keys:
|
|
14342
|
+
// changing what Fuse scores reshuffles which items win the result cap,
|
|
14343
|
+
// which cost 22 regressions against 6 improvements when measured over
|
|
14344
|
+
// positively-rated production cases.
|
|
14345
|
+
stripped: stripSeparators(normalized ?? item.name ?? "")
|
|
14346
|
+
};
|
|
14347
|
+
});
|
|
14290
14348
|
itemCaches[cacheKey] = {
|
|
14291
14349
|
cacheKey,
|
|
14292
14350
|
items: normalizedItems,
|
|
@@ -17379,7 +17437,7 @@ init_field_allow_list();
|
|
|
17379
17437
|
init_apply_filters();
|
|
17380
17438
|
init_singleton();
|
|
17381
17439
|
init_client();
|
|
17382
|
-
|
|
17440
|
+
init_hydrate_embedders();
|
|
17383
17441
|
init_parse_embedding_models();
|
|
17384
17442
|
var itemsPaginationRequest = async ({
|
|
17385
17443
|
db: db2,
|
|
@@ -17669,7 +17727,7 @@ function createQueries(table, tools, contexts) {
|
|
|
17669
17727
|
if (!exists) {
|
|
17670
17728
|
throw new Error("Context " + table.id + " not found in registry.");
|
|
17671
17729
|
}
|
|
17672
|
-
const info = await
|
|
17730
|
+
const info = await contextEmbedderInfoFor(exists);
|
|
17673
17731
|
let dimensionality = null;
|
|
17674
17732
|
let effectiveModelUnavailable = false;
|
|
17675
17733
|
if (info.effectiveModel) {
|
|
@@ -19444,7 +19502,7 @@ function createMutations(table, contexts, tools, config) {
|
|
|
19444
19502
|
willEmbedOnQueue: (c) => willEmbedOnQueue(c, queue)
|
|
19445
19503
|
});
|
|
19446
19504
|
return {
|
|
19447
|
-
info: await
|
|
19505
|
+
info: await contextEmbedderInfoFor(ctx),
|
|
19448
19506
|
rebuild: result.case,
|
|
19449
19507
|
itemsQueued: result.items
|
|
19450
19508
|
};
|
|
@@ -20148,6 +20206,18 @@ async function recallMemories({ agent, contexts, query, user, db: db2, previousU
|
|
|
20148
20206
|
return { collector, memoryItems: chunks, promptBlock: buildMemoryPromptBlock(collector.list()) };
|
|
20149
20207
|
}
|
|
20150
20208
|
|
|
20209
|
+
// src/exulu/public-surface.ts
|
|
20210
|
+
init_cjs_shims();
|
|
20211
|
+
var PUBLIC_SURFACE_HEADER = "x-public-surface";
|
|
20212
|
+
function isPublicSurface(req) {
|
|
20213
|
+
const raw = req?.headers?.[PUBLIC_SURFACE_HEADER];
|
|
20214
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
20215
|
+
return value === "1" || value === "true";
|
|
20216
|
+
}
|
|
20217
|
+
function treatAsGuest(req, user) {
|
|
20218
|
+
return isPublicSurface(req) || !user?.id;
|
|
20219
|
+
}
|
|
20220
|
+
|
|
20151
20221
|
// src/exulu/generate-stream.ts
|
|
20152
20222
|
init_decisions();
|
|
20153
20223
|
|
|
@@ -20384,7 +20454,8 @@ var generateSync = async ({
|
|
|
20384
20454
|
}
|
|
20385
20455
|
const { db: memoryDb } = await postgresClient();
|
|
20386
20456
|
const currentAsUiMessage = { id: "current", role: "user", parts: query ? [{ type: "text", text: query }] : [] };
|
|
20387
|
-
const
|
|
20457
|
+
const recallUser = isPublicSurface(req) ? void 0 : user;
|
|
20458
|
+
const memoryRecall = await recallMemories({ agent, contexts, query, user: recallUser, db: memoryDb, previousUserTurns: previousUserTexts([...messages, currentAsUiMessage]) });
|
|
20388
20459
|
const memoryContext = memoryRecall.promptBlock;
|
|
20389
20460
|
const memoryItems = memoryRecall.memoryItems;
|
|
20390
20461
|
const personalizationInformation = exuluConfig?.privacy?.systemPromptPersonalization !== false ? `
|
|
@@ -20723,7 +20794,8 @@ var generateStream = async ({
|
|
|
20723
20794
|
});
|
|
20724
20795
|
}
|
|
20725
20796
|
const { db: memoryDb } = await postgresClient();
|
|
20726
|
-
const
|
|
20797
|
+
const recallUser = isPublicSurface(req) ? void 0 : user;
|
|
20798
|
+
const memoryRecall = await recallMemories({ agent, contexts, query, user: recallUser, db: memoryDb, previousUserTurns: previousUserTexts(messages) });
|
|
20727
20799
|
const memoryContext = memoryRecall.promptBlock;
|
|
20728
20800
|
const memoryItems = memoryRecall.memoryItems;
|
|
20729
20801
|
messages = messages.filter(
|
|
@@ -21127,6 +21199,7 @@ var getEnabledTools = async (agent, allExuluTools, allContexts, disabledTools =
|
|
|
21127
21199
|
// ee/workers.ts
|
|
21128
21200
|
init_storage();
|
|
21129
21201
|
init_context();
|
|
21202
|
+
init_hydrate_embedders();
|
|
21130
21203
|
init_resolve_model();
|
|
21131
21204
|
init_client();
|
|
21132
21205
|
init_prune_job_results();
|
|
@@ -21868,6 +21941,10 @@ var createWorkers = async (queues2, config, contexts, evals, tools, tracer) => {
|
|
|
21868
21941
|
if (!context) {
|
|
21869
21942
|
throw new Error(`Context ${data.context} not found in the registry.`);
|
|
21870
21943
|
}
|
|
21944
|
+
try {
|
|
21945
|
+
await refreshContextEmbeddersIfStale(contexts);
|
|
21946
|
+
} catch {
|
|
21947
|
+
}
|
|
21871
21948
|
if (!context.embedder) {
|
|
21872
21949
|
throw new Error(`No embedder configured for context ${data.context}.`);
|
|
21873
21950
|
}
|
|
@@ -31063,7 +31140,9 @@ ${customInstructions}` : agent.instructions,
|
|
|
31063
31140
|
if (part.type === "finish") {
|
|
31064
31141
|
return {
|
|
31065
31142
|
...finishTurnMetadata({ totalUsage: part.totalUsage, startedAt: turnStartedAt }),
|
|
31066
|
-
|
|
31143
|
+
// The public surface is a guest surface even for a signed-in visitor:
|
|
31144
|
+
// the page renders in guest mode, so the data has to follow.
|
|
31145
|
+
...recalledMemoriesMetadata({ recall: result.recall, agent, isGuest: treatAsGuest(req, user) })
|
|
31067
31146
|
};
|
|
31068
31147
|
}
|
|
31069
31148
|
return void 0;
|
package/dist/index.js
CHANGED
|
@@ -67,6 +67,7 @@ import {
|
|
|
67
67
|
clearEmbedderSetting,
|
|
68
68
|
codeEmbedderFor,
|
|
69
69
|
collectMemoryDecisions,
|
|
70
|
+
contextEmbedderInfoFor,
|
|
70
71
|
contextOccupancy,
|
|
71
72
|
convertContextToTableDefinition,
|
|
72
73
|
convertExuluToolsToAiSdkTools,
|
|
@@ -143,8 +144,8 @@ import {
|
|
|
143
144
|
provisionDefaultUserBudget,
|
|
144
145
|
randomizedPCA,
|
|
145
146
|
readProjectionRow,
|
|
147
|
+
refreshContextEmbeddersIfStale,
|
|
146
148
|
reportSystemDependencies,
|
|
147
|
-
resolveContextEmbedder,
|
|
148
149
|
resolveEmbedder,
|
|
149
150
|
resolveEntityModel,
|
|
150
151
|
resolveLiteLLMConfigPath,
|
|
@@ -180,7 +181,7 @@ import {
|
|
|
180
181
|
willEmbedOnQueue,
|
|
181
182
|
withRetry,
|
|
182
183
|
workflowTemplatesSchema
|
|
183
|
-
} from "./chunk-
|
|
184
|
+
} from "./chunk-37MKZIH2.js";
|
|
184
185
|
import {
|
|
185
186
|
LiteLLMAdminError,
|
|
186
187
|
findLiteLLMModel,
|
|
@@ -1509,7 +1510,7 @@ function createQueries(table, tools, contexts) {
|
|
|
1509
1510
|
if (!exists) {
|
|
1510
1511
|
throw new Error("Context " + table.id + " not found in registry.");
|
|
1511
1512
|
}
|
|
1512
|
-
const info = await
|
|
1513
|
+
const info = await contextEmbedderInfoFor(exists);
|
|
1513
1514
|
let dimensionality = null;
|
|
1514
1515
|
let effectiveModelUnavailable = false;
|
|
1515
1516
|
if (info.effectiveModel) {
|
|
@@ -3234,7 +3235,7 @@ function createMutations(table, contexts, tools, config) {
|
|
|
3234
3235
|
willEmbedOnQueue: (c) => willEmbedOnQueue(c, queue)
|
|
3235
3236
|
});
|
|
3236
3237
|
return {
|
|
3237
|
-
info: await
|
|
3238
|
+
info: await contextEmbedderInfoFor(ctx),
|
|
3238
3239
|
rebuild: result.case,
|
|
3239
3240
|
itemsQueued: result.items
|
|
3240
3241
|
};
|
|
@@ -3878,6 +3879,17 @@ async function recallMemories({ agent, contexts, query, user, db, previousUserTu
|
|
|
3878
3879
|
return { collector, memoryItems: chunks, promptBlock: buildMemoryPromptBlock(collector.list()) };
|
|
3879
3880
|
}
|
|
3880
3881
|
|
|
3882
|
+
// src/exulu/public-surface.ts
|
|
3883
|
+
var PUBLIC_SURFACE_HEADER = "x-public-surface";
|
|
3884
|
+
function isPublicSurface(req) {
|
|
3885
|
+
const raw = req?.headers?.[PUBLIC_SURFACE_HEADER];
|
|
3886
|
+
const value = Array.isArray(raw) ? raw[0] : raw;
|
|
3887
|
+
return value === "1" || value === "true";
|
|
3888
|
+
}
|
|
3889
|
+
function treatAsGuest(req, user) {
|
|
3890
|
+
return isPublicSurface(req) || !user?.id;
|
|
3891
|
+
}
|
|
3892
|
+
|
|
3881
3893
|
// src/exulu/memory/usage.ts
|
|
3882
3894
|
function usageRows(input) {
|
|
3883
3895
|
const memories = input.recall?.list() ?? [];
|
|
@@ -4110,7 +4122,8 @@ var generateSync = async ({
|
|
|
4110
4122
|
}
|
|
4111
4123
|
const { db: memoryDb } = await postgresClient();
|
|
4112
4124
|
const currentAsUiMessage = { id: "current", role: "user", parts: query ? [{ type: "text", text: query }] : [] };
|
|
4113
|
-
const
|
|
4125
|
+
const recallUser = isPublicSurface(req) ? void 0 : user;
|
|
4126
|
+
const memoryRecall = await recallMemories({ agent, contexts, query, user: recallUser, db: memoryDb, previousUserTurns: previousUserTexts([...messages, currentAsUiMessage]) });
|
|
4114
4127
|
const memoryContext = memoryRecall.promptBlock;
|
|
4115
4128
|
const memoryItems = memoryRecall.memoryItems;
|
|
4116
4129
|
const personalizationInformation = exuluConfig?.privacy?.systemPromptPersonalization !== false ? `
|
|
@@ -4449,7 +4462,8 @@ var generateStream = async ({
|
|
|
4449
4462
|
});
|
|
4450
4463
|
}
|
|
4451
4464
|
const { db: memoryDb } = await postgresClient();
|
|
4452
|
-
const
|
|
4465
|
+
const recallUser = isPublicSurface(req) ? void 0 : user;
|
|
4466
|
+
const memoryRecall = await recallMemories({ agent, contexts, query, user: recallUser, db: memoryDb, previousUserTurns: previousUserTexts(messages) });
|
|
4453
4467
|
const memoryContext = memoryRecall.promptBlock;
|
|
4454
4468
|
const memoryItems = memoryRecall.memoryItems;
|
|
4455
4469
|
messages = messages.filter(
|
|
@@ -5568,6 +5582,10 @@ var createWorkers = async (queues2, config, contexts, evals, tools, tracer) => {
|
|
|
5568
5582
|
if (!context) {
|
|
5569
5583
|
throw new Error(`Context ${data.context} not found in the registry.`);
|
|
5570
5584
|
}
|
|
5585
|
+
try {
|
|
5586
|
+
await refreshContextEmbeddersIfStale(contexts);
|
|
5587
|
+
} catch {
|
|
5588
|
+
}
|
|
5571
5589
|
if (!context.embedder) {
|
|
5572
5590
|
throw new Error(`No embedder configured for context ${data.context}.`);
|
|
5573
5591
|
}
|
|
@@ -14590,7 +14608,9 @@ ${customInstructions}` : agent.instructions,
|
|
|
14590
14608
|
if (part.type === "finish") {
|
|
14591
14609
|
return {
|
|
14592
14610
|
...finishTurnMetadata({ totalUsage: part.totalUsage, startedAt: turnStartedAt }),
|
|
14593
|
-
|
|
14611
|
+
// The public surface is a guest surface even for a signed-in visitor:
|
|
14612
|
+
// the page renders in guest mode, so the data has to follow.
|
|
14613
|
+
...recalledMemoriesMetadata({ recall: result.recall, agent, isGuest: treatAsGuest(req, user) })
|
|
14594
14614
|
};
|
|
14595
14615
|
}
|
|
14596
14616
|
return void 0;
|
|
@@ -46,6 +46,129 @@ describe("fuzzyPrefilter", () => {
|
|
|
46
46
|
});
|
|
47
47
|
});
|
|
48
48
|
|
|
49
|
+
describe("fuzzyPrefilter separator handling", () => {
|
|
50
|
+
// Real NEWLIFT shape: the FST-2XT *handbooks* spell the product without a
|
|
51
|
+
// hyphen (hb_FST2XT-XTs_...), while brochures and certificates spell it with
|
|
52
|
+
// one. A question says "FST-2XT", so that is what the extractor emits. With
|
|
53
|
+
// more hyphenated files than the 30-result cap, an unhyphenated handbook has
|
|
54
|
+
// to survive the rescorer's match-ratio penalty to be pinned at all.
|
|
55
|
+
const decoys = Array.from({ length: 34 }, (_, i) => ({
|
|
56
|
+
id: `br${i}`,
|
|
57
|
+
name: `br_FST-2XT_brochure_${i}.pdf`,
|
|
58
|
+
external_id: `/b/br_FST-2XT_brochure_${i}.pdf`,
|
|
59
|
+
}));
|
|
60
|
+
const handbook = {
|
|
61
|
+
id: "hb",
|
|
62
|
+
name: "hb_FST2XT-XTs_2017-11_de.pdf",
|
|
63
|
+
external_id: "/b/hb_FST2XT-XTs_2017-11_de.pdf",
|
|
64
|
+
};
|
|
65
|
+
const newliftCtx = { id: "tech", getItems: jest.fn(async () => [...decoys, handbook]) };
|
|
66
|
+
|
|
67
|
+
it("pins an unhyphenated handbook despite a hyphenated identifier and a full result cap", async () => {
|
|
68
|
+
const r = await fuzzyPrefilter({
|
|
69
|
+
cacheKey: "sep1", relevantKeywords: ["FST-2XT"], context: newliftCtx,
|
|
70
|
+
fields: ["name", "id", "external_id"], normalize: (i) => i.external_id,
|
|
71
|
+
supplementSeparatorVariants: true,
|
|
72
|
+
});
|
|
73
|
+
expect(r.map((x) => x.id)).toContain("hb");
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe("fuzzyPrefilter supplement ordering", () => {
|
|
78
|
+
// `normalized` carries the whole storage path, and NEWLIFT files the product's
|
|
79
|
+
// documents under a `/FST/FST-2XT/` folder — so every unrelated file in that
|
|
80
|
+
// folder matches the identifier just as well as the handbook does. Taking the
|
|
81
|
+
// supplement in corpus order therefore fills the budget with incidental files
|
|
82
|
+
// (observed in production: Bosch-FWMaterialfahrt.pdf, spsrules.txt) and drops
|
|
83
|
+
// the handbook. A filename match has to outrank a path-only match.
|
|
84
|
+
const brochures = Array.from({ length: 34 }, (_, i) => ({
|
|
85
|
+
id: `br${i}`,
|
|
86
|
+
name: `br_FST-2XT_brochure_${i}.pdf`,
|
|
87
|
+
external_id: `/Techdoc/FST/FST-2XT/br_FST-2XT_brochure_${i}.pdf`,
|
|
88
|
+
}));
|
|
89
|
+
const pathOnly = Array.from({ length: 25 }, (_, i) => ({
|
|
90
|
+
id: `path${i}`,
|
|
91
|
+
name: `unrelated_doc_${i}.pdf`,
|
|
92
|
+
external_id: `/Techdoc/FST/FST-2XT/unrelated_doc_${i}.pdf`,
|
|
93
|
+
}));
|
|
94
|
+
const handbook = {
|
|
95
|
+
id: "hb",
|
|
96
|
+
name: "hb_FST2XT-XTs_2017-11_de.pdf",
|
|
97
|
+
external_id: "/Techdoc/FST/FST-2XT/hb_FST2XT-XTs_2017-11_de.pdf",
|
|
98
|
+
};
|
|
99
|
+
// handbook last, so only relevance ordering can keep it within the budget
|
|
100
|
+
const ctxRel = {
|
|
101
|
+
id: "tech",
|
|
102
|
+
getItems: jest.fn(async () => [...brochures, ...pathOnly, handbook]),
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
it("prefers a filename match over path-only matches when the budget is tight", async () => {
|
|
106
|
+
const r = await fuzzyPrefilter({
|
|
107
|
+
cacheKey: "ord1", relevantKeywords: ["FST-2XT"], context: ctxRel,
|
|
108
|
+
fields: ["name", "id", "external_id"], normalize: (i) => i.external_id,
|
|
109
|
+
supplementSeparatorVariants: true,
|
|
110
|
+
});
|
|
111
|
+
expect(r.map((x) => x.id)).toContain("hb");
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
describe("fuzzyPrefilter supplement scope and degenerate corpora", () => {
|
|
116
|
+
const brochures = Array.from({ length: 34 }, (_, i) => ({
|
|
117
|
+
id: `br${i}`,
|
|
118
|
+
name: `br_FST-2XT_brochure_${i}.pdf`,
|
|
119
|
+
external_id: `/Techdoc/FST/FST-2XT/br_FST-2XT_brochure_${i}.pdf`,
|
|
120
|
+
}));
|
|
121
|
+
const handbook = {
|
|
122
|
+
id: "hb",
|
|
123
|
+
name: "hb_FST2XT-XTs_2017-11_de.pdf",
|
|
124
|
+
external_id: "/Techdoc/FST/FST-2XT/hb_FST2XT-XTs_2017-11_de.pdf",
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
it("leaves the result untouched unless the caller opts in", async () => {
|
|
128
|
+
// The conversations keyword prefilter (search.ts) matches ticket text, not
|
|
129
|
+
// filenames, so it must not inherit filename-shaped supplementing.
|
|
130
|
+
const ctxNoOptIn = { id: "tech", getItems: jest.fn(async () => [...brochures, handbook]) };
|
|
131
|
+
const r = await fuzzyPrefilter({
|
|
132
|
+
cacheKey: "noopt", relevantKeywords: ["FST-2XT"], context: ctxNoOptIn,
|
|
133
|
+
fields: ["name", "id", "external_id"], normalize: (i) => i.external_id,
|
|
134
|
+
});
|
|
135
|
+
expect(r).toHaveLength(30);
|
|
136
|
+
expect(r.map((x) => x.id)).not.toContain("hb");
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it("adds nothing when external_id carries no filename text", async () => {
|
|
140
|
+
// Other tenants store an opaque id (uuid / int / "9998-31938") instead of a
|
|
141
|
+
// path, so there is nothing for a separator-free token to match.
|
|
142
|
+
const opaque = [
|
|
143
|
+
...brochures.map((b, i) => ({ ...b, external_id: `550e8400-e29b-41d4-a716-${String(i).padStart(12, "0")}` })),
|
|
144
|
+
{ ...handbook, external_id: "550e8400-e29b-41d4-a716-446655449999" },
|
|
145
|
+
];
|
|
146
|
+
const ctxOpaque = { id: "tickets", getItems: jest.fn(async () => opaque) };
|
|
147
|
+
const r = await fuzzyPrefilter({
|
|
148
|
+
cacheKey: "opaque", relevantKeywords: ["FST-2XT"], context: ctxOpaque,
|
|
149
|
+
fields: ["name", "id", "external_id"], normalize: (i) => i.external_id,
|
|
150
|
+
supplementSeparatorVariants: true,
|
|
151
|
+
});
|
|
152
|
+
// no crash, and the opaque corpus yields no separator-variant candidates
|
|
153
|
+
expect(r.length).toBeLessThanOrEqual(30);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("survives items with no name at all", async () => {
|
|
157
|
+
const nameless = [
|
|
158
|
+
...brochures,
|
|
159
|
+
{ id: "nameless", name: undefined as any, external_id: "/Techdoc/FST/FST-2XT/x.pdf" },
|
|
160
|
+
];
|
|
161
|
+
const ctxNameless = { id: "tech", getItems: jest.fn(async () => nameless) };
|
|
162
|
+
await expect(
|
|
163
|
+
fuzzyPrefilter({
|
|
164
|
+
cacheKey: "nameless", relevantKeywords: ["FST-2XT"], context: ctxNameless,
|
|
165
|
+
fields: ["name", "id", "external_id"], normalize: (i) => i.external_id,
|
|
166
|
+
supplementSeparatorVariants: true,
|
|
167
|
+
}),
|
|
168
|
+
).resolves.toBeDefined();
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
49
172
|
describe("resolveIdentifierPins", () => {
|
|
50
173
|
it("runs one extraction call per identifier set and routes pins to the set's contexts", async () => {
|
|
51
174
|
(generateText as jest.Mock).mockResolvedValue({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Fuse from "fuse.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { microCall } from "./micro-call";
|
|
4
|
-
import { normalizeFileName } from "./text-utils";
|
|
4
|
+
import { normalizeFileName, stripSeparators } from "./text-utils";
|
|
5
5
|
import { DEFAULT_PREFILTER_CUTOFF, type IdentifierSet, type KbKind } from "./config";
|
|
6
6
|
import type { PhaseStep } from "./types";
|
|
7
7
|
|
|
@@ -17,11 +17,17 @@ export type PrefilteredResult = {
|
|
|
17
17
|
|
|
18
18
|
type ItemsCache = {
|
|
19
19
|
fuseIndex: any;
|
|
20
|
-
items: { name?: string; id?: string; external_id?: string; normalized?: string }[];
|
|
20
|
+
items: { name?: string; id?: string; external_id?: string; normalized?: string; stripped?: string }[];
|
|
21
21
|
tsp: Date;
|
|
22
22
|
cacheKey: string;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
/** Shortest separator-free token eligible for the supplementary pass. Below
|
|
26
|
+
* this, a token matches too much of the corpus to be a useful pin. */
|
|
27
|
+
const SUPPLEMENT_MIN_TOKEN_LENGTH = 4;
|
|
28
|
+
/** Most items the supplementary pass may add on top of the primary result. */
|
|
29
|
+
const SUPPLEMENT_BUDGET = 15;
|
|
30
|
+
|
|
25
31
|
// ---------------------------------------------------------------------------
|
|
26
32
|
// Cache
|
|
27
33
|
// ---------------------------------------------------------------------------
|
|
@@ -50,12 +56,21 @@ const ensureItemsCache = async ({
|
|
|
50
56
|
) {
|
|
51
57
|
const result = await context.getItems({ fields, filters: [] });
|
|
52
58
|
|
|
53
|
-
const normalizedItems = result.map((item: any) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
+
const normalizedItems = result.map((item: any) => {
|
|
60
|
+
const normalized = normalize(item);
|
|
61
|
+
return {
|
|
62
|
+
name: item.name,
|
|
63
|
+
id: item.id,
|
|
64
|
+
external_id: item.external_id,
|
|
65
|
+
normalized,
|
|
66
|
+
// Separator-free form used only by the supplementary pass in
|
|
67
|
+
// fuzzyPrefilter. Deliberately NOT added to the Fuse index or keys:
|
|
68
|
+
// changing what Fuse scores reshuffles which items win the result cap,
|
|
69
|
+
// which cost 22 regressions against 6 improvements when measured over
|
|
70
|
+
// positively-rated production cases.
|
|
71
|
+
stripped: stripSeparators(normalized ?? item.name ?? ""),
|
|
72
|
+
};
|
|
73
|
+
});
|
|
59
74
|
|
|
60
75
|
itemCaches[cacheKey] = {
|
|
61
76
|
cacheKey,
|
|
@@ -137,6 +152,7 @@ export async function fuzzyPrefilter({
|
|
|
137
152
|
normalize,
|
|
138
153
|
cutoff = DEFAULT_PREFILTER_CUTOFF,
|
|
139
154
|
limit,
|
|
155
|
+
supplementSeparatorVariants = false,
|
|
140
156
|
}: {
|
|
141
157
|
cacheKey: string;
|
|
142
158
|
relevantKeywords: string[];
|
|
@@ -146,6 +162,15 @@ export async function fuzzyPrefilter({
|
|
|
146
162
|
normalize: (item: any) => string | undefined;
|
|
147
163
|
cutoff?: number;
|
|
148
164
|
limit?: number;
|
|
165
|
+
/**
|
|
166
|
+
* Opt in to the separator-insensitive supplement below. Only meaningful when
|
|
167
|
+
* `normalize` yields FILENAME-ish text: it exists because a hyphenated
|
|
168
|
+
* identifier scores badly against an unhyphenated filename. Callers that
|
|
169
|
+
* normalize to prose — the conversations keyword prefilter joins a ticket's
|
|
170
|
+
* name and description — get nothing useful from it, so it stays off by
|
|
171
|
+
* default rather than silently widening every prefilter in the pipeline.
|
|
172
|
+
*/
|
|
173
|
+
supplementSeparatorVariants?: boolean;
|
|
149
174
|
}): Promise<PrefilteredResult[]> {
|
|
150
175
|
const cache = await ensureItemsCache({ cacheKey, context, fields, normalize });
|
|
151
176
|
|
|
@@ -264,6 +289,82 @@ export async function fuzzyPrefilter({
|
|
|
264
289
|
id: result.item.id,
|
|
265
290
|
}));
|
|
266
291
|
|
|
292
|
+
// ---------------------------------------------------------------------
|
|
293
|
+
// Supplementary separator-insensitive pass
|
|
294
|
+
// ---------------------------------------------------------------------
|
|
295
|
+
// Fuse scores an identifier's punctuation, not just its letters: "FST-2XT"
|
|
296
|
+
// scores ~0.0001 against `br_FST-2XT_2019-10_de.pdf` but ~0.02 against
|
|
297
|
+
// `hb_FST2XT-XTs_2017-11_de.pdf`. NEWLIFT's brochures carry the hyphen and
|
|
298
|
+
// its handbooks do not, so the brochures filled the cap above and the
|
|
299
|
+
// handbooks — which hold the error-code tables — were dropped entirely.
|
|
300
|
+
// Because identifier pins are a hard id-whitelist rather than a boost, that
|
|
301
|
+
// made their content unreachable no matter how the model phrased the query.
|
|
302
|
+
//
|
|
303
|
+
// This pass is strictly ADDITIVE: it never reorders or displaces a primary
|
|
304
|
+
// hit, so no pin that resolved before can be lost. Only tokens that actually
|
|
305
|
+
// CONTAIN a separator can be mismatched this way, so only those are
|
|
306
|
+
// supplemented — a plain token like "FST" is already scored correctly and
|
|
307
|
+
// supplementing it would match most of the corpus.
|
|
308
|
+
const supplementTokens = !supplementSeparatorVariants
|
|
309
|
+
? []
|
|
310
|
+
: [
|
|
311
|
+
...new Set(
|
|
312
|
+
uniqueKeywords
|
|
313
|
+
.filter((k) => /[-_.]/.test(k))
|
|
314
|
+
.map((k) => stripSeparators(k))
|
|
315
|
+
.filter((t) => t.length >= SUPPLEMENT_MIN_TOKEN_LENGTH),
|
|
316
|
+
),
|
|
317
|
+
].sort((a, b) => b.length - a.length); // most specific first
|
|
318
|
+
|
|
319
|
+
if (supplementTokens.length > 0) {
|
|
320
|
+
const seen = new Set(prefiltered.map((p) => p.id));
|
|
321
|
+
// `normalized` is the full storage path, and NEWLIFT files a product's
|
|
322
|
+
// documents under a folder named after it (`/FST/FST-2XT/...`), so every
|
|
323
|
+
// incidental file in that folder matches the identifier as well as the
|
|
324
|
+
// handbook does. Rank a match in the FILENAME above a path-only match, then
|
|
325
|
+
// prefer the shorter name (the more specific document), before falling back
|
|
326
|
+
// to corpus order — otherwise the budget fills with whatever happens to be
|
|
327
|
+
// stored alongside.
|
|
328
|
+
const candidates = cache.items
|
|
329
|
+
.filter(
|
|
330
|
+
(item) =>
|
|
331
|
+
item.id &&
|
|
332
|
+
!seen.has(item.id) &&
|
|
333
|
+
supplementTokens.some((t) => (item.stripped ?? "").includes(t)),
|
|
334
|
+
)
|
|
335
|
+
.map((item, idx) => {
|
|
336
|
+
const nameStripped = stripSeparators(item.name ?? "");
|
|
337
|
+
return {
|
|
338
|
+
item,
|
|
339
|
+
idx,
|
|
340
|
+
nameMatch: supplementTokens.some((t) => nameStripped.includes(t)) ? 0 : 1,
|
|
341
|
+
nameLength: (item.name ?? "").length,
|
|
342
|
+
};
|
|
343
|
+
})
|
|
344
|
+
.sort(
|
|
345
|
+
(a, b) =>
|
|
346
|
+
a.nameMatch - b.nameMatch || a.nameLength - b.nameLength || a.idx - b.idx,
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const supplement: PrefilteredResult[] = [];
|
|
350
|
+
for (const { item } of candidates) {
|
|
351
|
+
if (supplement.length >= SUPPLEMENT_BUDGET) break;
|
|
352
|
+
if (!item.id || seen.has(item.id)) continue;
|
|
353
|
+
seen.add(item.id);
|
|
354
|
+
supplement.push({
|
|
355
|
+
key: item.external_id ?? item.id,
|
|
356
|
+
name: item.name ?? item.external_id ?? item.id,
|
|
357
|
+
id: item.id,
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (supplement.length > 0) {
|
|
361
|
+
console.log(
|
|
362
|
+
`[EXULU pipeline] fuzzyPrefilter: +${supplement.length} separator-insensitive supplement(s) for [${supplementTokens.join(", ")}]`,
|
|
363
|
+
);
|
|
364
|
+
prefiltered.push(...supplement);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
|
|
267
368
|
console.log(
|
|
268
369
|
`[EXULU pipeline] fuzzyPrefilter: ${prefiltered.length} result(s) for [${uniqueKeywords.join(", ")}]`,
|
|
269
370
|
);
|
|
@@ -352,6 +453,9 @@ export async function resolveIdentifierPins({
|
|
|
352
453
|
...common,
|
|
353
454
|
relevantKeywords: output.matches!,
|
|
354
455
|
cutoff: DEFAULT_PREFILTER_CUTOFF,
|
|
456
|
+
// Identifier pins are a hard id-whitelist over filenames,
|
|
457
|
+
// which is exactly the case the supplement exists for.
|
|
458
|
+
supplementSeparatorVariants: true,
|
|
355
459
|
});
|
|
356
460
|
if (!matched.length) return;
|
|
357
461
|
const target = pinsByContext.get(ctxId) ?? new Set<string>();
|
package/ee/workers.ts
CHANGED
|
@@ -10,6 +10,7 @@ import { ExuluStorage } from "@SRC/exulu/storage.ts";
|
|
|
10
10
|
import type { ExuluAgent } from "@EXULU_TYPES/models/agent.ts";
|
|
11
11
|
import type { ExuluQueueConfig } from "@EXULU_TYPES/queue-config.ts";
|
|
12
12
|
import { getTableName, type ExuluContext } from "@SRC/exulu/context.ts";
|
|
13
|
+
import { refreshContextEmbeddersIfStale } from "@SRC/exulu/hydrate-embedders";
|
|
13
14
|
import type { ExuluEval } from "@SRC/exulu/evals.ts";
|
|
14
15
|
import type { ExuluTool } from "@SRC/exulu/tool.ts";
|
|
15
16
|
import { resolveModel } from "@SRC/exulu/resolve-model.ts";
|
|
@@ -311,6 +312,21 @@ export const createWorkers = async (
|
|
|
311
312
|
throw new Error(`Context ${data.context} not found in the registry.`);
|
|
312
313
|
}
|
|
313
314
|
|
|
315
|
+
// A context whose embedder is configured in the database rather than
|
|
316
|
+
// declared in code (the framework-provided transcripts base, for one)
|
|
317
|
+
// only gets `embedder` set by hydrateContextEmbedders. This process
|
|
318
|
+
// builds its registry from code and hands it to createWorkers without
|
|
319
|
+
// hydrating, and createAndUpsertEmbeddings' only other caller already
|
|
320
|
+
// refreshes before use — so the embedder job is the one entry point
|
|
321
|
+
// that would otherwise read a context the override never reached, and
|
|
322
|
+
// reject its own queued job with "No embedder configured".
|
|
323
|
+
try {
|
|
324
|
+
await refreshContextEmbeddersIfStale(contexts);
|
|
325
|
+
} catch {
|
|
326
|
+
// Singleton not initialised (e.g. tests, early boot) — the embedder
|
|
327
|
+
// set at construction/boot-hydration still stands.
|
|
328
|
+
}
|
|
329
|
+
|
|
314
330
|
if (!context.embedder) {
|
|
315
331
|
throw new Error(`No embedder configured for context ${data.context}.`);
|
|
316
332
|
}
|