@rlabs-inc/memory 0.3.5 → 0.3.6

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.
package/README.md CHANGED
@@ -55,25 +55,73 @@ Uses `all-MiniLM-L6-v2` for 384-dimensional embeddings. Memories are retrieved b
55
55
  Sub-microsecond vector search via fsdb
56
56
  ```
57
57
 
58
- ### 10-Dimensional Scoring
59
- Memories are scored across multiple dimensions:
58
+ ### Precision-First Retrieval Algorithm
59
+
60
+ The retrieval system uses a two-phase scoring approach with dual gatekeepers. Philosophy: **quality over quantity, silence over noise**.
61
+
62
+ **Phase 1 - Relevance (max 35%)** - Must pass 8% gatekeeper to continue
60
63
 
61
64
  | Dimension | Weight | Description |
62
65
  |-----------|--------|-------------|
63
- | Vector similarity | 10% | Semantic match to your message |
64
- | Trigger phrases | 10% | Activation patterns set by curator |
65
- | Tag matching | 5% | Keyword overlap |
66
- | Question types | 5% | "How", "why", "what" alignment |
67
- | Importance | 20% | Curator's assessment |
68
- | Temporal | 10% | Persistent vs session vs temporary |
69
- | Context | 10% | Technical, personal, debugging... |
70
- | Confidence | 10% | Curator's certainty |
71
- | Emotion | 10% | Joy, frustration, discovery... |
72
- | Problem-solution | 5% | Bug fix patterns |
66
+ | Trigger phrases | 11% | Handcrafted activation patterns (primary signal) |
67
+ | Vector similarity | 9% | Semantic embedding match |
68
+ | Semantic tags | 6% | Direct keyword overlap |
69
+ | Word overlap | 5% | Corroboration from domain, feature, reasoning |
70
+ | Question types | 2% | How/why/what pattern matching |
71
+ | Domain/feature | 2% | Specific area matching |
72
+
73
+ **Phase 2 - Value (max 65%)** - Only calculated if relevance passes
74
+
75
+ | Dimension | Weight | Description |
76
+ |-----------|--------|-------------|
77
+ | Importance weight | 16% | Curator's assessment (most influential) |
78
+ | Context alignment | 10% | Context type matching message intent |
79
+ | Confidence score | 8% | Curator's certainty |
80
+ | Temporal score | 8% | Eternal > long-term > short-term |
81
+ | Action required | 7% | Priority boost for actionable items |
82
+ | Emotional resonance | 6% | Emotional context matching |
83
+ | Problem-solution | 5% | Utility for debugging |
84
+ | Awaiting flags | 5% | Boost for pending implementation/decisions |
85
+
86
+ **Final Gatekeeper**: Total score must exceed 40% to surface. Returns nothing if nothing qualifies.
87
+
88
+ ### Global vs Project Memories
89
+
90
+ Memories are stored in two scopes:
91
+
92
+ - **Global**: Personal memories, philosophy, preferences, cross-project breakthroughs - shared across ALL projects
93
+ - **Project**: Technical details, debugging insights, project-specific decisions - isolated per project
94
+
95
+ Global memories are retrieved alongside project memories, with a maximum of 2 globals per retrieval (technical types prioritized).
73
96
 
74
97
  ### Smart Curation
75
98
  At session end (or before context compaction), the same Claude instance reviews the conversation and extracts memories. No API key needed—uses Claude Code's `--resume` flag.
76
99
 
100
+ ### Memory Manager Agent
101
+
102
+ After curation, an autonomous manager agent organizes the memory store:
103
+
104
+ - **Supersedes** outdated memories when new information replaces old
105
+ - **Resolves** unresolved/todo memories when solutions emerge
106
+ - **Links** related memories via relationship fields
107
+ - **Updates** personal primer with new personal context
108
+
109
+ The manager runs in a sandboxed environment with access only to memory storage directories.
110
+
111
+ ### Personal Memories Control
112
+
113
+ Personal memory extraction can be disabled for shared or professional environments:
114
+
115
+ ```bash
116
+ # Via environment variable
117
+ MEMORY_PERSONAL_ENABLED=0 memory serve
118
+
119
+ # Or in configuration
120
+ personalMemoriesEnabled: false
121
+ ```
122
+
123
+ When disabled, the curator skips personal/relationship context extraction.
124
+
77
125
  ### Session Primer
78
126
  First message of each session receives temporal context:
79
127
 
@@ -128,9 +176,14 @@ Compact visual representation for efficient parsing:
128
176
  │ ┌─────────────┐ ┌──────────────┐ ┌───────────────┐ │
129
177
  │ │ Engine │ │ Embeddings │ │ Curator │ │
130
178
  │ │ (context) │ │ (MiniLM) │ │ (CLI resume) │ │
131
- │ └──────┬──────┘ └──────────────┘ └───────────────┘
132
- │ │
133
- │ ▼
179
+ │ └──────┬──────┘ └──────────────┘ └───────┬───────┘
180
+ │ │
181
+
182
+ │ │ ┌───────────────┐ │
183
+ │ │ │ Manager │ │
184
+ │ │ │ (CLI sandbox) │ │
185
+ │ │ └───────┬───────┘ │
186
+ │ ▼ │ │
134
187
  │ ┌─────────────────────────────────────────────────┐ │
135
188
  │ │ fsdb │ │
136
189
  │ │ (markdown files + parallel arrays) │ │
@@ -139,9 +192,12 @@ Compact visual representation for efficient parsing:
139
192
 
140
193
 
141
194
  ~/.local/share/memory/
142
- ├── memories/ # Curated memories as .md
143
- ├── sessions/ # Session metadata
144
- └── summaries/ # Session summaries
195
+ ├── global/
196
+ │ └── memories/ # Personal, philosophy (shared)
197
+ └── {project-id}/
198
+ ├── memories/ # Project-specific memories
199
+ ├── sessions/ # Session metadata
200
+ └── summaries/ # Session summaries
145
201
  ```
