Implement the Statement table, the three statement kinds (Fact, Preference, Event), supersession chains, contradiction handling, and the statement HNSW for semantic retrieval of statements.
- Phase 16 complete.
19_statements/00_purpose.md17_knowledge_model/02_three_statement_kinds.md25_provenance_versioning/00_purpose.md
Statement,StatementKind,StatementObject,Predicatetypes inbrain-core.- redb tables:
statements,statements_by_subject,statements_by_predicate,statements_by_object_entity,statements_by_event_time,statements_by_evidence,statement_chain,evidence_overflow,predicates. - Statement HNSW per shard.
- Wire opcodes 0x40-0x46.
- SDK helpers for Fact, Preference, Event.
Reads: 19_statements/00_purpose.md (schema).
Writes: crates/brain-core/src/statement.rs.
Done when: Statement, StatementObject, EvidenceRef types compile and round-trip.
Pitfalls: The tagged union for StatementObject is tricky for rkyv. Test all variants.
Reads: 19_statements/00_purpose.md (predicate vocabulary section).
Writes: crates/brain-metadata/src/predicates.rs.
Done when: Predicate defines / lookups by (namespace, name). Builtin predicates auto-registered.
Pitfalls: Namespace separator (:); validate predicate name characters.
Reads: 19_statements/00_purpose.md (indexes section).
Writes: crates/brain-metadata/src/statement_ops.rs.
Done when: statement_create writes to statements table and all relevant indexes in one transaction.
Pitfalls: Many indexes. Use a helper that takes the statement and dispatches index writes. Test that supersession-chain updates work.
Reads: 17_knowledge_model/02_three_statement_kinds.md (supersession rules).
Writes: crates/brain-core/src/supersession.rs.
Done when: creating a Preference with same (subject, predicate) supersedes the existing current one. Chain root computed correctly.
Pitfalls: Compute chain_root: if old has no supersedes, root is old.id; else inherit from old.
Reads: 17_knowledge_model/02_three_statement_kinds.md (contradiction handling).
Writes: crates/brain-core/src/contradiction.rs.
Done when: when two current Facts have same (subject, predicate) but different object, both are stored; list_contradictions returns them.
Pitfalls: Don't auto-resolve. Surface to the caller.
Reads: 26_knowledge_storage/00_purpose.md (statement HNSW).
Writes: crates/brain-index/src/statement_hnsw.rs.
Done when: statements get an embedding (predicate + object_text + subject_canonical_name) and are indexed. Search returns ranked StatementIds.
Pitfalls: Embedding worker runs async; the statement is queryable by direct ID before the embedding is ready.
Reads: 28_knowledge_wire_protocol/00_purpose.md.
Writes: crates/brain-protocol/src/knowledge/statement.rs, crates/brain-server/src/handlers/knowledge/statement.rs.
Done when: all 7 opcodes work end-to-end via test client.
Reads: 29_knowledge_sdk/00_purpose.md (statement API).
Writes: crates/brain-sdk-rust/src/knowledge/statement.rs.
Done when: client.fact(), client.preference(), client.event() fluent APIs work.
Reads: 25_provenance_versioning/00_purpose.md (confidence aggregation).
Writes: crates/brain-core/src/confidence.rs.
Done when: function computing 1 - Π(1 - c_i * decay(age_i)) for a statement; called on create and when evidence changes.
Pitfalls: Decay function configurable per kind. Test with empty evidence (should return 0).
Writes: tests/knowledge_statements.rs.
Done when: create-supersede chain test, contradiction surface test, evidence aggregation test, HNSW round-trip.
- All three kinds work end-to-end.
- Supersession chains traverse correctly.
- Contradictions surface (and don't auto-resolve).
- Evidence aggregation produces correct confidence.
- Statement HNSW returns plausible neighbors for semantic queries.
- Don't activate the supersession sweeper worker yet — Phase 23 wires that in.
- No extraction yet. Statements are created via SDK or wire only.