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. support.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:
martbost
2026-11-16 05:36:48 -06:00
parent 94067cf000
commit 7e113f055d
9 changed files with 304 additions and 12 deletions
+12
View File
@@ -31,6 +31,7 @@ const drip = require('./drip');
const spaces = require('./spaces'); // DO Spaces video storage (inert unless DO_SPACES_* set)
let QR = null; try { QR = require('qrcode'); } catch (e) { /* optional */ }
const chatbot = require('./chatbot');
const netkb = require('./netkb'); // the shared network KB on the hub; suggest() for the Help pane (2026-11-16)
const kb = require('./kb'); // the assistant's knowledge base: Admin > Knowledge base, seeded from chatbot.js CANNED + kb-seed.js (2026-10-20)
const fraud = require('./fraud');
const coach = require('./coach'); // coaching view, nudges, digest, prospects, link stats
@@ -5048,6 +5049,17 @@ const server = http.createServer(async (req, res) => {
const r = await tickets.create({ source: 'form', email: s.email, name: (a && a.username) || '', username: a && a.username, subject: b.subject, category: b.category, body: b.body, attachments: b.attachments });
return json(res, r.error ? 400 : 200, r.error ? r : { ok: true, ref: r.ticket.ref });
}
// help desk suggestions (2026-11-16): while a signed-in member types a new ticket, the closest help answers (the hub's semantic
// match over the network KB, BM25 here when the hub is slow or down). KB entries only, never another member's ticket. Never blocks sending.
if (p === '/api/my/support/suggest' && req.method === 'POST') {
const s = await auth.fromRequest(req);
if (!s || !s.email) return json(res, 401, { error: 'Sign in first.' });
const b = await readBody(req);
if (supportFlood('sg:' + String(s.email).toLowerCase(), 240, 3600000)) return json(res, 200, { items: [], via: 'limited' });
const text = (String(b.subject || '').slice(0, 200) + '. ' + String(b.body || '').slice(0, 800)).trim();
try { return json(res, 200, await netkb.suggest(text, { own: await kb.own(), fallback: q => kb.context(q, 4) })); }
catch (e) { console.error('support suggest', e.message); return json(res, 200, { items: [], via: 'error' }); }
}
m = /^\/api\/my\/support\/((?:IAP|LS)-\d{4,9})(\/reply)?$/.exec(p);
if (m && (req.method === 'GET' || (m[2] && req.method === 'POST'))) {
const s = await auth.fromRequest(req);