fix: fixed minor consistency issues within MemoryManager (#1353)

This commit is contained in:
Stephen Purdue
2026-06-03 06:12:24 +01:00
committed by GitHub
parent 6419bf2cdf
commit 85bc18b7d8

View File

@@ -12,7 +12,7 @@ logger = logging.getLogger(__name__)
def tokenize(text: str) -> List[str]:
"""Simple tokenizer that splits on whitespace and removes punctuation."""
return [word.strip('.,!?";') for word in text.split()]
return [cleaned for word in text.split() if (cleaned := word.strip('.,!?";'))]
def get_text_similarity(text1: str, text2: str) -> float:
"""Calculate Jaccard similarity between two texts."""
@@ -70,7 +70,7 @@ class MemoryManager:
if text:
memories.append({
"text": text,
"timestamp": int(datetime.now().timestamp()),
"timestamp": int(time.time()),
"session_id": session_id
})
# If we see a heading that suggests memories
@@ -105,6 +105,7 @@ class MemoryManager:
def ensure_file_exists(self):
"""Create memory file if it doesn't exist."""
if not os.path.exists(self.memory_file):
os.makedirs(os.path.dirname(self.memory_file), exist_ok=True)
with open(self.memory_file, 'w', encoding='utf-8') as f:
json.dump([], f, ensure_ascii=False, indent=2)