Memory System
Mia maintains a persistent memory store that survives across sessions, restarts, and conversations. Facts, preferences, and project context are stored locally and injected into AI dispatches when relevant.
Architecture
Section titled “Architecture”The memory system uses SQLite with FTS5 (full-text search) and BM25 ranking for relevance scoring. No vector databases or embeddings — just fast, local full-text search.
┌────────────────────────────────────────┐│ Memory Store API │├────────────────────────────────────────┤│ store() · query() · delete() ││ stats() · prune() │├────────────────────────────────────────┤│ LRU Query Cache ││ (30-second TTL) │├────────────────────────────────────────┤│ SQLite + FTS5 (BM25) ││ ~/.mia/memory.db │└────────────────────────────────────────┘Entry Types
Section titled “Entry Types”| Type | Description | Example |
|---|---|---|
conversation | Chat history | Prior messages from a session |
fact | Extracted knowledge | ”Uses pnpm workspaces” |
context | Codebase/workspace info | ”React + TypeScript monorepo” |
summary | Conversation compaction | Compressed prior conversation |
How Facts Get Stored
Section titled “How Facts Get Stored”Automatic Extraction
Section titled “Automatic Extraction”After every successful AI dispatch, the MemoryExtractor middleware runs asynchronously:
- Analyzes the conversation turn for extractable facts
- Uses the active AI plugin to identify key information
- Stores facts with timestamps and metadata
- Non-blocking — doesn’t delay the response
{ "pluginDispatch": { "memoryExtraction": { "enabled": true, "minDurationMs": 5000, "maxFacts": 5 } }}Manual Storage
Section titled “Manual Storage”Store facts explicitly via CLI or chat:
# CLI commandmia memory add "prefers functional components over class components"
# In chat/remember uses PostgreSQL for the main databaseHow Facts Get Retrieved
Section titled “How Facts Get Retrieved”During context preparation, the ContextPreparer queries the memory store for facts relevant to the current prompt:
- Sanitize query — Strip special characters, join terms with OR
- FTS5 search — Full-text search with BM25 ranking
- Score and rank — Relevance score + recency weighting
- Inject into context — Top N results added to the plugin context
By default, up to 5 facts are injected per dispatch.
Query Caching
Section titled “Query Caching”Repeated queries are cached to reduce database load:
- Cache type: LRU (Least Recently Used)
- TTL: 30 seconds
- Max entries: Configurable (default varies)
- Eviction: Automatic on TTL expiry or capacity overflow
Maintenance
Section titled “Maintenance”TTL Pruning
Section titled “TTL Pruning”Old entries are automatically pruned:
- Default TTL: 30 days
- Prune interval: Configurable (default: every few hours)
- Entries older than TTL are permanently deleted
Row Cap
Section titled “Row Cap”FIFO eviction prevents unbounded growth:
- Default cap: 10,000 entries
- When exceeded, oldest entries are deleted first
- Configurable via
memory.maxRows
Manual Management
Section titled “Manual Management”mia memory list # Recent factsmia memory search "react" # Search by keywordmia memory stats # Counts by type, total sizeConfiguration
Section titled “Configuration”{ "memory": { "ttlDays": 30, "queryCacheMaxEntries": 100, "maxRows": 10000, "pruneIntervalHours": 6 }}