Smarter chatbot + support matching by meaning (Marty 2026-11-16): the hub's semantic match (free core2 embeddings)
Chatbot (chatbot.js + netkb.js route): a hand-off pattern still answers first; then the hub's POST /v1/kb/match answers with this site's entry when it is sure, keeps or overrules the CANNED regex hit, and picks the AI prompt context, this site's own entries first. 1.5 s timeout, then the hub is skipped for 30 s and the old pattern + BM25 path answers (NETKB_MATCH=0 = off). Support desk: while a signed-in member types a new ticket, POST /api/my/support/suggest shows the closest help answers (KB entries only, incl. ones written from past tickets, never another member's ticket; BM25 when the hub is down); Send is never blocked. help-screen.js?v=20261116sg. Tests: qa/netkb-semantic.test.mjs (route/suggest decisions, fail soft, shared-file parity; run.sh kb) and qa/support-suggest.mjs (run.sh member). netkb.js is the same file in all eight network sites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+10
-4
@@ -292,23 +292,29 @@ async function answerRaw(message, historyText) {
|
||||
const msg = String(message || '').trim();
|
||||
if (!msg) return { error: 'Say something first.' };
|
||||
// fast path: the knowledge base's instant answers (seeded from CANNED); the in-code list only if the KB store is down
|
||||
let hit = null, kbOk = true;
|
||||
let hit = null, kbOk = true, other = [];
|
||||
try {
|
||||
await kb.load();
|
||||
// another network site named (and this one not): this site's instant answers stand aside, except a hand-off (2026-11-15)
|
||||
const other = /link ?spin/i.test(msg) ? [] : kb.namesOther(msg, process.env.HUB_SITE || 'linkspin');
|
||||
other = /link ?spin/i.test(msg) ? [] : kb.namesOther(msg, process.env.HUB_SITE || 'linkspin');
|
||||
hit = await kb.fastPath(msg);
|
||||
if (hit && other.length && !hit.handoff) hit = null;
|
||||
} catch (e) { kbOk = false; console.error('kb fast path', e.message); }
|
||||
// a hand-off answers from its exact pattern before anything else; then meaning (2026-11-16, netkb.route): the hub's semantic match
|
||||
// over the network KB answers, keeps or overrules the pattern hit and picks the prompt context. Hub or model slow or down: null,
|
||||
// and the pattern + BM25 path below runs exactly as before.
|
||||
let sem = null;
|
||||
if (kbOk && !(hit && hit.handoff)) { try { sem = await netkb.route(msg, { fast: hit, own: await kb.own(), prefer: other }); } catch (e) { sem = null; } }
|
||||
if (sem) hit = sem.hit;
|
||||
if (hit && hit.id === 'refuel' && !REFUEL_ON()) return { reply: REFUEL_OFF_ANSWER, canned: true, kb: hit.id };
|
||||
if (hit && (hit.id === 'network-rate' || hit.id === 'c-network-rate') && (SYN_N() !== 4 || SYN_T() !== 10)) return { reply: netRateAnswer(SYN_N()), canned: true, kb: hit.id };
|
||||
if (hit) return Object.assign({ reply: hit.answer, canned: true, kb: hit.id }, hit.handoff ? { handoff: true } : {});
|
||||
if (hit) return Object.assign({ reply: hit.answer, canned: true, kb: hit.id }, sem ? { via: sem.via } : {}, hit.handoff ? { handoff: true } : {});
|
||||
if (!kbOk) for (const c of CANNED) if (c.re.test(msg)) return c.id === 'refuel' && !REFUEL_ON() ? { reply: REFUEL_OFF_ANSWER, canned: true } : c.id === 'network-rate' && (SYN_N() !== 4 || SYN_T() !== 10) ? { reply: netRateAnswer(SYN_N()), canned: true } : Object.assign({ reply: c.a, canned: true }, c.handoff ? { handoff: true } : {});
|
||||
// retrieval: the closest entries ride along in the system prompt (a short follow-up borrows words from the chat so far)
|
||||
let kbBlock = '', kbIds = [];
|
||||
try {
|
||||
const query = msg.split(/\s+/).length < 4 && historyText ? msg + ' ' + String(historyText).slice(-200) : msg;
|
||||
const hits = await kb.context(query, 5);
|
||||
const hits = sem && sem.hits.length ? sem.hits : await kb.context(query, 5); // the semantic context when the hub answered (2026-11-16)
|
||||
kbBlock = kb.promptBlock(hits); kbIds = hits.map(h => h.entry.id);
|
||||
} catch (e) { console.error('kb search', e.message); }
|
||||
if (!enabled()) return { reply: 'Good question. The quick answers I have cover spin links, pages, zones, packages, the payout split, qualification and joining; for anything deeper, the plain-language contract review at ' + SITE_URL + '/contract covers most of it, or tap "Send this to support" and Marty will answer.', handoff: true };
|
||||
|
||||
Reference in New Issue
Block a user