Add regex mode to SearchMemory tool#343
Merged
rockfordlhotka merged 1 commit intomainfrom May 6, 2026
Merged
Conversation
Extends the existing SearchMemory tool with a `mode` parameter that
switches the search backend between hybrid (BM25 + optional vector,
default) and regex/grep-style literal pattern matching. The model picks
the mode based on whether it knows a literal token to search for.
The regex backend matches against the memory's logical path name
(`{category}/{id}`) plus the BM25 document text (content + tags +
category words), never the on-disk file path. Bounded by a 1s per-entry
Regex.MatchTimeout (catches catastrophic backtracking) plus a 10s
overall wall-clock budget across the scan (bounds total cost as the
corpus grows).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
modeparameter to theSearchMemorytool:hybrid(default — BM25 + optional vector, unchanged) orregex(literal pattern matching).{category}/{id}) plus the BM25 document text (content + tags + category words). The on-disk file path fromFileMemoryStore.GetFilePathis deliberately never in the match surface — the model operates in id-space.Regex.MatchTimeoutof 1s catches catastrophic backtracking on a single input; an overall 10s wall-clock budget across the scan stops a slow-but-not-pathological pattern from dominating as the corpus grows.MemorySearchExceptioncarries human-readable backend errors (invalid pattern, per-entry timeout, overall budget) up to the tool layer, which surfaces the message verbatim so the model can refine its query._embeddingCacheare skipped entirely in regex mode — behaves identically whether the deployment runs hybrid or BM25-only.common-directives.md(loaded by both primary and sub agents) with one short paragraph teaching when to reach formode='regex'.Test plan
dotnet build RockBot.slnx— cleandotnet test RockBot.slnx— full unit suite green (615 Host tests, 130 Agent tests, all others pass)Search_RegexMode_*tests cover: literal-token match, id-in-path match, category-in-path match, on-disk-path-must-not-leak, default case-insensitive, case-sensitive flag, category pre-filter, MaxResults cap, invalid pattern → exception, no-match → empty, importance/last-seen ordering, null-query fallback, catastrophic-backtracking timeout, overall-budget overrunMemoryToolsTestscover: default mode is hybrid,regex/Regexparsed, unknown mode returns error string and skips the store,MemorySearchExceptionflows through verbatimCloses #339
🤖 Generated with Claude Code