@elizaos/plugin-memory 1.1.0 โ†’ 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +230 -330
  2. package/dist/actions/remember.d.ts +11 -0
  3. package/dist/browser/index.browser.js +209 -348
  4. package/dist/browser/index.browser.js.map +14 -23
  5. package/dist/cjs/index.node.cjs +1035 -2167
  6. package/dist/cjs/index.node.js.map +14 -23
  7. package/dist/evaluators/long-term-extraction.d.ts +8 -0
  8. package/dist/evaluators/summarization.d.ts +25 -6
  9. package/dist/index.d.ts +33 -152
  10. package/dist/node/index.node.js +1060 -2194
  11. package/dist/node/index.node.js.map +14 -23
  12. package/dist/providers/context-summary.d.ts +12 -0
  13. package/dist/providers/long-term-memory.d.ts +11 -18
  14. package/dist/providers/recent-messages.d.ts +15 -0
  15. package/dist/schemas/index.d.ts +6 -16
  16. package/dist/schemas/long-term-memories.d.ts +70 -308
  17. package/dist/schemas/memory-access-logs.d.ts +154 -0
  18. package/dist/schemas/session-summaries.d.ts +283 -0
  19. package/dist/services/memory-service.d.ts +51 -95
  20. package/dist/types/index.d.ts +53 -298
  21. package/package.json +2 -84
  22. package/dist/evaluators/consolidation.d.ts +0 -19
  23. package/dist/prompts/consolidation.d.ts +0 -35
  24. package/dist/prompts/summarization.d.ts +0 -25
  25. package/dist/providers/action-results.d.ts +0 -2
  26. package/dist/providers/recent-conversation-summary.d.ts +0 -2
  27. package/dist/repositories/conversation-summary.d.ts +0 -33
  28. package/dist/repositories/index.d.ts +0 -17
  29. package/dist/repositories/long-term-memory.d.ts +0 -53
  30. package/dist/schemas/conversation-summaries.d.ts +0 -494
  31. package/dist/utils/db-mapping.d.ts +0 -20
  32. package/dist/utils/decay-scoring.d.ts +0 -41
  33. package/dist/utils/embedding.d.ts +0 -21
  34. package/dist/utils/formatting.d.ts +0 -17
  35. package/dist/utils/index.d.ts +0 -17
  36. package/dist/utils/search-merging.d.ts +0 -18
  37. package/dist/utils/token-counter.d.ts +0 -53
package/README.md CHANGED
@@ -1,435 +1,335 @@
1
1
  # @elizaos/plugin-memory
2
2
 
3
- Advanced cognitive memory system for ElizaOS agents with persistent memory, intelligent fact extraction, and hybrid retrieval.
3
+ Advanced memory management plugin for ElizaOS that provides intelligent conversation summarization and persistent long-term memory storage.
4
4
 
5
- > ๐Ÿ“š **Research-Driven**: Built on analysis of 40+ academic papers. See [`refactor.md`](./refactor.md) and [`EVALUATION.md`](./EVALUATION.md) for details.
5
+ ## Features
6
6
 
7
- ---
7
+ ### ๐Ÿ”„ Short-term Memory (Conversation Summarization)
8
8
 
9
- ## Overview
9
+ - **Automatic Summarization**: Compresses long conversations when they exceed configurable thresholds
10
+ - **Context Preservation**: Maintains conversation flow while dramatically reducing token usage
11
+ - **Recent Message Retention**: Keeps the most recent messages for immediate context
12
+ - **Topic Extraction**: Identifies and tracks main topics discussed in each session
10
13
 
11
- Transforms stateless LLM agents into persistent entities with human-like memory capabilities:
14
+ ### ๐Ÿง  Long-term Memory (Persistent Facts)
12
15
 
13
- - **Three-Tier Memory**: Episodic (events), Semantic (facts), Procedural (skills)
14
- - **Smart Consolidation**: Automatically extracts persistent facts from conversations
15
- - **Hybrid Retrieval**: Vector + BM25 + Graph search with exponential decay
16
- - **Contextual Embeddings**: Self-contained memories that improve retrieval accuracy
17
- - **Contradiction Detection**: Automatically handles conflicting information
16
+ - **Intelligent Extraction**: Automatically learns facts about users from conversations
17
+ - **Cognitive Science Based**: Organizes information into 3 core memory types (episodic, semantic, procedural)
18
+ - **Strict Criteria**: Only extracts truly significant, persistent information
19
+ - **Confidence Scoring**: Tracks reliability of stored information
20
+ - **Cross-session Persistence**: Remembers user context across all interactions
18
21
 
