Skip to content

Comments

fix: escape SQL LIKE wildcards in semantic memory search#208

Open
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
haosenwang1018:fix/semantic-search-wildcard
Open

fix: escape SQL LIKE wildcards in semantic memory search#208
haosenwang1018 wants to merge 1 commit intoConway-Research:mainfrom
haosenwang1018:fix/semantic-search-wildcard

Conversation

@haosenwang1018
Copy link
Contributor

Summary

  • SemanticMemoryManager.search() interpolates the query directly into LIKE patterns (%${query}%) without escaping SQL wildcards
  • A search for "100%" matches any value starting with "100" followed by anything; "_" matches any single character
  • This was fixed for episodic and procedural memory in fix: memory search LIKE wildcards not escaped #127 but the identical pattern in semantic memory was missed

Fix

  • Escape % and _ in the query using query.replace(/[%_]/g, (ch) => '\\' + ch)
  • Add ESCAPE '\\' to both LIKE clauses (with-category and without-category paths)
  • Same pattern used in the episodic and procedural memory fixes (fix: memory search LIKE wildcards not escaped #127)

Test plan

  • All 74 memory tests pass (including 3 new tests for semantic wildcard escaping)
  • npx tsc --noEmit passes
  • Search for a value containing % or _ and verify exact match behavior

SemanticMemoryManager.search() interpolates the query directly into
LIKE patterns without escaping '%' and '_'. A search for "100%" would
match any value starting with "100" followed by anything, and "_"
would match any single character instead of a literal underscore.

This was fixed for episodic and procedural memory in PR Conway-Research#127 but the
same fix was not applied to semantic memory.

Apply the identical escaping pattern: replace '%' and '_' with their
backslash-escaped forms and add ESCAPE '\\' to both LIKE clauses.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant