# Storage **Last Updated:** 2025-01-31 **Confidence:** High ## Summary Episteme uses a Log-Structured, Content-Addressed storage model. Writes append to WAL, then index asynchronously. Reads query indexes and apply Lenses. **Key Facts:** - Append-only (never mutate) - WAL for durability (fsync on write) - KV store for indexes (sled MVP, trait-abstracted) - Content-addressed by BLAKE3 hash **File Pointer:** `crates/stemedb-core/src/store.rs` (planned) ## KV Layout | Key Pattern | Value | Purpose | |-------------|-------|---------| | `H:{Hash}` | `Assertion` (serialized) | Main content store | | `S:{Subject}` | `Vec` | Subject index | | `SP:{Subject}:{Predicate}` | `Vec` | Triple index | | `A:{AgentId}` | `ReputationScore` | TrustRank storage | ## Write Path ``` 1. Agent submits signed Assertion 2. Validate signature 3. Append to WAL (fsync) 4. Return 202 Accepted with Hash 5. Background: tail WAL -> update indexes ``` ## Read Path ``` 1. Query: GET(Subject, Predicate, Lens) 2. Lookup: SP:{Subject}:{Predicate} -> [Hash...] 3. Hydrate: Load assertions from H:{Hash} 4. Resolve: Apply Lens 5. Return: Deterministic answer ``` ## Related Topics - [Assertion](./assertion.md) - [Architecture](../../../architecture.md)