19
- ---
22
+ ### ๐Ÿ“Š Memory Categories (Based on Cognitive Science)
20
23
 
21
- ## Installation
22
-
23
- ```bash
24
- bun add @elizaos/plugin-memory
25
- ```
26
-
27
- Add to your character file:
24
+ The plugin uses the three fundamental types of long-term memory from cognitive science:
28
25
 
29
- ```json
30
- {
31
- "plugins": ["@elizaos/plugin-memory"]
32
- }
33
- ```
34
-
35
- The plugin auto-creates database tables on first load and handles everything automatically.
26
+ 1. **Episodic Memory**: Personal experiences and specific events
27
+ - Example: "User completed migration from MongoDB to PostgreSQL in Q2 2024"
28
+ - Contains: WHO did WHAT, WHEN/WHERE
29
+ - Use for: Significant project milestones, important incidents, formative experiences
36
30
 
37
- ---
31
+ 2. **Semantic Memory**: General facts, concepts, and knowledge
32
+ - Example: "User is a senior TypeScript developer with 8 years experience"
33
+ - Contains: Factual, timeless information
34
+ - Use for: Professional identity, core expertise, established facts about work context
38
35
 
39
- ## Configuration
36
+ 3. **Procedural Memory**: Skills, workflows, and how-to knowledge
37
+ - Example: "User follows TDD workflow: writes tests first, then implementation"
38
+ - Contains: HOW user does things
39
+ - Use for: Consistent workflows, methodologies, debugging processes
40
40
 
41
- ### Quick Reference
42
-
43
- | Setting | Default | Description |
44
- | -------------------------------- | ------- | --------------------------------------- |
45
- | `MEMORY_CONSOLIDATION_THRESHOLD` | `12` | Messages before fact extraction |
46
- | `MEMORY_MIN_CONFIDENCE` | `0.7` | Minimum confidence to store facts (0-1) |
47
- | `MEMORY_ENABLE_VECTOR_SEARCH` | `true` | Enable semantic search |
48
- | `MEMORY_ENABLE_BM25` | `true` | Enable keyword search |
49
- | `MEMORY_RETRIEVAL_LIMIT` | `5` | Max memories per query |
50
- | `MEMORY_TOKEN_BUDGET` | `1000` | Token budget for memory context |
51
- | `MEMORY_SUMMARY_ENABLED` | `true` | Enable conversation summarization |
52
- | `MEMORY_MESSAGES_PER_SUMMARY` | `7` | Messages per summary |
53
- | `MEMORY_SUMMARIES_PER_LEVEL` | `5` | Summaries before next level |
54
- | `MEMORY_SUMMARY_MAX_DEPTH` | `3` | Maximum summary hierarchy depth |
55
- | `MEMORY_SUMMARY_TOKEN_BUDGET` | `500` | Token budget for summaries |
56
- | `CONTEXT_OVERLAP_USER_MESSAGES` | `2` | User messages overlap after summary |
57
-
58
- ### Configuration Methods
41
+ ## Installation
59
42
 
60
- Settings are loaded via `runtime.getSetting()` with priority:
43
+ ```bash
44
+ bun add @elizaos/plugin-memory
45
+ ```
61
46
 
62
- 1. **Character `settings`** (highest priority)
63
- 2. **Environment variables** (`.env` file)
64
- 3. **Plugin defaults** (fallback)
47
+ ## Usage
65
48
 
66
- #### Character File Example
49
+ ### Basic Setup
67
50
 
