Route definitional questions to the narrative docs, and tolerate misspelling

"What is Varaverk" matched the PURPOSE intent, so retrieval returned every
script's one-line purpose and the model answered that the context does not
define the system — while README.md sat in the index unread. A definitional
question with no explicit filter now goes to kind=readme.

Varaverk is a coined word with no spell-check, so it arrives as varavrk,
veraverk, varavek. Edit distance catches those without a pattern that needs
extending per typo. This is search, not identity — a near-miss only widens a
document search, unlike hostname resolution where it must never resolve.
This commit is contained in:
Gmer4Lfe
2026-08-03 18:17:56 -04:00
parent 9d189e9dbf
commit 452bf0e544
2 changed files with 37 additions and 1 deletions
+29
View File
@@ -453,6 +453,35 @@ function vv_ai_retrieve(string $query, string $kind = '', string $section = '',
'scanned' => $d['scanned'] ?? 0];
}
// ── Question shape ───────────────────────────────────────────────────────────────────────────
//
// "Varaverk" is a coined word with no spell-check and an awkward keyboard shape, so it arrives
// misspelled often — varavrk, veraverk, varavek, varverk. Edit distance catches those without a
// hand-written pattern that would need extending every time a new typo appears.
//
// This is search, not identity. The rule against fuzzy hostname matching is about deciding which
// machine you are talking to, where a near-miss must never resolve; here a near-miss only widens
// a document search, and the cost of being wrong is a slightly odd set of passages.
function vv_ai_mentions_varaverk(string $q): bool {
foreach (preg_split('/[^a-z0-9]+/i', mb_strtolower($q), -1, PREG_SPLIT_NO_EMPTY) as $w) {
if (strlen($w) < 5 || strlen($w) > 12) continue; // bound the comparison window
if ($w === 'varaverk' || levenshtein($w, 'varaverk') <= 2) return true;
}
return false;
}
// "What is Varaverk", "explain varavrk", "whats this thing do". Intent routing boosts PURPOSE
// for these, which surfaces every script's one-line purpose and buries the top-level prose that
// actually defines the system — so the model answers that the context does not define it, while
// README.md sits in the index unread.
function vv_ai_is_definitional(string $q): bool {
if (!vv_ai_mentions_varaverk($q)) return false;
return (bool)preg_match(
'/\b(what\'?s?|whats|define|definition|describe|explain|overview|tell me about|'
. 'purpose of|point of|elevator|in a nutshell)\b/i', $q);
}
// ── Memory ───────────────────────────────────────────────────────────────────────────────────
//
// A small operator-maintained file handed to the model at the start of every conversation.