Temporal history and service reference
Start with Temporal and bitemporal data for a complete two-horizon example, Append and revise historical records for interval corrections/retractions and index freshness, or Read one historical account consistently for pinned reads and historical Cypher. This reference retains detailed temporal publication, integrity and shared claim/rule contracts. Recovery and migration procedures live in Compatibility, Migration, and Recovery.
Unless a block creates its own graph, the code below is a reference fragment
using an open graph and the named values from its surrounding explanation.
It is not an independently runnable application. Claims and rules share temporal
commits but remain separate services, not historical graph edges.
For historical-analysis and evidence-audit workflows, the Components, Interfaces, and Applications guide distinguishes this storage layer from temporal inference, current read views, and reusable sampling snapshots.
GestaltDB can append immutable node and edge versions alongside its existing mutable graph. Temporal versions use two distinct time dimensions:
valid time is the half-open interval
[start, end)in which a fact is applicable in the modeled domain;system time is the monotonically increasing UTC instant at which GestaltDB committed that version.
Together these dimensions are bitemporal: one question asks what applied at a time, another asks what had been recorded about it by a given horizon. A correction records a replacement account; a retraction withdraws the selected claim/version’s applicability under the temporal rules. Old records are retained. See Concepts and Terminology for the shared vocabulary and Reason over complete validity ranges for computing intervals of inferred conclusions rather than merely storing history.
The explicit version APIs do not update records returned by get_node or
get_edge and do not change unqualified current-graph Cypher or ordinary
sampling results. Qualified historical queries use a separate view. Temporal history has
separate indexes for exact versions, logical entities, valid starts, system
times, and typed outgoing/incoming traversal.
Decoded-commit caching is scoped to the exact backend store object and bounded to 256 entries (oldest-half eviction). Returned node/edge payloads are detached: mutating a fetched entity does not change history or a later read. Verified pinned backend read snapshots may reuse validated records directly. Live or unverifiable stores recheck the visibility marker, descriptor and record bytes before decode reuse, so missing markers and changed records are not masked by a warm cache. These live checks still cost a commit-sized record scan; the cache avoids repeated decoding, not all backend I/O. Separate snapshot/store objects never share cache admission even when their GraphDB wrappers share the cache dictionary.
Claim enumeration groups temporal locators by commit, amortizing these full checks over each group rather than each selected row. It resolves corrections and retractions against complete logical histories at one captured horizon, buffers the selected immutable winners, and revalidates all touched commits before successful iterator exhaustion. Marker removal, historical rewrites and record corruption during iteration fail the completed read; appends beyond its horizon do not change its answers. Consumers must exhaust the iterator and discard partial output on error. Closing an iterator early is not successful authenticated completion.
This is an operation-local grouped-read protocol, not a backend snapshot or a change to cache trust. Full descriptor/marker/envelope validation remains in place on live stores, including unrelated records in touched commits. Validation I/O is proportional to selected locators plus the sizes of touched commits, with a constant number of full checks per touched commit. Selected locators/winners are buffered in Python; no hard RSS bound or per-row I/O guarantee is implied. LMDB/LevelDB/plain and transactional PyRex retain their existing distinct snapshot capabilities. Individual version/commit reads keep their existing validation.
Assertions, Corrections, and Retractions
Illustrative fragment (not standalone).
1from gestaltdb.graphdb import Edge, Node
2from gestaltdb.temporal import TemporalInterval
3
4alice = graph.temporal.put_node_version(
5 Node(node_id="alice", labels=["Person"], properties={"name": "Alice"}),
6 valid=TemporalInterval.parse("2020-01-01T00:00:00Z"),
7 metadata={"source": "people-import"},
8)
9
10corrected = graph.temporal.correct_node_version(
11 Node(node_id="alice", labels=["Person"], properties={"name": "Alicia"}),
12 supersedes_version_id=alice.version_id,
13)
14
15graph.temporal.retract_node_version(
16 "alice",
17 valid_from="2030-01-01T00:00:00Z",
18 supersedes_version_id=corrected.version_id,
19 reason="source withdrew the assertion",
20)
Corrections and retractions append records. They never modify or physically
delete the superseded payload. Omitting valid from a correction inherits the
superseded version’s interval.
Atomic Logical Batches
Use write descriptors from gestaltdb.versioning to publish several
versions under one commit ID:
Illustrative fragment (not standalone).
1from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
2
3commit = graph.temporal.commit_versions([
4 NodeVersionWrite.assertion(Node(node_id="acme"), (0, None)),
5 EdgeVersionWrite.assertion(
6 Edge(
7 edge_id="employment-1",
8 source="alice",
9 target="acme",
10 properties={"type": "WORKS_FOR"},
11 ),
12 (0, None),
13 ),
14], metadata={"source": "hr-import"})
Retractions require an existing assertion/correction for the same entity kind
and logical ID in published temporal history, or an earlier assertion in the
same batch. Unknown identities raise TemporalVersionError before allocating
a commit ID or writing any part of the batch. Current-state records alone,
unpublished assertions, and retraction-only history do not establish temporal
identity. This validation also works with deferred indexes. Known identities
may be retracted repeatedly or over disjoint valid intervals; validity overlap
is not required. Retractions remain observable through the version-history APIs,
even though as-of entity reads return None where a retraction wins.
Transactional LMDB and transactional PyRex publish the complete batch in one backend transaction. All filesystem-backed stores reserve commit IDs through a durable sidecar sequence while holding a database-wide writer lock. LevelDB and default PyRex then write the descriptor and records and publish a visibility marker last. Records without a valid marker remain invisible. Reservations are never reused, including when an outer backend transaction rolls back, so visible commit IDs may contain gaps.
list_temporal_orphans() reports empty reservation gaps and validated
incomplete publications. reclaim_temporal_orphans(through_commit=...)
removes only unmarked artifacts through an explicit inclusive horizon, rebuilds
derived indexes, and never reuses reclaimed commit IDs. Use the recovery
procedure in Compatibility, Migration, and Recovery; malformed unpublished data fails closed.
As-Of Resolution and Traversal
get_node_version and get_edge_version retrieve visible versions by UUID.
iter_node_versions and iter_edge_versions return append order and accept
an optional system-time or commit horizon. iter_temporal_commits accepts a
commit horizon.
get_node_as_of and get_edge_as_of select a logical entity at one valid
instant and optional inclusive system horizon. Eligible versions are ordered by
commit and in-commit ordinal. The newest assertion or correction supplies the
payload; a newest retraction returns None.
Illustrative fragment (not standalone).
1historical = graph.temporal.get_node_as_of(
2 "alice",
3 valid_time="2025-01-01T00:00:00Z",
4 system_time=corrected.system_time,
5)
6
7edges = list(graph.temporal.iter_edges_as_of(
8 source="alice",
9 edge_type="WORKS_FOR",
10 valid_time="2025-01-01T00:00:00Z",
11))
Temporal traversal resolves each logical edge before checking its winning source, target, and type, so interval-local topology corrections and retractions do not leak historical adjacency.
Consistent Read Views
graph.temporal.open_read_view captures the contiguous prefix of fully visible commits
and a default valid-time instant. It stops before the first incomplete commit,
so a later marker cannot change the view. Every history and as-of call through
the view uses that horizon, even if newer commits are published through the
graph handle.
Illustrative fragment (not standalone).
1with graph.temporal.open_read_view(graph, manifest=graph.manifest, database_id=graph.database_id, valid_time="2025-01-01T00:00:00Z") as view:
2 alice = view.get_node_as_of("alice")
3 snapshot = view.build_sampler_snapshot("snapshots/2025-01-01")
4 token = view.provenance.token
Pass system_time=... to capture the visible prefix at a historical system
instant, or through_commit=... to select a commit directly; these options
are mutually exclusive.
The immutable ReadViewProvenance records the stable database UUID, visible
commit marker and full visibility-prefix digest, valid instant, backend layout,
serializer format, and snapshot mechanism. Its token is SHA-256 over canonical
JSON. Snapshot builds materialize nodes and edges from immutable temporal
history at that exact point,
publish through a staging directory, and store the authenticated provenance.
SamplerSnapshot.verify_source and provenance-aware node/edge hydration fail
if the source identity, serializer, backend, commit marker, or token differs.
Legacy snapshots without source provenance retain their existing unverified
behavior.
through_commit may recreate an older visible view. Database paths are not
part of provenance, so moving a managed database does not change its identity.
Choose graph history or sourced claims
Historical node/edge reads and qualified Cypher select graph structure
(Read one historical account consistently). Temporal sampler snapshots contain graph history, not
claims (Sample historical graph structure). Claims retain source, polarity and world
identity on graph.epistemic; graph.rules derives and explains selected
claim conclusions. Their shared commit history does not implicitly convert
claims to edges or make unqualified Cypher reason over them. See the claim/rule
reference below, Bounded Modal and Epistemic Evaluation and Unified inference audit for those tasks.
Index Maintenance
Temporal writes maintain indexes by default. Pass
index_mode=IndexMaintenanceMode.DEFER for bulk append workflows; indexed
reads then fail closed until rebuild_temporal_indexes or
rebuild_deferred_indexes succeeds. DEFER_REBUILD rebuilds before the
write returns. Rebuilds are additive and idempotent because canonical history is
append-only. Temporal node scans and untyped endpoint traversal use derived
catalog indexes in addition to logical, system, and typed-adjacency indexes. A
database predating any current temporal index format is automatically reported
with the temporal stale family and can be migrated with
rebuild_deferred_indexes.
Point-in-time candidates are intersected through valid-start and valid-end indexes before entity payloads are decoded. This preserves half-open interval semantics while avoiding hydration of expired historical versions.
Index rebuilds use copy-on-build generations. The active generation records its visible-marker checksum and commit horizon; activation is one metadata update, and prior-generation entries are reclaimed only after activation succeeds.
Migrating TimeIndexedEdge
The deprecated TimeIndexedEdge class encoded a datetime in a mutable edge
key; it is not an immutable temporal version. Use
migrate_time_indexed_edges once, with concurrent writers stopped. The method
maps successive timestamps for each logical edge ID to half-open intervals,
publishes all new versions in one temporal commit, and can optionally delete the
legacy records after publication. Validate first with delete_legacy=False;
cleanup is independently retryable.
Migration fails closed for undecodable payloads, payload/key mismatches, duplicate timestamps, or changed legacy input after a previous migration. It does not rewrite existing temporal history or snapshots. See Compatibility, Migration, and Recovery for the backup, retry, serializer, snapshot, and recovery contract.
Epistemic Claims and Provenance
For an independent claims/status/derivation example, use Sourced claims and conflicting evidence; for support maintenance, use Stored rules and support maintenance.
Epistemic claims are immutable, sourced subject-predicate-object assertions or
denials. They use the same valid/system-time commits and read views as node and
edge versions, but remain separate from graph edges and current-state Cypher.
Entity objects are stable graph IDs; pass object_kind="literal" for a
JSON-compatible literal value.
Illustrative fragment (not standalone).
1from gestaltdb import ClaimStatus
2
3reported = graph.epistemic.assert_claim(
4 subject="alice", predicate="WORKS_FOR", object="acme",
5 polarity="positive", agent="source:hr-feed", source="hr-2024.csv",
6 confidence=0.97, world="reported", provenance={"row": 42},
7 valid_from="2024-01-01T00:00:00Z",
8)
9graph.epistemic.assert_claim(
10 subject="alice", predicate="WORKS_FOR", object="acme",
11 polarity="negative", agent="source:investigator", source="interview-7",
12 confidence=0.6, world="reported",
13 valid_from="2024-01-01T00:00:00Z",
14)
15assert graph.epistemic.claim_status(
16 "alice", "WORKS_FOR", "acme",
17 valid_time="2024-06-01T00:00:00Z", world="reported",
18) is ClaimStatus.BOTH
Claim.statement_id is a deterministic SHA-256 identity for the proposition
only. Claim.claim_id additionally includes polarity, agent, source, and
world. Confidence and provenance are not identity fields, so
correct_claim can revise them while preserving the sourced claim identity.
It accepts either a Claim object or its logical ID. Explicit confidence
and provenance keywords override values on the supplied object (or the
superseded version for an ID); omitted keywords preserve those values.
confidence=None clears confidence and provenance={} clears provenance.
Confidence is optional or a finite number from 0 through 1; it never determines
polarity. Claim payloads and provenance are canonical JSON and therefore do not
depend on the graph’s configured entity serializer.
iter_claims_as_of filters by statement, subject, predicate, object kind,
agent, source, world, and polarity. get_claim_as_of resolves one claim ID.
Both accept system_time or through_commit and use half-open valid-time
intervals. Corrections and retractions append history:
Illustrative fragment (not standalone).
1reviewed = graph.epistemic.correct_claim(
2 reported.logical_id,
3 supersedes_version_id=reported.version_id,
4 confidence=0.99,
5 provenance={"row": 42, "reviewed": True},
6)
7graph.epistemic.retract_claim(
8 reported.logical_id,
9 supersedes_version_id=reviewed.version_id,
10 valid_from="2025-01-01T00:00:00Z",
11 reason="source withdrew the assertion",
12)
claim_status uses open-world four-valued semantics: SUPPORTED when at
least one matching positive claim is visible, REFUTED for negative only,
BOTH when both polarities coexist, and UNKNOWN when neither is visible.
A GraphReadView exposes the same claim lookup, iteration, and status methods
at its pinned system horizon and default valid time.
Positive Horn Rules
create_rule validates and appends immutable system-time versions of named
positive Horn rules. Predicates are constants, and every variable in the head
must occur in the body. Invalid or unsafe definitions are rejected before the
catalog changes. Reusing a rule name creates a new version; get_rule and
iter_rule_versions accept a system-time horizon.
Illustrative fragment (not standalone).
1rule = graph.rules.create_rule(
2 "employment-implies-affiliation",
3 when=[("?p", "WORKS_FOR", "?c"), ("?c", "MEMBER_OF", "?g")],
4 then=("?p", "AFFILIATED_WITH", "?g"),
5)
6result = graph.rules.run(
7 as_of="2024-06-01T00:00:00Z",
8 max_iterations=100,
9 max_derivations=10_000,
10 max_justifications=100_000,
11)
graph.rules.run evaluates the latest version of each rule with semi-naive deltas.
Only positive entity-object claims participate. All premises in a match must
share a world, and each justification contributes the intersection of its
premises’ half-open valid-time intervals. Overlapping supports for an equivalent
conclusion are consolidated into one validity interval. Derived conclusions use the
reserved gestaltdb:rules agent identity and retain canonical justification
records containing the rule version ID and ordered premise version IDs.
Recursive finite rule sets stop at a fixpoint, and repeating an unchanged run
is idempotent.
The three positive resource limits are mandatory safeguards. Exceeding one
raises RuleEvaluationLimitError before any staged conclusion is persisted.
Successful conclusions are published together in one temporal commit and
remain separate from mutable graph edges and unqualified Cypher. Rule
evaluation does not consume negative claims, literal-object claims, or claims
from different worlds in one match.
Closed-world negation and stratification
create_rule(..., not_when=[...], closed_world=[...]) adds negated body
atoms. A negated atom is an absence check, not a negative claim or a stored
denial. Every negated predicate must appear in the active program’s
closed-world declarations; the effective scope is the union of declarations on
the latest version of each rule. Undeclared predicates, unbound negated
variables and negative dependency cycles are rejected before the catalog
changes.
graph.rules.run and graph.rules.maintain order positive predicate components so
every negative edge points strictly downward. A negated atom anti-joins only
against completed lower strata; a negative edge inside one component is
unstratifiable and never falls back to unstratified evaluation. Components
without rules keep zero-round positions. Programs containing negation exclude
prior rule-engine conclusions from their authoritative input, so a stale
derived claim cannot block an absence check after its base support disappears.
For a candidate conclusion interval, a negated atom is satisfied only when no matching positive claim overlaps any part of that interval. Partial overlap blocks the derivation instead of producing an interval fragment that the claim model cannot represent. Rules whose interval spans periods with and without the negated fact must therefore be evaluated over narrower intervals or model the distinction with explicit claims. This is conservative absence evidence, not a closed-world default for undocumented predicates.
Standalone example. Choose the capability-qualified installation tab below.
The claim-history workflow preserves backend-qualified publication and temporal-view behavior; it does not require a mutable snapshot.
1python -m pip install "gestaltdb[lmdb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='lmdb', serializer='json')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[lmdb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='lmdb', serializer='pickle')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[lmdb,msgpack]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='lmdb', serializer='messagepack')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[lmdb,protobuf]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='lmdb', serializer='protobuf')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[leveldb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='leveldb', serializer='json')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[leveldb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='leveldb', serializer='pickle')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[leveldb,msgpack]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='leveldb', serializer='messagepack')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[leveldb,protobuf]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='leveldb', serializer='protobuf')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[rocksdb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='pyrex', serializer='json')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[rocksdb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='pyrex', serializer='pickle')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[msgpack,rocksdb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='pyrex', serializer='messagepack')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
1python -m pip install "gestaltdb[protobuf,rocksdb]"
1from pathlib import Path
2from tempfile import TemporaryDirectory
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as directory:
6 graph = GraphDB.create(Path(directory) / "db", backend='pyrex', serializer='protobuf')
7 try:
8 graph.epistemic.assert_claim(
9 subject="supplier-1", predicate="SHIPS", object="widgets",
10 polarity="positive", agent="erp", valid=(0, 100),
11 )
12 graph.rules.create_rule(
13 "review-uncertified",
14 when=[("?s", "SHIPS", "?goods")],
15 then=("?s", "REQUIRES_SAFETY_REVIEW", "yes"),
16 not_when=[("?s", "CERTIFIED", "iso9001")],
17 closed_world=["CERTIFIED"],
18 )
19 graph.rules.run(as_of=10)
20 flagged = next(graph.epistemic.iter_claims_as_of(
21 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW"))
22 assert flagged.claim.subject == "supplier-1"
23
24 graph.epistemic.assert_claim(
25 subject="supplier-1", predicate="CERTIFIED", object="iso9001",
26 polarity="positive", agent="audit", valid=(0, 100),
27 )
28 assert graph.rules.maintain(as_of=10).retracted_count == 1
29 assert list(graph.epistemic.iter_claims_as_of(
30 valid_time=10, predicate="REQUIRES_SAFETY_REVIEW")) == []
31 finally:
32 graph.close()
Incremental Truth Maintenance and Explanations
graph.rules.maintain reconciles rule-derived claims after claims or rule versions
change. It recomputes a bounded fixpoint from non-derived positive entity
claims, indexes premise/rule dependents and independent supports, and appends
only changed derivations. Removing one support corrects the conclusion’s
justifications; the conclusion is retracted only after its final support
disappears. Derived claims are never authoritative seeds, so unsupported rule
cycles terminate instead of sustaining themselves.
Illustrative fragment (not standalone).
1graph.epistemic.retract_claim(
2 reported.logical_id,
3 supersedes_version_id=reviewed.version_id,
4 reason="source correction",
5)
6maintained = graph.rules.maintain(
7 as_of="2024-06-01T00:00:00Z",
8 max_iterations=100,
9 max_derivations=10_000,
10 max_justifications=100_000,
11)
The first pass requires as_of. Later calls may omit it to resume the valid
time recorded by the latest completed rule run or maintenance pass. Conclusions
are published in one temporal commit before the rebuildable dependency index;
retrying after interruption is therefore idempotent. A bound failure publishes
no maintenance commit.
graph.rules.explain resolves the claim at both valid and system time and returns a
ClaimExplanation graph. Claim nodes contain exact immutable
ClaimVersion values, rule nodes contain exact RuleVersion values,
absence nodes contain RuleAbsence evidence, and
derived_by/premise/absent_premise edges retain positive and
negated body positions. Absence nodes are closed-world checks at the
evaluation horizon, not claim versions or negative facts. Historical horizons
keep earlier explanations reproducible after later corrections or retractions.
Traversal tracks visited version IDs and accepts max_depth and max_nodes
bounds; truncated reports a reached bound. The unified audit export in
gestaltdb.inference preserves absence nodes and their justification groups.
Illustrative fragment (not standalone).
1explanation = graph.rules.explain(
2 derived.logical_id,
3 valid_time="2024-06-01T00:00:00Z",
4 system_time=derived.system_time,
5)
6assert explanation.root_version_id == derived.version_id
Current Limits
Read views cover immutable temporal history on every backend. Bitemporal Cypher
MATCH reads use these views. Unqualified Cypher automatically uses a unified
mutable-state read snapshot on capable backends, while explicit snapshot requests
fail closed elsewhere. Mutable and temporal provenance remain distinct. Temporal
properties persist through Cypher and configured exact/range indexes. Temporal
sampler snapshots support point/window traversal, causal paths, node
availability, and time-aware hard-negative rejection. Claim, rule, and
explanation Cypher syntax is not implemented. Marker-backed data that fails hash or
envelope validation raises
TemporalCorruptionError rather than returning partial history.
Version dataclasses contain immutable metadata and detached entity payloads.
Node and Edge payload objects remain mutable for compatibility; mutating
a returned payload never changes persisted history, and a later read returns a
fresh decoded payload whose hash still matches storage. Temporal history must be
reopened with the same configured serializer used to write it.
There is no temporal-history pruning or TTL API; canonical commits are retained
indefinitely. Derived temporal indexes and sampler snapshots are rebuildable,
but corrupted canonical history requires restoring a complete backup.