68
- ```json
69
- {
70
- "name": "MyAgent",
71
- "plugins": ["@elizaos/plugin-memory"],
72
- "settings": {
73
- "MEMORY_CONSOLIDATION_THRESHOLD": "15",
74
- "MEMORY_MIN_CONFIDENCE": "0.8",
75
- "MEMORY_RETRIEVAL_LIMIT": "10"
76
- }
77
- }
51
+ ```typescript
52
+ import { memoryPlugin } from '@elizaos/plugin-memory';
53
+
54
+ const agent = new Agent({
55
+ name: 'MyAgent',
56
+ plugins: [
57
+ memoryPlugin,
58
+ // ... other plugins
59
+ ],
60
+ });
78
61
  ```
79
62
 
80
- #### `.env` File Example
63
+ ### Configuration
64
+
65
+ Configure the plugin via environment variables in your `.env` file:
81
66
 
82
67
  ```env
83
- # Core Settings
84
- MEMORY_CONSOLIDATION_THRESHOLD=12
85
- MEMORY_MIN_CONFIDENCE=0.7
86
-
87
- # Retrieval Settings
88
- MEMORY_ENABLE_VECTOR_SEARCH=true
89
- MEMORY_ENABLE_BM25=true
90
- MEMORY_RETRIEVAL_LIMIT=5
91
- MEMORY_TOKEN_BUDGET=1000
92
-
93
- # Summarization Settings
94
- MEMORY_SUMMARY_ENABLED=true
95
- MEMORY_MESSAGES_PER_SUMMARY=7
96
- MEMORY_SUMMARIES_PER_LEVEL=5
97
- MEMORY_SUMMARY_MAX_DEPTH=3
98
- MEMORY_SUMMARY_TOKEN_BUDGET=500
99
- CONTEXT_OVERLAP_USER_MESSAGES=2
68
+ # Short-term Memory Settings
69
+ MEMORY_SUMMARIZATION_THRESHOLD=16 # Messages before summarization starts (default: 16)
70
+ MEMORY_SUMMARIZATION_INTERVAL=10 # Update summary every N messages (default: 10)
71
+ MEMORY_RETAIN_RECENT=10 # Recent messages to keep (default: 10)
72
+ MEMORY_MAX_NEW_MESSAGES=20 # Max new messages in summary update (default: 20)
73
+
74
+ # Long-term Memory Settings
75
+ MEMORY_LONG_TERM_ENABLED=true # Enable long-term extraction (default: true)
76
+ MEMORY_EXTRACTION_THRESHOLD=30 # Min messages before extraction starts (default: 30)
77
+ MEMORY_EXTRACTION_INTERVAL=10 # Run extraction every N messages (default: 10)
78
+ MEMORY_CONFIDENCE_THRESHOLD=0.85 # Minimum confidence to store (default: 0.85)
100
79
  ```
101
80
 
102
- ---
103
-
104
- ## Configuration Details
105
-
106
- ### Core Memory Settings
107
-
108
- #### `MEMORY_CONSOLIDATION_THRESHOLD` (default: `12`)
109
-
110
- Number of messages to buffer before triggering memory consolidation.
111
-
112
- - **Lower** (5-8): Extract facts frequently, more LLM calls, better for fast-paced chats
113
- - **Higher** (15-30): Let conversations develop, fewer LLM calls, better for long-form discussions
114
-
115
- #### `MEMORY_MIN_CONFIDENCE` (default: `0.7`)
116
-
117
- Minimum confidence score (0-1) to store extracted facts.
118
-
119
- - **Higher** (0.8-0.9): Only store high-certainty facts, good for critical applications
120
- - **Lower** (0.5-0.6): Capture more nuanced information, risk storing noise
121
-
122
- ### Retrieval Settings
123
-
124
- #### `MEMORY_ENABLE_VECTOR_SEARCH` (default: `true`)
125
-
126
- Enable semantic similarity search using embeddings. Recommended to keep enabled.
127
-
128
- #### `MEMORY_ENABLE_BM25` (default: `true`)
129
-
130
- Enable keyword-based search with stemming. Works best combined with vector search.
131
-
132
- #### `MEMORY_RETRIEVAL_LIMIT` (default: `5`)
133
-
134
- Maximum number of memories to retrieve per query.
135
-
136
- - **Lower** (3): Faster responses, less context
137
- - **Higher** (10-20): More context, uses more tokens
138
-
139
- #### `MEMORY_TOKEN_BUDGET` (default: `1000`)
140
-
141
- Maximum tokens for memory context in prompts. Automatically trims to fit budget.
142
-
143
- ### Summarization Settings
144
-
145
- #### `MEMORY_SUMMARY_ENABLED` (default: `true`)
146
-
147
- Enable hierarchical conversation summarization. Reduces token usage for long conversations.
148
-
149
- #### `MEMORY_MESSAGES_PER_SUMMARY` (default: `7`)
150
-
151
- How many messages to include in each Level 1 summary.
152
-
153
- - **Lower** (5): More granular summaries
154
- - **Higher** (15-20): Broader summaries
155
-
156
- #### `MEMORY_SUMMARIES_PER_LEVEL` (default: `5`)
157
-
158
- How many summaries to accumulate before creating the next level.
159
-
160
- - Example: 5 Level-1 summaries โ†’ 1 Level-2 summary
81
+ ### Manual Memory Storage
161
82
 
162
- #### `MEMORY_SUMMARY_MAX_DEPTH` (default: `3`)
83
+ Users can explicitly ask the agent to remember information:
163
84
 
164
- Maximum depth of the summary hierarchy.
165
-
166
- - Level 1: Direct message summaries
167
- - Level 2: Summaries of summaries
168
- - Level 3+: Higher-level abstractions
169
-
170
- #### `MEMORY_SUMMARY_TOKEN_BUDGET` (default: `500`)
171
-
172
- Maximum tokens for conversation summaries in context.
173
-
174
- #### `CONTEXT_OVERLAP_USER_MESSAGES` (default: `2`)
175
-
176
- Number of user messages to show as overlap after summarization for conversation continuity.
177
-
178
- ---
179
-
180
- ## Configuration Presets
181
-
182
- ### High-Frequency Chatbot
183
-
184
- ```json
185
- {
186
- "MEMORY_CONSOLIDATION_THRESHOLD": "8",
187
- "MEMORY_MIN_CONFIDENCE": "0.8",
188
- "MEMORY_RETRIEVAL_LIMIT": "3",
189
- "MEMORY_MESSAGES_PER_SUMMARY": "5"
190
- }
191
85
  ```
86
+ User: "Remember that I prefer TypeScript over JavaScript"
87
+ Agent: I've made a note of that in my Semantic memory: "User prefers TypeScript over JavaScript"
192
88
 
193
- **Why**: Fast extraction, high-quality facts only, minimal context for speed.
194
-
195
- ### Long-Form Conversations (Therapy, Coaching, Research)
89
+ User: "Keep in mind I'm working on a startup project"
90
+ Agent: I've made a note of that in my Episodic memory: "User is working on a startup project"
196
91
 
197
- ```json
198
- {
199
- "MEMORY_CONSOLIDATION_THRESHOLD": "20",
200
- "MEMORY_MIN_CONFIDENCE": "0.6",
201
- "MEMORY_RETRIEVAL_LIMIT": "10",
202
- "MEMORY_TOKEN_BUDGET": "2000"
203
- }
92
+ User: "Don't forget I always use TDD"
93
+ Agent: I've made a note of that in my Procedural memory: "User follows TDD (Test-Driven Development) methodology"
204
94
  ```
205
95
 
206
- **Why**: Natural conversation flow, capture nuanced details, rich context.
96
+ ### Accessing the Memory Service
207
97
 
208
- ### Critical Applications (Medical, Legal, Financial)
209
-
210
- ```json
211
- {
212
- "MEMORY_MIN_CONFIDENCE": "0.9",
213
- "MEMORY_ENABLE_BM25": "true",
214
- "MEMORY_ENABLE_VECTOR_SEARCH": "true"
215
- }
216
- ```
217
-
218
- **Why**: Only store very certain facts, use both keyword and semantic matching.
98
+ ```typescript
99
+ import { MemoryService } from '@elizaos/plugin-memory';
219
100
 
