Memory Lifecycle
CEMS memories go through several stages from creation to archival:1. Creation
Memories are created via:- Skills:
/remember,/share - CLI:
cems add - MCP tools:
memory_add - Hooks: automatic extraction during sessions
- Observer: session learning observations
- Indexing:
cems index repo
- Content is received and validated
- Atomic facts are extracted
- Check for existing similar memories (cosine similarity)
- Decision: ADD (new), UPDATE (modify), or DUPLICATE (skip)
- Generate embedding via text-embedding-3-small (1536 dimensions)
- Store in PostgreSQL with pgvector
- Update access tracking
2. Active Use
Access Tracking: Every memory search that returns a result triggers access tracking:last_accessed_attimestamp updatedaccess_countincremented- Feedback tracked via
memory_log_shownAPI endpoint
- Important memories (frequently accessed)
- Stale memories (never or rarely accessed)
- Relevant memories (high user satisfaction)
| Stage | What It Does | LLM Calls |
|---|---|---|
| 1. Query Understanding | LLM routes to vector or hybrid strategy | 1 |
| 2. Query Synthesis | LLM expands query into 2-5 search terms | 1 |
| 3. HyDE | Generates hypothetical ideal answer | 1 |
| 4. Candidate Retrieval | pgvector HNSW + tsvector BM25 | 0 |
| 5. RRF Fusion | Reciprocal Rank Fusion | 0 |
| 6. Relevance Filtering | Remove low-quality results | 0 |
| 7. Scoring Adjustments | Time decay, priority boost | 0 |
| 8. Token-Budgeted Assembly | Greedy selection | 0 |
vector- Fast (0 LLM calls)hybrid- Thorough (3-4 LLM calls)auto- Smart routing (default)
3. Consolidation
Schedule: Nightly at 3 AM Purpose: Merge semantic duplicates to reduce memory clutter Process:- Find memories with high cosine similarity (>= 0.92)
- Group by similarity clusters
- Merge duplicate memories into one canonical version
- Update references and embeddings
- Archive merged duplicates
- Nearly identical memories from different sessions
- Rephrased versions of the same fact
- Updated versions of outdated information
- Pinned memories (never consolidated)
- Memories with
pin_reasonset - Foundation/constitution memories
4. Summarization
Schedule: Weekly on Sunday at 4 AM Purpose: Compress old memories and prune stale entries Process:- Identify old, low-access memories (>30 days old, <2 accesses)
- Group related memories by project/category
- Generate compressed summaries using LLM
- Replace verbose memories with concise versions
- Archive completely stale memories (never accessed)
- Age > 90 days AND access_count = 0
- Age > 180 days AND access_count < 2
- Marked as archived/deleted
- Never used (observation_count = 0 for observer memories)
- Pinned memories
- Foundation guidelines
- Constitution/playbook rules
- Gate rules
- Recently accessed memories (<30 days)
5. Re-indexing
Schedule: Monthly on the 1st at 5 AM Purpose: Rebuild embeddings and archive dead memories Process:- Re-generate embeddings for all active memories
- Update vector indexes (HNSW)
- Archive memories that failed re-indexing
- Rebuild graph connections
- Update metadata and statistics
- Embedding model updates
- Index corruption recovery
- Performance optimization
- Metadata corrections
6. Archive
Soft Delete: Default deletion mode (preserves for audit):deleted_attimestamp set- Won’t appear in searches
- Can be recovered by admin
- Preserved for compliance
- Memory completely removed from database
- Embeddings deleted
- Graph connections removed
- Cannot be recovered
- User deletion:
/forgetorcems delete - Maintenance pruning (stale memories)
- Consolidation (duplicate resolution)
- Manual admin action
Memory Scopes
Personal Memories
Visibility: Only the user who created them Use Cases:- Individual preferences (“I prefer dark mode”)
- Personal workflow patterns
- Private coding style choices
- Learning notes and reminders
Shared Memories
Visibility: All users in the same team Requirements: Must haveCEMS_TEAM_ID configured
Use Cases:
- Team conventions and standards
- Architecture decisions (ADRs)
- Deployment processes
- Codebase patterns
- Onboarding knowledge
Team Configuration
Set team ID in credentials:Memory Categories
Categories help organize and filter memories:| Category | Use Cases | Examples |
|---|---|---|
preferences | Personal choices, style | ”I prefer dark mode”, “Use 2-space tabs” |
conventions | Team standards, patterns | ”Snake_case for columns”, “REST versioning” |
architecture | System design, ADRs | ”Microservices via queue”, “PostgreSQL for DB” |
decisions | Important choices | ”Chose TypeScript”, “Deploy via Docker” |
workflow | Processes, procedures | ”Deploy to staging first”, “PR review required” |
errors | Debugging insights | ”CORS needs credentials:true”, “JWT expires 24h” |
learnings | Insights, TIL | ”Cursor position in editor”, “Cache invalidation” |
general | Uncategorized | Default for unspecified |
guidelines | Foundation rules | Constitution, playbook rules |
gate-rules | PreToolUse blocking | ”Never deploy to prod via CLI” |
Memory Tags
Tags provide flexible filtering and grouping: Common Tags:foundation,constitution- Foundation guidelinesplaybook,operational- Playbook rulesprinciple:01,rule-id:p01- Rule identifiersauth,security- Security-relateddeploy,process- Deploymenttesting,quality- Quality assurance- Project-specific tags
Pinning Memories
Pinned memories are protected from automatic maintenance: What Pinning Does:- Prevents consolidation
- Prevents pruning
- Prevents summarization
- Prevents archival by maintenance jobs
- Foundation guidelines and rules
- Critical architectural decisions
- Gate rules for PreToolUse hook
- Canonical documentation references
- Onboarding checklists
- “foundational constitution memory”
- “critical architecture decision”
- “gate rule for production safety”
- “canonical team convention”
Best Practices
What to Store
Good candidates:- User preferences and style choices
- Project conventions and naming patterns
- Architecture and infrastructure decisions
- Debugging insights and solutions to recurring problems
- Workflow patterns and deployment processes
- Foundation guidelines and rules
- Gate rules for safety enforcement
- Session-specific context (current task, temporary state)
- Information already in the codebase
- Build output or error messages being debugged right now
- Speculative conclusions from a single observation
- Secrets or credentials
- Large code blocks (use references instead)
Memory Quality
Write Atomic Facts: Good:Project Context
Always include project context for better recall:- Same-project memories are boosted in search
- Cross-project noise is reduced
- Maintenance jobs group by project
- Observer associates sessions with projects
Search Strategy
Use Natural Language:memory_get:
Maintenance Timing
Run maintenance during off-hours to avoid disrupting active sessions: Scheduled Times:- Consolidation: 3:00 AM
- Observation Reflection: 3:30 AM
- Summarization: Sunday 4:00 AM
- Re-indexing: 1st of month 5:00 AM
Observer Integration
The observer daemon automatically learns from sessions: What It Observes:- High-level workflow patterns
- Tool usage and preferences
- Project structure and conventions
- Deployment processes
- Error resolution patterns
- Tagged with
observerorsession:* - Include project context
- Incremental updates during sessions
- Finalized on session end
Storage Details
Database Schema
memory_documents:- Document-level metadata
- User/team scoping
- Categories and tags
- Soft-delete support
- Pinning and access tracking
- Chunked content (for large documents)
- 1536-dim vector embeddings
- HNSW index for vector search
- Full-text search (tsvector + GIN index)
- Authentication via bcrypt-hashed API keys
- Team membership
Embedding Model
Model: text-embedding-3-small Provider: OpenRouter Dimensions: 1536 Features:- Batch support for bulk operations
- Semantic similarity via cosine distance
- HNSW index for fast approximate search
Vector Search
Index Type: HNSW (Hierarchical Navigable Small World) Distance Metric: Cosine similarity Parameters:m= 16 (connections per node)ef_construction= 64 (build quality)ef_search= 40 (query quality)
- 98% recall@5 on benchmark
- Sub-10ms query latency (10k memories)
Full-Text Search
Index Type: GIN (Generalized Inverted Index) Features:- PostgreSQL tsvector
- BM25 ranking
- Stemming and stop words
- Combined with vector search via RRF fusion
Troubleshooting
Memory Not Being Recalled
Diagnosis:- Query too vague (use natural language)
- Wrong scope (check personal vs shared)
- Project mismatch (cross-project penalty)
- Relevance threshold too high
Duplicate Memories
Run consolidation:Stale Memories
Run summarization:Poor Search Quality
Debug:- Enable query synthesis:
--no-synthesisOFF - Enable graph traversal:
--no-graphOFF - Increase token budget:
--max-tokens 8000 - Run re-indexing:
cems maintenance run reindex
Related Pages
- Skills & Commands - Skills and slash commands reference
- CLI Usage - Command-line interface reference
- Observer Daemon - Background session learning