146
202
 
147
203
  ## Storage Format
@@ -150,17 +206,33 @@ Memories are stored as human-readable markdown with YAML frontmatter:
150
206
 
151
207
  ```markdown
152
208
  ---
209
+ # Core fields (v1)
153
210
  importance_weight: 0.9
211
+ confidence_score: 0.85
154
212
  context_type: technical
155
213
  temporal_relevance: persistent
156
- semantic_tags:
157
- - embeddings
158
- - vectors
159
- - memory-system
160
- trigger_phrases:
161
- - working with embeddings
162
- - vector search
163
- embedding: [0.023, -0.041, 0.087, ...] # 384 dimensions
214
+ semantic_tags: [embeddings, vectors, memory-system]
215
+ trigger_phrases: [working with embeddings, vector search]
216
+ question_types: [how, what]
217
+ knowledge_domain: architecture
218
+ emotional_resonance: discovery
219
+
220
+ # Lifecycle fields (v2)
221
+ schema_version: 2
222
+ status: active # active, pending, superseded, deprecated, archived
223
+ scope: project # global or project
224
+ temporal_class: long_term # eternal, long_term, medium_term, short_term, ephemeral
225
+ fade_rate: 0.02 # decay per session (0 = no decay)
226
+ domain: embeddings
227
+ feature: vector-search
228
+
229
+ # Relationships
230
+ related_to: [memory-xyz, memory-abc]
231
+ supersedes: memory-old-id
232
+ superseded_by: null
233
+
234
+ # Embedding (384 dimensions)
235
+ embedding: [0.023, -0.041, 0.087, ...]
164
236
  ---
165
237
 
166
238
  Embeddings are 384-dimensional vectors generated by all-MiniLM-L6-v2.
@@ -179,15 +251,20 @@ Benefits:
179
251
  memory serve # Start memory server (default port 8765)
180
252
  memory serve --port 9000 # Custom port
181
253
  memory serve --verbose # Detailed logging
254
+ memory serve --quiet # Minimal output
182
255
 
183
256
  memory install # Set up Claude Code hooks
184
257
  memory install --force # Overwrite existing hooks
258
+ memory install --gemini # Install for Gemini CLI instead
185
259
 
186
260
  memory doctor # Health check
187
261
  memory doctor --verbose # Detailed diagnostics
188
262
 
189
263
  memory stats # Show memory statistics
190
264
  memory stats --project x # Project-specific stats
265
+
266
+ memory migrate # Upgrade memories to latest schema (v1 → v2)
267
+ memory migrate --dry-run # Preview changes without applying
191
268
  ```
192
269
 
193
270
  ## Environment Variables
@@ -197,6 +274,13 @@ MEMORY_PORT=8765 # Server port
197
274
  MEMORY_HOST=localhost # Server host
198
275
  MEMORY_STORAGE_MODE=central # 'central' or 'local'
199
276
  MEMORY_API_URL=http://localhost:8765 # For hooks
277
+
278
+ # Feature toggles
279
+ MEMORY_MANAGER_ENABLED=1 # Enable/disable memory manager agent (default: 1)
280
+ MEMORY_PERSONAL_ENABLED=1 # Enable/disable personal memory extraction (default: 1)
281
+
282
+ # Optional: for SDK curation mode (alternative to CLI mode)
283
+ ANTHROPIC_API_KEY=sk-... # Uses SDK instead of CLI for curation
200
284
  ```
201
285
 
202
286
  ## How It Works
@@ -206,21 +290,30 @@ When you start Claude Code, the `SessionStart` hook injects a primer with:
206
290
  - Time since last session
207
291
  - Previous session summary
208
292
  - Project status
293
+ - Personal primer (relationship context, injected every session)
209
294
  - Current datetime for temporal awareness
210
295
 
211
296
  ### 2. Every Message
212
297
  The `UserPromptSubmit` hook:
213
298
  1. Embeds your message (~5ms)
214
- 2. Searches stored memories using 10-dimensional scoring
215
- 3. Filters through gatekeeper (relevance > 5%, total > 30%)
216
- 4. Injects top matches into your message context
299
+ 2. Searches both global and project memories
300
+ 3. Applies two-phase scoring with dual gatekeepers
301
+ 4. Injects top matches (max 5 by default, max 2 global)
217
302
 
218
303
  ### 3. Session End
219
304
  The `PreCompact` or `SessionEnd` hook triggers curation:
220
305
  1. Resumes the same Claude session via CLI
221
306
  2. Claude reviews the conversation
222
- 3. Extracts important memories with rich metadata
307
+ 3. Extracts important memories with rich metadata (v2 lifecycle fields)
223
308
  4. Stores as markdown files with embeddings
309
+ 5. Determines scope: global (personal/philosophy) vs project (technical)
310
+
311
+ ### 4. Memory Management (Async)
312
+ After curation completes, the manager agent:
313
+ 1. Scans for outdated memories to supersede
314
+ 2. Resolves unresolved/todo items when solutions appear
315
+ 3. Links related memories together
316
+ 4. Updates the personal primer with new relationship context
224
317
 
225
318
  ## Requirements
226
319