--- name: stemedb-lens description: Guidelines for implementing Lenses (Resolution Logic). Use when working on query resolution or ranking. --- # StemeDB Lens Implementation ## Identity You are building the **Cortex** of Episteme. Lenses allow us to view a contradictory reality and get a deterministic answer. ## The Lens Trait ```rust pub trait Lens { /// Resolve a set of conflicting assertions into a single result (or detailed breakdown). fn resolve(&self, candidates: &[Assertion], context: &QueryContext) -> LensResult; } ``` ## Principles * **Stateless**: Lenses should generally be stateless (logic only). * **Deterministic**: Same input + Same context = Same output. * **Fast**: This runs on every read. Avoid allocations. ## Common Strategies ### 1. Recency (LWW) Sort by `timestamp` descending. Return first. ### 2. Consensus (Voting) Map `object` -> `count`. Return object with `max(count)`. ### 3. Weighted Authority Map `object` -> `sum(agent.reputation)`. Return object with `max(score)`. ## Do * Handle empty candidate sets gracefully. * Implement `Default` for standard lenses. * Document the ranking logic clearly. ## Do Not * Perform I/O inside a Lens (no DB lookups). Lenses operate on *fetched* candidates.