Consensus graph¶
ConsensusGraph(kg) keeps versioned consensus over a KnowledgeGraph. Claims are the immutable evidence log;
each commit evaluates affected questions from all their retained evidence and appends answer versions. Reads
can be pinned to a published commit. KGCURRENT remains the separate latest-reported projection.
from SharedData.ConsensusGraph import ConsensusGraph
cg = ConsensusGraph(kg) # kg = shdata.knowledge('EARNINGS', ...)
cg.genesis() # every question evaluated from all its evidence
cg.commit(claims=new_claim_ids, batch='feed-2026-11-01T10')
cg.state(question=q) # answer at head
cg.state(subject=company, commit=3) # branch-local sequence or a global commit id
cg.history(q), cg.diff(1), cg.log()
cg.context_pack(subject=company) # answers, confidence, alternatives, citations
cg.reevaluate({'version': 'p2', 'rel_tol': 0.001}, 'strict')
cg.fast_forward('strict')
Questions and evidence¶
A question is a state key (subject, predicate, scope). Its evidence includes claims linked by an ABOUT
edge, claim -> question, and claims with that state key. An append-only in-memory catalog of fixed claim
rows supplies the latter, including claims whose ABOUT write was interrupted. Catalog updates read only
new rows; individual evidence retrievals use locations and indexed ABOUT lookups, with no per-question
claim-table scan. Scope must distinguish period, basis and actuals versus guidance.
Producers must publish canonical amounts and ranges, units and currency, using content-sensitive claim ids.
Consensus does not convert scales or currencies. Published claims must remain immutable; corrections and
withdrawals are new claims. KnowledgeGraph's general upsert API still allows payload/value updates, so this
producer contract matters, including for pinned retrieval citations. Alias/ABOUT changes that do not append
claims require commit(questions=affected_questions) or a full commit().
Payload fields include status='withdrawn', amendment=True, family (one independent observation, e.g. an
accession), source_class, low, high, point, unit, currency, doc, and quote.
Consolidation (evaluate_question)¶
- Evaluation is pure and ordered deterministically by known time and claim id; missing known times sort first. Nonfinite scalar values supply no numeric evidence. Duplicate identical claim ids count once; contradictory content for one id raises.
- Default equality tolerance is 0.5%, with optional
abs_tol. Every pair within a cluster meets tolerance; near-neighbor chains cannot join distant answers. Endpoints of ranges must agree individually; ranges and points, or different units/currencies, remain distinct. Bounds remain in clusters and retrieval packs; the scalarvalueof a range is its midpoint, or its sole known endpoint. - Source priority, then significant digits, known time and claim id select a representative. One cluster is
preferred; several arecontested. Recency alone never decides, but source priority does: among clusters backed by the origin's own primary claim, the highest source class (a filing over a release over a deck) wins outright aspreferred, and the others stay visible as recorded alternatives. - The other statuses are
attested(the evidence is non-numeric: support is counted by object and polarity, and no answer is chosen),distribution(every claim is an estimate),withdrawn(only withdrawals remain) andinsufficient(no evidence at all). - Confidence is
1 - product(1 - p_family), where each family's prior is the maximum prior among its reports. Dependent copies count once. Contested confidence is zero, and its independent-source count is the union of families across alternatives. Tolerances and priors must be finite and within their domains. - A later valid/report time alone never supersedes. An explicit amendment supersedes strictly earlier known evidence. Equal-time conflicting amendments stay contested. A withdrawal resets the question; only strictly later active evidence resumes it, without reviving pre-withdrawal assertions. A withdrawal takes precedence over an amendment at the same known time. Superseded ids remain in the answer record.
- An optional
judge(question, clusters, claims)handles contested questions only. The cache key includes the complete ordered input, clusters, effective policy, model and prompt version. Decisions are cached individually before subsequent model calls;None, invalid selections and explicit abstentions are cached as unresolved. The first cache publication wins. Valid choices use a bounded confidence capped by source confidence. Replay after a completed cache write never calls the model for that input.
Publication and reads¶
Tables live under <user>/Hashs/D1/<name>/: KGCOMMITS (branch/sequence publications), KGCONSENSUS
(immutable answer versions with prev), KGCHEADS (question heads and empty-batch receipts), KGJUDGMENTS.
Commit ids hash the parent, complete effective policy, cumulative sorted evidence manifest, changed answers, and optional fast-forward provenance. Evidence hashes cover claim content and exclude physical BSON offsets. Wall clock, author, message and batch label do not enter identity. Incremental and full evaluation at the same evidence produce the same answers and manifest; commit ids also depend on their parents.
Write order is judgments, answer rows, heads, commit row last. Answer ids include the candidate commit id. Readers accept only rows matching a published branch/sequence and commit id, and walk past orphan versions. A crash before publication leaves the previous consensus visible; replay completes the same candidate when inputs are unchanged. A crash after publication leaves the complete new commit visible. These are process failure guarantees at/between table writes; no filesystem flush or power-loss transaction is added.
The final collision check, head writes and publication share a hold of the existing commit-table process mutex. A conflicting writer raises before replacing winning heads. This guard does not replace the graph's single-writer topology for ingestion and model work.
Empty commits are suppressed. Published batch labels return their original commit id, including long labels. A no-op batch gets a receipt without publishing a commit; its replay remains a no-op even after later evidence. Commit-log caches refresh by append count and decode only newly published rows. State reads batch head/answer probes. Diff and fast-forward use published question deltas, avoiding full answer-table scans. Manifest hashing still visits the sorted question manifest once per nonempty commit.
Branches, policy and compatibility¶
fork(name, commit=...) records a sequence-zero fork marker and pins its ancestor's answers and policy.
Sequence numbers are local to the selected branch; commit ids resolve globally. State/diff reject unknown pins
and branches.
Nested fork history follows the original fork points. diff(a, b) compares endpoint answer digests in either
direction, including across branches. history(q) returns published versions, newest first, across ancestors.
Changing any effective policy setting forces full evaluation. Subsequent commits and reopened wrappers inherit
the published policy. reevaluate(policy, branch) forks and evaluates there. fast_forward(src) requires the
destination still at the fork parent, copies only published changes, adopts the source policy, and records
source_commit; replay of that fast-forward returns its existing id. Merge commits remain deferred.
Format-2 publications add cumulative manifest deltas, question deltas and policy-content hashes. Existing
published ids/pins remain readable. The first evaluating commit after an older publication re-evaluates all
questions and writes format-2 metadata. Before fast-forwarding an older source branch, run
commit(branch=source) to upgrade it; otherwise fast-forward raises an actionable error. New ids and judgment
keys intentionally differ from the original implementation.
Historical measurement (before this review)¶
2026Q3 earnings, 10,430 questions, one host: genesis 3.8 s, all answers read in 2.0 s, unchanged re-commit 4.3 s;
retrieval pack median 7.6 ms. Those production measurements were not repeated during this review. Regression
coverage uses isolated /dev/shm data, including a 10,001-question lookup/scan check.