The Memory Layer for AI Agents - Drop-in memory infrastructure for AI agents and apps. Context that persists. Built for production.
Python agentic-memoryagentic-memory-systemagentsaiai-agentschatgptgenaillmlong-term-memorymemorymemory-managementpythonragstate-management
fix: sanitize hyphens in Neo4j Cypher relationship names (#4154)
lamost423f9e30304d75b
diff --git a/mem0/memory/utils.py b/mem0/memory/utils.pyindex 0d2cb6749..e0581a09c 100644--- a/mem0/memory/utils.py+++ b/mem0/memory/utils.py@@ -249,6 +249,7 @@ def sanitize_relationship_for_cypher(relationship) -> str:"}": "_rbrace_","<": "_langle_",">": "_rangle_",+ "-": "_",}# Apply replacements and clean updiff --git a/tests/memory/test_neo4j_cypher_syntax.py b/tests/memory/test_neo4j_cypher_syntax.pyindex 45eab377a..53fe0a0de 100644--- a/tests/memory/test_neo4j_cypher_syntax.py+++ b/tests/memory/test_neo4j_cypher_syntax.py@@ -1,6 +1,32 @@import osfrom unittest.mock import Mock, patch+from mem0.memory.utils import sanitize_relationship_for_cypher+++class TestSanitizeRelationshipForCypher:+ """Test that relationship names are properly sanitized for Neo4j Cypher queries."""++ def test_hyphen_replaced_with_underscore(self):+ """Hyphens in relationship names cause Neo4j CypherSyntaxError and must be replaced."""+ assert sanitize_relationship_for_cypher("manages_via_low-cost_models") == "manages_via_low_cost_models"++ def test_multiple_hyphens(self):+ assert sanitize_relationship_for_cypher("co-owns-with") == "co_owns_with"++ def test_no_special_chars_unchanged(self):+ assert sanitize_relationship_for_cypher("works_at") == "works_at"++ def test_spaces_not_handled_here(self):+ """Spaces are replaced upstream before this function is called."""+ # sanitize only handles special chars, spaces are handled by the caller+ result = sanitize_relationship_for_cypher("has relationship")+ assert result == "has relationship"++ def test_existing_chars_still_sanitized(self):+ assert "_slash_" in sanitize_relationship_for_cypher("read/write")+ assert "_at_" in sanitize_relationship_for_cypher("user@company")+class TestNeo4jCypherSyntaxFix:"""Test that Neo4j Cypher syntax fixes work correctly"""