220
- ---
101
+ // Get the service from runtime
102
+ const memoryService = runtime.getService('memory') as MemoryService;
221
103
 
222
- ## Basic Usage
104
+ // Store a long-term memory manually
105
+ await memoryService.storeLongTermMemory({
106
+ agentId: runtime.agentId,
107
+ entityId: userId,
108
+ category: LongTermMemoryCategory.SEMANTIC,
109
+ content: 'User prefers concise responses',
110
+ confidence: 0.9,
111
+ source: 'manual',
112
+ });
223
113
 
224
- The plugin works automatically once installed. No code changes required.
114
+ // Retrieve memories
115
+ const memories = await memoryService.getLongTermMemories(userId);
225
116
 
226
- ### How It Works
117
+ // Get session summaries
118
+ const summaries = await memoryService.getSessionSummaries(roomId);
119
+ ```
227
120
 
228
- 1. **Conversation**: Agent buffers messages
229
- 2. **Consolidation**: After threshold (default 12), LLM extracts persistent facts
230
- 3. **Storage**: Facts stored with confidence โ‰ฅ 0.7 (configurable)
231
- 4. **Retrieval**: Hybrid search (vector + BM25) with decay scoring
232
- 5. **Context**: Relevant memories added to prompts automatically
121
+ ## Database Setup
233
122
 
234
- ### Example Flow
123
+ The plugin uses ElizaOS's dynamic migration system. Database tables are automatically created when the plugin is loaded. The plugin defines three tables:
235
124
 
236
- ```
237
- User: "I'm a software engineer working on React. I prefer TypeScript."
238
- โ†’ [12 messages later, consolidation triggers]
239
- โ†’ Extracted: "User is a software engineer" (confidence: 0.95)
240
- โ†’ Extracted: "User works with React" (confidence: 0.92)
241
- โ†’ Extracted: "User prefers TypeScript" (confidence: 0.95)
242
-
243
- User: "What's the best state management for my project?"
244
- โ†’ Retrieves: React + TypeScript preferences
245
- โ†’ Agent: "For React with TypeScript, I'd recommend Zustand or..."
246
- ```
125
+ - **`long_term_memories`**: Stores persistent facts about users
126
+ - **`session_summaries`**: Stores conversation summaries
127
+ - **`memory_access_logs`**: Optional usage tracking for analytics
247
128
 
248
- ---
129
+ No manual migration is required - the schema is handled automatically by the runtime.
249
130
 
250
- ## Programmatic Access
131
+ ## Architecture
251
132
 
252
- ```typescript
253
- import { MemoryService, MemoryType, DecayFunction } from '@elizaos/plugin-memory';
133
+ ### Components
254
134
 
