From f1dc07961e426790131b7c74bf0d0719f188d8dc Mon Sep 17 00:00:00 2001 From: sumitvairagar Date: Mon, 14 Sep 2026 10:07:49 +0530 Subject: [PATCH] cleanup: remove dead extractKeywords() and STOPWORDS orphaned by ILIKE removal (#341) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit extractKeywords() was documented as the lexical fallback keyword extractor, but the lexical fallback was removed in bae7bbb1 (semantic-only proactive recall, drop ILIKE fallback). e98aa533 cleaned up stale comments in recall.ts but left this helper and its STOPWORDS set behind. Zero production callers remain — the only references outside the definition were the test file (tests/shared/recall.test.ts:495-511). STOPWORDS is private to this function and unused elsewhere (SUMMARY_STOPWORDS in mine-local.ts is a separate, unrelated constant). Changes: - Delete STOPWORDS set and extractKeywords() from recall-gate.ts - Remove extractKeywords import and its describe block from recall.test.ts Test count: 58/58 pass (was 61 — 3 extractKeywords tests removed). TypeScript: tsc --noEmit clean. --- src/hooks/shared/recall-gate.ts | 28 ---------------------------- tests/shared/recall.test.ts | 20 -------------------- 2 files changed, 48 deletions(-) diff --git a/src/hooks/shared/recall-gate.ts b/src/hooks/shared/recall-gate.ts index ca61796b3..a3e889ca2 100644 --- a/src/hooks/shared/recall-gate.ts +++ b/src/hooks/shared/recall-gate.ts @@ -134,32 +134,4 @@ export const RECALL_THRESHOLD: number = (() => { return Number.isFinite(n) && n > 0 && n <= 1 ? n : DEFAULT_RECALL_THRESHOLD; })(); -// Common words carry no recall signal — matching them would surface noise. -const STOPWORDS = new Set([ - "the", "and", "for", "are", "but", "not", "you", "your", "with", "this", "that", - "have", "has", "had", "was", "were", "can", "could", "should", "would", "will", - "does", "did", "what", "why", "how", "when", "where", "which", "who", "into", - "from", "they", "them", "then", "than", "there", "here", "out", "get", "got", - "use", "using", "used", "make", "made", "want", "need", "please", "let", "add", - "fix", "run", "set", "all", "any", "our", "its", "his", "her", "now", "new", - "some", "more", "most", "such", "only", "also", "just", "like", "able", "via", -]); -/** - * Extract salient lower-cased keywords from a prompt for the lexical fallback. - * Keeps identifier-ish tokens (snake_case, dotted, paths), drops stopwords and - * sub-3-char tokens, de-dupes, and caps the count. - */ -export function extractKeywords(prompt: string | undefined | null, max = 8): string[] { - const raw = (prompt ?? "").toLowerCase().match(/[a-z0-9][a-z0-9_./-]{2,}/g) ?? []; - const out: string[] = []; - const seen = new Set(); - for (const tok of raw) { - const w = tok.replace(/[._/-]+$/, ""); // trim trailing separators - if (w.length < 3 || STOPWORDS.has(w) || seen.has(w)) continue; - seen.add(w); - out.push(w); - if (out.length >= max) break; - } - return out; -} diff --git a/tests/shared/recall.test.ts b/tests/shared/recall.test.ts index 0d3c7f17f..e241858f4 100644 --- a/tests/shared/recall.test.ts +++ b/tests/shared/recall.test.ts @@ -2,7 +2,6 @@ import { describe, it, expect, vi } from "vitest"; import { shouldRecall, passesThreshold, - extractKeywords, proactiveRecallDisabled, parsePositive, RECALL_THRESHOLD, @@ -492,25 +491,6 @@ describe("recallTopHit — focused semantic query", () => { }); }); -describe("extractKeywords — lexical fallback keyword extraction", () => { - it("keeps salient/identifier tokens, drops stopwords and short tokens", () => { - const kw = extractKeywords("why does the parser throw a TypeError in column_streamers.hpp?"); - expect(kw).toContain("parser"); - expect(kw).toContain("typeerror"); - expect(kw).toContain("column_streamers.hpp"); - expect(kw).not.toContain("the"); - expect(kw).not.toContain("why"); // stopword - }); - it("de-dupes and caps the count", () => { - const kw = extractKeywords("cache cache cache redis redis storage storage provider bucket byoc extra", 4); - expect(kw.length).toBe(4); - expect(new Set(kw).size).toBe(kw.length); - }); - it("returns few/no keywords for terse input (can't meet the lexical bar)", () => { - expect(extractKeywords("ok go").length).toBeLessThan(2); - }); -}); - describe("recordRecallEvent — always-on JSONL sink", () => { let home: string; beforeEach(() => { home = mkdtempSync(join(tmpdir(), "recall-ev-")); setFakeHome(home); });