"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(memory): treat underscores as word boundaries in _tokenize (#87)
Hitesh P09dd59e9aaf0
diff --git a/agent/src/memory/persistent.py b/agent/src/memory/persistent.pyindex 022d0a096..21b53c838 100644--- a/agent/src/memory/persistent.py+++ b/agent/src/memory/persistent.py@@ -48,7 +48,10 @@ class MemoryEntry:def _tokenize(text: str) -> set[str]:"""Split text into searchable tokens.- ASCII words >= 3 chars + CJK individual characters.+ ASCII words >= 3 chars + CJK individual characters. Underscores are+ treated as word boundaries so snake_case titles (e.g. ``mcp_wiring_test``)+ match natural-language queries (``"mcp wiring"``) as well as verbatim+ lookups.Args:text: Input text.@@ -56,7 +59,7 @@ def _tokenize(text: str) -> set[str]:Returns:Set of tokens."""- ascii_tokens = set(re.findall(r"[a-zA-Z0-9_]{3,}", text.lower()))+ ascii_tokens = set(re.findall(r"[a-zA-Z0-9]{3,}", text.lower()))cjk_tokens = set(re.findall(r"[\u4e00-\u9fff\u3400-\u4dbf]", text))return ascii_tokens | cjk_tokensdiff --git a/agent/tests/test_persistent_memory.py b/agent/tests/test_persistent_memory.pyindex d4052aeff..40420509c 100644--- a/agent/tests/test_persistent_memory.py+++ b/agent/tests/test_persistent_memory.py@@ -42,6 +42,14 @@ class TestTokenize:def test_empty(self) -> None:assert _tokenize("") == set()+ def test_underscores_split(self) -> None:+ # snake_case titles must match natural-language queries.+ # Regression: previously _tokenize treated underscores as word chars,+ # so "mcp_wiring_test" became a single token and queries like+ # "mcp wiring" never matched.+ tokens = _tokenize("mcp_wiring_test")+ assert tokens == {"mcp", "wiring", "test"}+# ---------------------------------------------------------------------------# PersistentMemory.add