255
- // Get service
256
- const memoryService = runtime.getService<MemoryService>('memory');
135
+ #### Services
257
136
 
258
- // Store memory manually
259
- await memoryService.storeLongTermMemory({
260
- agentId: runtime.agentId,
261
- entityId: userId,
262
- roomId: roomId,
263
- type: MemoryType.SEMANTIC,
264
- content: 'User is allergic to peanuts',
265
- embeddingContext: '[Health fact]: User is allergic to peanuts',
266
- confidence: 1.0,
267
- decayRate: 0.0, // Never decays
268
- decayFunction: DecayFunction.NONE,
269
- source: { authorId: userId },
270
- metadata: { category: 'health', critical: true },
271
- });
137
+ - **MemoryService**: Core service managing all memory operations
138
+ - Tracks message counts for summarization triggers
139
+ - Stores and retrieves long-term memories
140
+ - Manages session summaries
141
+ - Provides formatted memory context
272
142
 
273
- // Search memories
274
- const memories = await memoryService.searchLongTermMemories({
275
- entityId: userId,
276
- query: 'What foods should I avoid?',
277
- type: MemoryType.SEMANTIC,
278
- limit: 5,
279
- minConfidence: 0.7,
280
- });
143
+ #### Evaluators
281
144
 
282
- // Get all memories by type
283
- const facts = await memoryService.getLongTermMemories(userId, MemoryType.SEMANTIC, 20);
284
- ```
145
+ - **summarizationEvaluator**: Runs after conversations reach threshold
146
+ - Generates comprehensive summaries using LLM
147
+ - Extracts topics and key points
148
+ - Archives old messages while preserving summaries
149
+ - **longTermExtractionEvaluator**: Periodically analyzes conversations
150
+ - Identifies facts worth remembering long-term
151
+ - Categorizes information semantically
152
+ - Assigns confidence scores
153
+ - Stores high-confidence memories
285
154
 
286
- ---
155
+ #### Providers
287
156
 
288
- ## Troubleshooting
157
+ - **longTermMemoryProvider**: Injects persistent user facts into context
158
+ - Runs early (position: 50) to establish user context
159
+ - Formats memories by category
160
+ - Provides "What I Know About You" context
161
+ - **shortTermMemoryProvider**: Provides conversation summaries
162
+ - Runs before recentMessages (position: 95)
163
+ - Includes recent session summaries
164
+ - Shows topics and message counts
289
165
 
290
- ### No memories being extracted
166
+ #### Actions
291
167
 
292
- **Check**:
168
+ - **rememberAction**: Handles explicit memory requests
169
+ - Triggers on keywords like "remember", "keep in mind", etc.
170
+ - Uses LLM to extract what to remember
171
+ - Categorizes and stores with confirmation
293
172
 
294
- 1. Has threshold been reached? (default: 12 messages)
295
- 2. Is LLM provider configured?
296
- 3. Check logs: `grep "consolidation" agent.log`
173
+ ## How It Works
297
174
 
298
- **Debug**:
175
+ ### Short-term Memory Flow
299
176
 
300
- ```typescript
301
- const memoryService = runtime.getService<MemoryService>('memory');
302
- console.log('Config:', memoryService.getConfig());
303
- ```
177
+ 1. **Tracking**: MemoryService tracks message count per room
178
+ 2. **Trigger**: When count reaches threshold (default: 50), summarizationEvaluator activates
179
+ 3. **Summarization**: LLM generates comprehensive summary of conversation
180
+ 4. **Archival**: Older messages deleted, summary stored, recent messages retained
181
+ 5. **Context Injection**: shortTermMemoryProvider injects summaries in future conversations
304
182
 
305
- ### Agent doesn't remember facts
183
+ ### Long-term Memory Flow
306
184
 
307
- **Check**:
185
+ 1. **Warm-up Period**: Extraction waits until 30+ messages (configurable) to ensure meaningful patterns
186
+ 2. **Monitoring**: longTermExtractionEvaluator runs periodically (every 10 messages after threshold)
187
+ 3. **Analysis**: LLM analyzes conversation for **persistent, important** facts worth remembering
188
+ 4. **Strict Filtering**: Applies cognitive science principles to extract only truly significant information
189
+ 5. **Storage**: High-confidence facts (โ‰ฅ0.85) stored in long_term_memories table
190
+ 6. **Retrieval**: longTermMemoryProvider injects relevant facts in all future conversations
308
191
 
309
- 1. Database: `SELECT * FROM long_term_memories WHERE isActive = true;`
310
- 2. Confidence: `WHERE confidence >= 0.7`
311
- 3. Decay scores (old memories may have decayed)
192
+ **Ultra-Strict Extraction Criteria**: The evaluator uses stringent criteria to prevent memory pollution:
312
193
 
313
- **Debug**:
194
+ - โœ… **DO Extract:**
195
+ - **Episodic**: Significant milestones, important incidents, major decisions with lasting impact
196
+ - **Semantic**: Professional identity, core expertise, established facts (explicitly stated or conclusively demonstrated)
197
+ - **Procedural**: Consistent workflows (3+ occurrences or explicitly stated), standard practices, methodologies
314
198
 
315
- ```typescript
316
- const memories = await memoryService.getLongTermMemories(userId, undefined, 50, true);
317
- console.log('Total:', memories.length, 'Active:', memories.filter((m) => m.isActive).length);
318
- ```
199
+ - โŒ **NEVER Extract:**
200
+ - One-time requests or tasks
201
+ - Casual conversations without lasting significance
202
+ - Exploratory questions or testing
203
+ - Temporary context or situational information
204
+ - Preferences from single occurrence
205
+ - Social pleasantries
206
+ - Common patterns everyone has
207
+ - General knowledge not specific to user
319
208
 
320
- ### High token usage
209
+ ### Manual Memory Flow
321
210
 
322
- **Solutions**:
211
+ 1. **Detection**: User says "remember that..." or similar trigger phrase
212
+ 2. **Validation**: rememberAction validates the request
213
+ 3. **Extraction**: LLM extracts what to remember and categorizes it
214
+ 4. **Storage**: Fact stored with 'manual' source and high confidence
215
+ 5. **Confirmation**: Agent confirms what was stored
323
216
 
324
- - Lower `MEMORY_CONSOLIDATION_THRESHOLD` (consolidate more often)
325
- - Reduce `MEMORY_RETRIEVAL_LIMIT` (fewer memories per query)
326
- - Increase `MEMORY_MIN_CONFIDENCE` (only high-quality facts)
327
- - Reduce `MEMORY_TOKEN_BUDGET` and `MEMORY_SUMMARY_TOKEN_BUDGET`
217
+ ## Performance Optimization
328
218
 
329
- ### Transient requests stored as facts
219
+ ### Context Reduction
330
220
 
331
- **Solutions**:
221
+ - Without plugin: 1000 messages = ~200,000 tokens
222
+ - With plugin: 1000 messages = ~20 summaries + 10 recent = ~25,000 tokens
223
+ - **Savings**: ~85% reduction in context size
332
224
 
333
- - Increase `MEMORY_MIN_CONFIDENCE` to 0.8+
334
- - Use better LLM model (GPT-4, Claude)
335
- - Customize extraction prompts in `prompts/consolidation.ts`
225
+ ### Token Efficiency
336
226
 
337
- ---
227
+ - Summaries are 1/10th the size of original conversations
228
+ - Long-term memories provide rich context in minimal tokens
229
+ - Recent messages still available for immediate context
338
230
 
339
- ## Database Schema
231
+ ### Database Optimization
340
232
 
341
- Tables auto-created on first load via ElizaOS dynamic migrations:
233
+ - Indexed queries for fast retrieval
234
+ - Separate tables for different memory types
235
+ - Optional vector search for semantic similarity (requires pgvector)
342
236
 
343
- ### `long_term_memories`
237
+ ## Best Practices
344
238
 
345
- Stores episodic, semantic, and procedural memories with:
239
+ ### For Users
346
240
 
347
- - Embeddings (pgvector)
348
- - Confidence scores
349
- - Decay rates
350
- - Access tracking
351
- - Soft deletes
241
+ - Use explicit commands: "Remember that...", "Keep in mind...", "Don't forget..."
242
+ - Provide clear, factual information for better storage
243
+ - Verify important memories were stored correctly
352
244
 
353
- ### `conversation_summaries`
245
+ ### For Developers
354
246
 
355
- Hierarchical conversation summaries with:
247
+ - Adjust thresholds based on your use case
248
+ - Monitor summarization quality with test conversations
249
+ - Use confidence thresholds to filter low-quality extractions
250
+ - Consider enabling vector search for large-scale deployments
356
251
 
357
- - Multi-level compression
358
- - Time ranges
359
- - Token estimates
360
- - Access tracking
252
+ ### Configuration Tips
361
253
 
362
- ---
254
+ **Short-term Memory:**
255
+ - **High-frequency chatbots**: Lower summarization threshold (10-15 messages)
256
+ - **Long-form conversations**: Higher threshold (20-30 messages)
257
+ - **Adjust retention**: Keep more recent messages for immediate context
363
258
 
364
- ## Architecture Highlights
259
+ **Long-term Memory:**
260
+ - **Conservative extraction**: Keep threshold at 30+ messages for better pattern recognition (default)
261
+ - **Aggressive extraction**: Lower threshold to 20 messages if needed (may reduce quality)
262
+ - **Balanced approach**: Default 0.85 confidence threshold ensures high-quality extractions
263
+ - **More permissive**: Lower confidence to 0.80 for more extractions (risk of lower quality)
264
+ - **Most strict**: Raise confidence to 0.90 for only the most certain facts
265
+ - **Frequent updates**: Lower extraction interval to 5-8 messages for faster learning
266
+ - **Conservative updates**: Keep default 10+ message interval to prevent over-extraction
365
267
 
366
- ### Memory Types
268
+ ## Advanced Features
367
269
 
368
- - **Episodic**: Time-anchored events ("User asked about X on Tuesday")
369
- - **Semantic**: Timeless facts ("User is allergic to peanuts")
370
- - **Procedural**: Skills and patterns ("User prefers git rebase")
270
+ ### Vector Search (Optional)
371
271
 
372
- ### Hybrid Retrieval
272
+ Enable semantic search for memories by:
373
273
 
374
- Combines:
274
+ 1. Installing pgvector extension
275
+ 2. Setting `MEMORY_VECTOR_SEARCH_ENABLED=true`
276
+ 3. Generating embeddings for memories
375
277
 
376
- - **Vector Search**: Semantic similarity (pgvector HNSW index)
377
- - **BM25**: Keyword matching with stemming
378
- - **Decay Scoring**: `Confidence ร— e^(-ฮปร—t) ร— (1 + log(accessCount))`
278
+ ### Memory Analytics
379
279
 
380
- ### Contextual Embeddings
280
+ Use the `memory_access_logs` table to:
381
281
 
382
- Enriches content before embedding:
282
+ - Track which memories are most frequently accessed
283
+ - Identify useful vs. unused memories
284
+ - Optimize extraction strategies
383
285
 
384
- - Raw: "It was terrible"
385
- - Enriched: "[Movie preference]: The movie Inception was terrible"
286
+ ### Custom Categories
386
287
 
387
- ### Contradiction Detection
288
+ The plugin uses three scientifically-grounded memory types from cognitive science. If you need additional categories for domain-specific use cases, you can extend the enum:
388
289
 
389
- - Detects conflicting facts via LLM
390
- - Soft deletes old memories (marks inactive)
391
- - Maintains provenance chain via `supersedesId`
290
+ ```typescript
291
+ export enum CustomMemoryCategory {
292
+ ...LongTermMemoryCategory,
293
+ MEDICAL_HISTORY = 'medical_history',
294
+ FINANCIAL_DATA = 'financial_data',
295
+ }
296
+ ```
392
297
 
393
- ---
298
+ **Note**: Consider carefully whether your custom category truly represents a different type of memory, or if it can be classified under episodic (events), semantic (facts), or procedural (how-to) memory.
394
299
 
395
300
  ## Testing
396
301
 
302
+ Run the test suite:
303
+
397
304
  ```bash
