trivial turn patch
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const {getEnv} = require('./config/env');
|
||||
const {QDRANT, COLLECTIONS, EPISODIC, SERVICES, OLLAMA, PORTS, LLAMACPP, INFERENCE_DEFAULTS, SQLITE, ORCHESTRATION, SUMMARIES, ENTITIES, RETRIEVAL } = require('./config/constants');
|
||||
const {parseRow, formatEpisodeText} = require('./utils')
|
||||
const {parseRow, formatEpisodeText, isTrivialTurn} = require('./utils')
|
||||
const logger = require('./utils/logger');
|
||||
|
||||
module.exports = {
|
||||
@@ -17,6 +17,7 @@ module.exports = {
|
||||
ORCHESTRATION,
|
||||
parseRow,
|
||||
formatEpisodeText,
|
||||
isTrivialTurn,
|
||||
SUMMARIES,
|
||||
ENTITIES,
|
||||
logger,
|
||||
|
||||
@@ -10,4 +10,46 @@ function formatEpisodeText(userMessage, aiResponse) {
|
||||
return `User: ${userMessage}\nAssistant: ${aiResponse}`;
|
||||
}
|
||||
|
||||
module.exports = { parseRow, formatEpisodeText };
|
||||
// Contentless "social" turns — greetings, sign-offs, acknowledgements — that
|
||||
// carry no information to store or recall. Used to skip entity extraction and
|
||||
// noisy retrieval on such turns.
|
||||
const TRIVIAL_TURNS = new Set([
|
||||
'good morning', 'good night', 'good evening', 'good afternoon', 'morning', 'evening',
|
||||
'hello', 'hi', 'hey', 'hey there', 'yo', 'sup', 'whats up', 'hiya', 'howdy',
|
||||
'goodbye', 'bye', 'see you', 'see ya', 'see you later', 'talk later', 'talk soon',
|
||||
'later', 'catch you later', 'gtg', 'gotta go', 'im off', 'heading out',
|
||||
'thanks', 'thank you', 'thanks again', 'thank you so much', 'ty', 'thx', 'cheers',
|
||||
'no worries', 'no problem', 'np', 'youre welcome', 'my pleasure',
|
||||
'ok', 'okay', 'k', 'kk', 'alright', 'sure', 'sounds good', 'got it', 'gotcha',
|
||||
'cool', 'nice', 'great', 'awesome', 'perfect', 'lol', 'haha',
|
||||
'just saying hi', 'just saying hello', 'just checking in', 'just dropping in',
|
||||
'stopping by', 'just stopping by', 'just wanted to say hi',
|
||||
]);
|
||||
|
||||
// Trailing filler words that don't change a phrase's social nature, so
|
||||
// "good morning again" / "thanks everyone" collapse to a base phrase.
|
||||
const TRIVIAL_FILLER = new Set(['again', 'there', 'everyone', 'all', 'yall', 'folks', 'man', 'dude', 'friend', 'buddy']);
|
||||
|
||||
// Conservative, HIGH-PRECISION check: is this a contentless social turn?
|
||||
// It exists to skip retrieval/extraction on turns with nothing to remember or
|
||||
// recall, and deliberately errs toward "substantive" — a real short query like
|
||||
// "capital of France" must NOT be treated as trivial. Genuine intent
|
||||
// classification is a separate, later concern (confidence-based routing), not
|
||||
// this heuristic. Extend TRIVIAL_TURNS as new pure-social phrases show up.
|
||||
function isTrivialTurn(message) {
|
||||
if (!message) return true;
|
||||
const norm = String(message)
|
||||
.toLowerCase()
|
||||
.replace(/[^\p{L}\p{N}\s]/gu, ' ') // punctuation → space (unicode-aware)
|
||||
.replace(/\s+/g, ' ')
|
||||
.trim();
|
||||
if (!norm) return true; // empty / punctuation-only
|
||||
if (TRIVIAL_TURNS.has(norm)) return true;
|
||||
|
||||
// Drop trailing filler and re-check ("good morning again" → "good morning")
|
||||
const words = norm.split(' ');
|
||||
while (words.length > 1 && TRIVIAL_FILLER.has(words[words.length - 1])) words.pop();
|
||||
return TRIVIAL_TURNS.has(words.join(' '));
|
||||
}
|
||||
|
||||
module.exports = { parseRow, formatEpisodeText, isTrivialTurn };
|
||||
Reference in New Issue
Block a user