Strict Context Search & Supersession Provenance #18
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Implement contextual search (
POST /v1/context/search/life context search) and contextual rationale retrieval with strictall_stricttag scoping, supersession tracking, and stale provenance labeling.Background & Technical Rationale
Semantic memory retrieval via vector embeddings introduces significant operational hazards if left unconstrained: semantic drift, cross-item leakage, outdated context hallucination, and contradiction of confirmed factual state. Life establishes rigorous governance rules for contextual search:
Recalled memory text is NEVER authoritative for current calendar or task state!
Consider an operational scenario where a user asks: "Why is the portfolio outline task postponed?" A semantic memory recall might return: "User chose to postpone the portfolio outline until next week." However, live Radicale state shows that the user completed the task yesterday (
STATUS: COMPLETED).Promoting the recalled memory to current authority would hallucinate a false postponement. Under Life's architecture, Radicale live reads are unconditionally authoritative for current state. The system must report the live calendar fact first (
COMPLETED), citing the recalled memory strictly as historical background rationale.When querying Hindsight for context regarding a specific item (
life context search --item-id <id>or internal "Why" resolution):tags: ["life-item:<hash>"]andtags_match: "all_strict".all_strictrequires that returned memories contain all specified tags and strictly excludes untagged memories.When a user updates a rationale, plan, or decision, Life commits a new context event with a
supersedes_context_idlink inlife_eventsprovenance.Because Hindsight embeddings and consolidated observations may still rank the older memory highly, Life maintains a local supersession ledger in SQLite. When memories are recalled:
source_event_idmetadata from each recalled memory.context_stalewarning, discloses the superseding event ID, and presents the newer rationale as authoritative.temporal_windowin Hindsight influences temporal retrieval ranking, but is not an exhaustive filter (memories outside the window may still appear in search results). All authoritative counts, ranges, and coverage metrics come from SQLite WAL, not memory recall.Exact Technical References & Specifications
Normative Recall Request Payload
From
docs/technical/hindsight.md(lines 43–45):Normative recall rules (
hindsight.md, lines 47–51):Verification Matrix Scenarios
From
docs/technical/verification.md(lines 25, 116, 119):CLI & API Routes and Payloads
From
docs/technical/cli-api.md:life context add --input -:POST /v1/context(scope:write)life context search --input -:POST /v1/context/search(scope:read)Context add:text, optionalitem_id,reason,supersedes_context_id\rightarrowoperation_id, source event ID, delivery state.Context search:query, optionalitem_idand bounded temporal preference\rightarrowcontext hits with source/document IDs, freshness and superseded markers.context_stale,context_unavailable.Section Citations
docs/technical/hindsight.md: Section Recall and stale context (lines 39–53), Section Compatibility requirements and sources (lines 53–57).docs/technical/verification.md: Section Workflow scenarios (line 25, Scenario W11), Section Integration scenarios (lines 116, 119, Scenarios I02, I05).docs/technical/cli-api.md: Section Command-to-route table (lines 46–47), Section Command payloads and results (lines 93–94), Section Error identifiers (line 127).What to Build
1. Recall Query Builder (
src/hindsight/recall.rs)search_context:item_idprovided):life-item:<sha256>).RecallQuerywithtags = vec![item_tag]andtags_match = "all_strict".POST /v1/default/banks/{bank_id}/recall.item_idomitted):RecallQuerywithout tags; search across entire bank.2. Supersession Ledger & Provenance Filter (
src/hindsight/provenance.rs)life_eventstable to build the supersession map:source_event_idfrom metadata.source_event_idappears assupersedes_idorcorrection_targetof a newer event, mark the hit asis_stale = trueandsuperseded_by = Some(newer_event_id).3. Calendar Authority Arbitrator (
src/hindsight/why.rs)item_projectionwithout live confirmation; if Radicale is unavailable, report calendar unavailability rather than promoting cached state to live authority (docs/technical/hindsight.md:49).STATUS: COMPLETED):4. Axum Routes & CLI Handlers
src/api.rs:POST /v1/context:life_eventswith optionalsupersedes_context_id.outbox.operation_id, sourceevent_id, andcontext_delivery: "pending".POST /v1/context/search:{ "query": String, "item_id": Option<String> }.{ "hits": Vec<ContextHit> }with warnings.src/cli.rs:life context add --input - [--operation-id KEY] [--json]life context search --input - [--json]5. Integration Test Suite (
tests/hindsight_search_tests.rs)life-item:other, and memories taggedlife-item:target.item_idof target.tags_match: "all_strict".STATUS: COMPLETED.COMPLETEDas authoritative, labeling memory as historical rationale.C_1(evt_01), then record contextC_2(evt_02) withsupersedes_context_id: "evt_01".C_1.C_1withis_stale: true,superseded_by: "evt_02", andcontext_stalewarning.Acceptance Criteria
tags: ["life-item:<hash>"]andtags_match: "all_strict", excluding untagged or foreign-tagged memories (Scenario I02).is_stale: true, cite the superseding event ID, and emitcontext_stalewarnings (Scenario I05).supersedes_context_id.life context addandlife context searchcontracts.Notes
captures.rswas refactored onto the same helpers.all_strictand the item tag are structurally enforced (private fields, constructors only), and the supersession chain walk is bounded against a reciprocal-pair cycle.Cargo.tomlauthors chore lands with #35.Blocked by
Issue #018: Strict Context Search & Supersession Provenanceto Strict Context Search & Supersession Provenance