From 99b000f25a1932cb21fd3745febdb5a93adea4a6 Mon Sep 17 00:00:00 2001 From: PeninsulaInd Date: Wed, 1 Apr 2026 09:58:18 -0500 Subject: [PATCH] Add word-overlap gate to _fuzzy_keyword_match to avoid unnecessary LLM calls LLM plural check was firing for every non-exact keyword pair (e.g. "insert molding" vs "cement plant lubrication"), causing timeouts and wasted API calls. Now requires keywords to share all but one word before escalating to the LLM. Co-Authored-By: Claude Opus 4.6 (1M context) --- cheddahbot/tools/linkbuilding.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cheddahbot/tools/linkbuilding.py b/cheddahbot/tools/linkbuilding.py index 9b5b552..25d81fc 100644 --- a/cheddahbot/tools/linkbuilding.py +++ b/cheddahbot/tools/linkbuilding.py @@ -285,6 +285,15 @@ def _fuzzy_keyword_match(a: str, b: str, llm_check: Callable[[str, str], bool] | return True if llm_check is None: return False + + # Only call LLM when keywords share most words (possible plural difference). + words_a = set(a.split()) + words_b = set(b.split()) + shared = words_a & words_b + total = max(len(words_a), len(words_b)) + if total > 1 and len(shared) < total - 1: + return False + return llm_check(a, b)