Large Language Model (LLM) agents require persistent memory to maintain personalization, factual continuity, and long-horizon reasoning, yet standard context-window and retrieval-augmented generation (RAG) pipelines degrade over multi-session interactions. We present MemMachine, an open-source memory system that integrates short-term, long-term episodic, and profile memory within a ground-truth-preserving architecture that stores entire conversational episodes and reduces lossy LLM-based extraction. MemMachine uses contextualized retrieval that expands nucleus matches with surrounding context, improving recall when relevant evidence spans multiple dialogue turns. Across benchmarks, MemMachine achieves strong accuracy-efficiency tradeoffs: on LoCoMo it reaches 0.9169 using gpt4.1-mini; on LongMemEvalS (ICLR 2025), a six-dimension ablation yields 93.0 percent accuracy, with retrieval-stage optimizations -- retrieval depth tuning (+4.2 percent), context formatting (+2.0 percent), search prompt design (+1.8 percent), and query bias correction (+1.4 percent) -- outperforming ingestion-stage gains such as sentence chunking (+0.8 percent). GPT-5-mini exceeds GPT-5 by 2.6 percent when paired with optimized prompts, making it the most cost-efficient setup. Compared to Mem0, MemMachine uses roughly 80 percent fewer input tokens under matched conditions. A companion Retrieval Agent adaptively routes queries among direct retrieval, parallel decomposition, or iterative chain-of-query strategies, achieving 93.2 percent on HotpotQA-hard and 92.6 percent on WikiMultiHop under randomized-noise conditions. These results show that preserving episodic ground truth while layering adaptive retrieval yields robust, efficient long-term memory for personalized LLM agents.
Figures & tables
Benchmark
Metric
Result
LoCoMo
Overall score (gpt-4.1-mini)
91.69%
LongMemEval S
Ablation best (gpt-5-mini)
93.0%
HotpotQA hard
Retrieval Agent accuracy
93.2%
WikiMultiHop †
Retrieval Agent accuracy
92.6%
Mem0 comparison
Input token reduction
~80% less
† Randomized-noise setting.
Table 1: Benchmark snapshot (quick overview). Detailed setup and full breakdowns are provided in later sections.
Criterion
Episodic
Semantic
Query type
Specific past events
General preferences
Accuracy need
Ground truth
Approximate
Temporal scope
Point-in-time
Cross-session
Data form
Raw conversation
Extracted facts
Example
“What did I say about X?”
“What foods do I like?”
Table 2: Episodic vs. Semantic Memory Usage
Figure 1: MemMachine system architecture. Clients (AI agents, Python SDK, MCP servers) access MemMachine through REST API and SDK interfaces. Internally, episodic memory comprises working memory (short-term) and persistent memory (long-term), while semantic memory stores user profiles. All memory types are backed by SQL, vector, and graph databases.
Figure 2: Memory recall workflow. The query passes through STM, LTM vector search, contextualization, deduplication, reranking, and chronological sorting before returning results.
Figure 3: Retrieval Agent tool tree. The ToolSelectAgent classifies each query and routes it to one of three strategies. All strategies ultimately delegate to the same declarative memory search, ensuring that index and reranker improvements propagate automatically.
Benchmark
Questions
Answer LLM
MemMachine
Retrieval Agent
Baseline
Acc.
Recall
Acc.
Recall
Acc.
LoCoMo
1,540
gpt-5-mini
90.5%
82.2%
90.2%
82.5%
91.7%
WikiMultiHop
500
gpt-4.1-mini
88.8%
90.8%
90.0%
92.5%
96.7%
WikiMultiHop †
500
gpt-5-mini
87.4%
91.7%
92.6%
83.3%
96.7%
MRCR
300
gpt-5.2
79.6%
99.1%
81.4%
99.4%
32.3%
EpBench
546
gpt-5-mini
73.4%
66.1%
71.8%
65.3%
77.5%
Table 3: Retrieval Agent benchmark results across five datasets. Accuracy is LLM-judge score; Recall measures gold supporting fact retrieval. Best result per benchmark in bold . All MemMachine and Agent results use surrounding episodes enabled unless noted.
Tool
Questions
Accuracy
Recall
MemMachine
201
93.53%
89.31%
SplitQuery
118
94.07%
92.83%
ChainOfQuery
181
92.27%
95.31%
Overall (Agent)
500
93.20%
92.31%
Table 4: HotpotQA hard set: per-tool performance breakdown for the Retrieval Agent (n=500, gpt-5-mini).
Component
Input Tokens
Output Tokens
ToolSelect (router)
1,049
195
ChainOfQuery
2,874
1,614
SplitQuery
1,229
435
MemMachine
0
0
Table 5: Average token cost per question by Retrieval Agent strategy (HotpotQA hard set).
Use Agent Mode
When…
Best fit
Queries involve multi-hop reasoning, co-reference resolution, or multi-entity fan-out. Accuracy is prioritized over latency. Use cases include research assistants, compliance review, and complex QA.
Not needed
Queries are predominantly single-hop factual lookups. Latency requirements are strict ( < 200ms). Token budget is constrained. Use cases include simple chatbot recall, preference lookup, and session context.
Table 6: Decision guidance for enabling agent mode.
Configuration
LLM Score
Mode
gpt-4.1-mini (agent)
0.9169
Agent
gpt-4.1-mini (memory)
0.9123
Memory
gpt-4o-mini (agent)
0.8812
Agent
gpt-4o-mini (memory)
0.8747
Memory
Table 7: Impact of eval-LLM on MemMachine v0.2 LoCoMo scores.
System
Input Tokens
Output Tokens
MemMachine v0.2 (memory)
4.20M
43,169
MemMachine v0.2 (agent)
8.57M
93,210
Mem0 main/HEAD (memory)
19.21M
14,840
Table 8: Token usage comparison on LoCoMo (gpt-4.1-mini).
Table 11: LoCoMo benchmark comparison across AI agent memory systems (LLM Judge Score). MemMachine results are with gpt-4o-mini for fair comparison with published baselines; gpt-4.1-mini results shown separately in Table 10 .
Table 13: LongMemEval S ablation: contribution of each optimization to overall LLM score, measured by comparing configuration pairs that differ in one variable.
Config
LLM
SSU
SSP
SSA
TR
KU
MS
Total
C5 (baseline)
GPT-5
0.986
0.700
1.000
0.798
0.925
0.797
0.855
C6 (user-q)
GPT-5
0.957
0.667
0.982
0.850
0.885
0.835
0.870
C7 ( k =30)
GPT-5
0.986
0.800
1.000
0.917
0.923
0.850
0.912
C12 (mini, k =20)
GPT-5-mini
0.986
0.933
1.000
0.902
0.962
0.850
0.922
C14 (mini, k =50)
GPT-5-mini
1.000
0.933
1.000
0.932
0.949
0.842
0.928
C15 (mini, k =100)
GPT-5-mini
1.000
0.933
0.982
0.917
0.949
0.872
0.930
Table 14: LongMemEval S per-category LLM scores for selected configurations ( n=500 ). SSU = single-session-user, SSP = single-session-preference, SSA = single-session-assistant, TR = temporal reasoning, KU = knowledge update, MS = multi-session.
Config (LLM)
k
Input (M)
Score
C6 (GPT-5)
20
2.94
0.870
C7 (GPT-5)
30
4.03
0.912
C8 (GPT-5)
50
6.47
0.890
C12 (GPT-5-mini)
20
2.58
0.922
C14 (GPT-5-mini)
50
5.97
0.928
C15 (GPT-5-mini)
100
9.79
0.930
Table 15: LongMemEval S token consumption per 500-question run. Input tokens scale with k ; output tokens remain approximately constant.
Property
MemMachine
Mem0
Zep
Mastra OM
MemOS
Full Context
Memory approach
Retrieval
Retrieval
Retrieval
In-context
Hybrid
In-context
Ground truth preserved
✓
Partial
Partial
×
Partial
✓
Prompt cacheable
Partial
×
×
✓
×
✓
Scales beyond context window
✓
✓
✓
×
✓
×
LLM calls per message
Low
High
Moderate
Moderate
High
None
Specialized DB required
Yes
Yes
Yes
No
Yes
No
Table 16: Architectural design space comparison across agent memory systems.