398
305
  cd packages/plugin-memory
399
306
  bun test
400
307
  ```
401
308
 
402
- Tests cover:
403
-
404
- - XML parsing
405
- - Memory consolidation
406
- - Decay algorithms
407
- - Contradiction detection
408
- - Hybrid retrieval
309
+ ## Troubleshooting
409
310
 
410
- ---
311
+ ### Summaries not generating
411
312
 
412
- ## Research & References
313
+ - Check that message threshold is reached
314
+ - Verify MemoryService is registered
315
+ - Check LLM provider is configured
413
316
 
414
- Based on comprehensive research documented in [`refactor.md`](./refactor.md):
317
+ ### Long-term memories not stored
415
318
 
416
- - **Cognitive Science**: Ebbinghaus forgetting curve, memory consolidation theory
417
- - **AI/RAG Systems**: MemGPT, GraphRAG, Contextual Retrieval (Anthropic), HyDE
418
- - **Agent Architecture**: A-MEM, AgentCore (AWS), MLE-Benchmark
319
+ - Verify `MEMORY_LONG_TERM_ENABLED=true`
320
+ - Check confidence threshold isn't too high
321
+ - Ensure facts are being extracted (check logs)
419
322
 
420
- Full analysis: [`EVALUATION.md`](./EVALUATION.md)
323
+ ### High token usage
421
324
 
422
- ---
325
+ - Lower summarization threshold
326
+ - Reduce number of retained recent messages
327
+ - Limit number of long-term memories retrieved
423
328
 
424
329
  ## License
425
330
 
426
331
  MIT
427
332
 
428
- ---
429
-
430
- ## Support
333
+ ## Contributing
431
334
 
432
- - **Research**: [`refactor.md`](./refactor.md)
433
- - **Evaluation**: [`EVALUATION.md`](./EVALUATION.md)
434
- - **Issues**: [GitHub Issues](https://github.com/elizaOS/eliza/issues)
435
- - **Discord**: [ElizaOS Community](https://discord.gg/elizaos)
335
+ Contributions welcome! Please see the main ElizaOS contributing guide.