Skip to main content
Cohaku organizes memories into three layers, each with different priority and lifecycle characteristics. Memory Layers

The Three Layers

LayerPriorityPurposeTTL
Rule10 (highest)Persistent instructions and constraintsNone
Working5Current session context, temporary notesOptional
Long-term1General knowledge, facts, patternsNone

Rule Layer

Rules are the highest priority memories. They represent instructions, constraints, and preferences that should always be active.
"Always use TypeScript strict mode"
"Never commit directly to main"
"Use pnpm, not npm"
Rules are never expired and always included first in get_context results.

Working Layer

Working memories represent temporary, session-relevant context. They support optional TTL via expiresAt.
"Currently debugging the auth flow in src/auth.ts"
"The user prefers verbose error messages for this session"
Expired working memories are automatically excluded from get_context and listMemoriesByLayer.

Long-term Layer

Long-term memories store general knowledge accumulated over time.
"The project uses React 19 with TypeScript and Vite"
"The database schema was last migrated on 2026-01-15"

Context Budget Allocation

When get_context is called with a budget of N memories:
  1. Rule — Fetch all rules (up to N)
  2. Working — Fetch 60% of the remaining budget
  3. Long-term — Fill the rest
Budget: 50 memories
├── Rules: 5 (all rules included)
├── Working: ceil((50 - 5) * 0.6) = 27
└── Long-term: 50 - 5 - 27 = 18

Scoring

When searching with search_memories, each memory receives a hybrid score:
score = semantic * 0.4 + bm25 * 0.3 + recency * 0.2 + salience * 0.1
ComponentDescription
SemanticCosine similarity from vector search (0-1)
BM25Normalized full-text search rank (0-1)
RecencyExponential decay from lastAccessedAt (half-life: 24h)
Salienceimportance decayed over time
Weights are configurable per-query via the weights parameter.