Smarter chatbot matching by meaning (Marty 2026-11-16): the hub's semantic match (free core2 embeddings)
chatcore.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). netkb.js also has suggest() for the support desk (used by InstantAdPay and LinkSpin). Same chatcore.js in the six rebuilt sites, same netkb.js in all eight. Test: node qa/netkb-semantic.test.mjs (decisions, fail soft, shared-file parity). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+12
-2
@@ -2,6 +2,9 @@
|
||||
// The site's own chatbot.js holds what it knows (CANNED instant answers + FACTS, written from that site's code); this file
|
||||
// holds how it answers, the same on every site:
|
||||
// 1. the knowledge base's instant answers (kb.js, seeded from CANNED; first matching pattern wins, no AI call)
|
||||
// (since 2026-11-16 only a hand-off pattern answers outright; any other pattern hit is checked against step 1b)
|
||||
// 1b. the hub's semantic match by meaning (netkb.route, core2 embeddings): answers with this site's entry when it is sure,
|
||||
// keeps or overrules a pattern hit, and picks the prompt context; fails soft to the old path within NETKB_MATCH_MS
|
||||
// 2. retrieval over the merged NETWORK knowledge base (this site's entries boosted, netkb.js), into the system prompt
|
||||
// 3. OpenRouter (deepseek/deepseek-v4-flash:nitro, reasoning OFF, retried once), house rules in the prompt and on the way out
|
||||
// Account problems go to the network support desk on InstantAdPay (handoff: true makes the widget offer it).
|
||||
@@ -125,12 +128,19 @@ async function answerRaw(message, historyText) {
|
||||
hit = await kb.fastPath(msg);
|
||||
if (hit && other.length && !hit.handoff) hit = null;
|
||||
} catch (e) { kbOk = false; console.error('kb fast path', e.message); }
|
||||
if (hit) return Object.assign({ reply: hit.answer, canned: true, kb: hit.id }, hit.handoff ? { handoff: true } : {});
|
||||
// a hand-off (support, one person's account problem) always answers from its exact pattern, before anything else
|
||||
if (hit && hit.handoff) return { reply: hit.answer, canned: true, kb: hit.id, handoff: true };
|
||||
// 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 as before.
|
||||
let sem = null;
|
||||
if (kbOk) { 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) 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 S.canned) if (c.re && c.re.test(msg)) return Object.assign({ reply: c.a, canned: true }, c.handoff ? { handoff: true } : {});
|
||||
let kbBlock = '', kbIds = [], hits = [];
|
||||
try {
|
||||
const query = msg.split(/\s+/).length < 4 && historyText ? msg + ' ' + String(historyText).slice(-200) : msg;
|
||||
hits = await kb.context(query, 6);
|
||||
hits = sem && sem.hits.length ? sem.hits : await kb.context(query, 6);
|
||||
kbBlock = kb.promptBlock(hits); kbIds = hits.map(h => h.entry.id);
|
||||
} catch (e) { console.error('kb search', e.message); }
|
||||
if (!enabled()) {
|
||||
|
||||
Reference in New Issue
Block a user