MidOS Memory Cascade
by @msruruguay
Auto-escalating multi-tier memory search that cascades from in-memory cache through SQLite, grep, and LanceDB vector search to find the best answer with mini...
clawhub install midos-memory-cascadeπ About This Skill
name: midos-memory-cascade description: Auto-escalating multi-tier memory search that cascades from in-memory cache through SQLite, grep, and LanceDB vector search to find the best answer with minimal latency. metadata: {}
MidOS Memory Cascade
A self-tuning, auto-escalating search engine that tries each memory tier from fastest to slowest, stopping as soon as it finds a high-confidence answer.
What It Does
Instead of the agent deciding which storage layer to query, the cascade tries each tier automatically:
| Tier | Storage | Latency | Strategy | |------|---------|---------|----------| | T0 | In-memory session cache | <1ms | Exact + fuzzy key match | | T1 | JSON state files | <5ms | Filename + key match | | T2 | SQLite (pipeline_synergy.db) | <5ms | Structured SQL LIKE | | T3 | SQLite FTS5 | <1ms | Full-text keyword on 22K rows | | T4 | Grep over 46K chunks | ~3s | Brute-force ripgrep fallback | | T5 | LanceDB keyword (BM25) | slow | 670K vector rows, no embeddings | | T5b | LanceDB semantic | 3β30s | Embedding similarity, last resort |
Question routing: Queries starting with how/what/why/etc. skip keyword tiers and route directly to semantic search.
Self-learning: The cascade records which tier resolves each query. After enough history, evolve() learns shortcuts (skip directly to the winning tier) and marks consistently-empty tiers for skip.
Usage
Python API
from tools.memory.memory_cascade import recall, storeSearch across all tiers
result = recall("adaptive alpha reranking")
β {"answer": {...}, "tier": "T5:lancedb", "latency_ms": 340, "confidence": 0.87}
Write to the right storage automatically
store("pattern", content="...", tags=["ml", "reranking"])
CLI
# Search
python memory_cascade.py recall "query here"View tier resolution stats
python memory_cascade.py statsRun self-evolution (learn shortcuts + tier skips)
python memory_cascade.py evolve
recall() Options
recall(
query: str,
min_confidence: float = 0.5, # stop escalating at this threshold
max_tier: int = 6 # 0=T0 only, 6=all tiers
)
Returns:
{
"answer": { "source": "...", "text": "..." },
"confidence": 0.87,
"latency_ms": 340.2,
"tiers_tried": 3,
"resolved_at": "T5:lancedb",
"shortcut": null,
"question_routed": false,
"escalation": [...]
}
Requirements
hive_commons for LanceDB tiers (T5/T5b)tools.memory.memory_router for store() routingThe cascade degrades gracefully β if LanceDB is unavailable, it stops at grep (T4). All stdlib tiers (T0βT4) work with zero dependencies.
Architecture Notes
threading.Lock; stats writes use separate locksmsvcrt on Windows, fcntl on Unix)knowledge/SYSTEM/cascade_stats.json accumulates hit rates per tierBuilt with MidOS. 1 of 200+ skills. Full ecosystem at midos.dev/pro
π‘ Examples
Python API
from tools.memory.memory_cascade import recall, storeSearch across all tiers
result = recall("adaptive alpha reranking")
β {"answer": {...}, "tier": "T5:lancedb", "latency_ms": 340, "confidence": 0.87}
Write to the right storage automatically
store("pattern", content="...", tags=["ml", "reranking"])
CLI
# Search
python memory_cascade.py recall "query here"View tier resolution stats
python memory_cascade.py statsRun self-evolution (learn shortcuts + tier skips)
python memory_cascade.py evolve
recall() Options
recall(
query: str,
min_confidence: float = 0.5, # stop escalating at this threshold
max_tier: int = 6 # 0=T0 only, 6=all tiers
)
Returns:
{
"answer": { "source": "...", "text": "..." },
"confidence": 0.87,
"latency_ms": 340.2,
"tiers_tried": 3,
"resolved_at": "T5:lancedb",
"shortcut": null,
"question_routed": false,
"escalation": [...]
}