lerim maintain command is the cold path for memory refinement. It runs offline maintenance over stored memories: merges duplicates, archives low-value items, consolidates related memories, and applies time-based decay to keep the memory store clean and relevant.
This is a service command - it requires a running Lerim server started via
lerim up or lerim serve.Syntax
What it does
- Scans existing memories - Reads all decision and learning markdown files from
<repo>/.lerim/memory/ - Identifies duplicates - Finds memories with similar titles and bodies
- Merges duplicates - Combines redundant memories into a single authoritative version
- Archives low-value items - Moves outdated or low-confidence memories to
memory/archived/ - Consolidates related memories - Merges closely related memories that should be unified
- Applies time-based decay - Reduces confidence scores for stale memories over time
- Updates metadata - Refreshes
updatedtimestamps and recalculates confidence scores
Parameters
Force maintenance even if a recent run was completed.By default,
maintain tracks the last run time and skips execution if maintenance ran recently (within the configured interval). Use --force to override this and run maintenance unconditionally.Preview mode: record a run but skip all actual memory changes.Shows what would be merged, archived, or updated without modifying any files. Useful for:
- Testing maintenance logic
- Previewing large-scale changes
- Verifying deduplication rules
Examples
Standard usage
Force maintenance
Preview mode
JSON output
Maintenance operations
Duplicate merging
Finds memories with similar content and merges them: Before:memory/archived/decisions/.
Low-value archiving
Memories are archived if:- Confidence score drops below threshold (default: 0.3)
- Age exceeds maximum staleness (default: 180 days)
- Marked as superseded by newer memories
Related memory consolidation
Closely related memories (e.g. multiple learnings about the same topic) are merged into a single, richer memory.Time-based decay
Confidence scores decrease over time for memories that haven’t been reinforced by recent sessions:- 0-30 days: No decay
- 30-90 days: 10% decay
- 90-180 days: 25% decay
- 180+ days: 50% decay (may be archived)
Sync vs maintain
| Command | Path | What it does | Frequency |
|---|---|---|---|
lerim sync | Hot path | Index sessions, extract new memories | High (every 10 min) |
lerim maintain | Cold path | Refine existing memories (merge, archive, decay) | Low (every 60 min) |
- Sync creates memories from sessions
- Maintain cleans up and refines the memory store
Automation
Maintenance runs automatically when using:- Docker service (
lerim up) - Maintain runs every 60 minutes by default - Daemon loop (
lerim daemon) - Maintain runs at configured interval - Manual (
lerim maintain) - Run on-demand
~/.lerim/config.toml:
Output
Human-readable:When to run maintain
Run manually when:
- After a large sync (e.g.
lerim sync --window all) - When you notice duplicate memories in the dashboard
- After changing deduplication rules in config
- To clean up before a fresh start
Let daemon handle it when:
- Using
lerim uporlerim daemon(runs automatically) - Maintenance is working well with default intervals
- You want hands-off memory management
Exit codes
| Code | Meaning |
|---|---|
0 | Maintenance completed successfully |
1 | Server not running or runtime error |
2 | Usage error (invalid arguments) |
Related commands
lerim sync- Extract new memories before maintaininglerim daemon- Run continuous sync + maintain looplerim status- Check last maintain timestamplerim memory reset- Destructive reset of all memorieslerim up- Start server before maintaining
Troubleshooting
”Lerim is not running”
Start the server first:Maintain doing nothing
Check if it ran recently:Too many duplicates
If deduplication isn’t catching duplicates:-
Preview what would be merged:
-
Adjust similarity threshold in config:
-
Run with force:
Aggressive archiving
If too many memories are being archived:-
Check archive threshold in config:
-
Restore archived memories manually:
Not enough archiving
If the memory store is cluttered:-
Lower archive threshold:
-
Run maintain more frequently:
-
Force immediate maintenance:
Preview changes safely
Before running maintenance on a large memory store:Memory lifecycle
- Creation -
lerim syncextracts memories from sessions - Reinforcement - Repeated mentions increase confidence
- Consolidation -
lerim maintainmerges related memories - Decay - Confidence decreases over time without reinforcement
- Archiving - Low-confidence or stale memories are archived
- Deletion - Archived memories can be manually deleted