Append and revise historical records

Start with Temporal and bitemporal data for the two time dimensions. Historical records are append-only: a correction supplies another account and a retraction withdraws applicability over an interval. Neither operation physically edits or deletes an older payload. This page uses the same Alice department example to show interval-local effects.

Correct an interval, then retract part of it

The latest eligible assertion/correction supplies the payload; an eligible winning retraction produces None. Ordering is by commit and in-commit ordinal (record position), not by the latest valid-start date. The smaller retracted interval does not withdraw Alice’s department for the whole year.

Standalone example. Choose the capability-qualified installation tab below.

Corrections and retractions append immutable versions. Backend transaction/publication mechanisms remain distinct; no current-graph snapshot is requested.

1python -m pip install "gestaltdb[lmdb]"
 1from tempfile import TemporaryDirectory
 2from gestaltdb.graphdb import GraphDB, Node
 3from gestaltdb.temporal import TemporalInterval
 4
 5with TemporaryDirectory() as root:
 6    graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json')
 7    try:
 8        first = graph.temporal.put_node_version(
 9            Node("alice", properties={"department": "Research"}),
10            valid=TemporalInterval.parse("2024-01-01T00:00:00Z", "2024-12-31T00:00:00Z"),
11        )
12        corrected = graph.temporal.correct_node_version(
13            Node("alice", properties={"department": "Safety"}),
14            supersedes_version_id=first.version_id,
15            valid=TemporalInterval.parse("2024-03-01T00:00:00Z", "2024-06-01T00:00:00Z"),
16        )
17        retracted = graph.temporal.retract_node_version(
18            "alice", supersedes_version_id=corrected.version_id,
19            valid=TemporalInterval.parse("2024-04-01T00:00:00Z", "2024-05-01T00:00:00Z"),
20            reason="source withdrew this part of its account",
21        )
22        instants = ["2024-01-15", "2024-03-15", "2024-04-15", "2024-05-15", "2024-06-01"]
23        selected = [graph.temporal.get_node_as_of("alice", valid_time=day + "T00:00:00Z")
24                    for day in instants]
25        assert [None if row is None else row.node.properties["department"]
26                for row in selected] == ["Research", "Safety", None, "Safety", "Research"]
27        older = graph.temporal.get_node_as_of(
28            "alice", valid_time="2024-04-15T00:00:00Z", through_commit=corrected.commit_id,
29        )
30        assert older.version_id == corrected.version_id
31        assert graph.temporal.get_node_version(retracted.version_id) is not None
32        assert len(list(graph.temporal.iter_node_versions("alice"))) == 3
33    finally:
34        graph.close()

Omitting valid from a correction inherits the superseded interval. Supply explicit intervals when only part of an account should change. Retractions require asserted temporal history of the same entity kind and logical ID (or an earlier assertion in the same batch). A mutable current record alone is insufficient; unknown identities fail before commit allocation. Known identities may be retracted repeatedly or over disjoint intervals.

Publish a logical batch

Use graph.temporal.commit_versions with NodeVersionWrite and EdgeVersionWrite descriptors to publish related versions under one commit ID. Eligible versions within that commit use their ordinal for deterministic order. This does not update mutable current nodes/edges.

LMDB and transactional PyRex publish through a backend transaction. LevelDB and plain PyRex publish validated records with a visibility marker written last; incomplete publications remain invisible. This shared logical commit contract is not universal backend rollback support. See Atomic Logical Batches and Storage Backends for the exact boundaries.

Keep derived indexes fresh

Ordinary temporal writes maintain indexes. Bulk workflows can defer them, but indexed as-of reads fail closed while the temporal family is stale. This separate standalone example rebuilds before reading; it does not silently repair during a query or disable freshness checks.

Standalone example. Choose the capability-qualified installation tab below.

Deferred temporal indexes are rebuilt explicitly before indexed reads, independently of entity codec and backend transaction support.

1python -m pip install "gestaltdb[lmdb]"
 1from tempfile import TemporaryDirectory
 2from gestaltdb.graphdb import GraphDB, Node
 3from gestaltdb.ingestion import IndexMaintenanceMode
 4
 5with TemporaryDirectory() as root:
 6    graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json')
 7    try:
 8        version = graph.temporal.put_node_version(
 9            Node("alice", properties={"department": "Research"}), valid=(0, None),
10            index_mode=IndexMaintenanceMode.DEFER,
11        )
12        assert "temporal" in graph.stale_indexes()
13        graph.temporal.rebuild_temporal_indexes()
14        assert "temporal" not in graph.stale_indexes()
15        assert graph.temporal.get_node_as_of("alice", valid_time=0).version_id == version.version_id
16    finally:
17        graph.close()

Integers in the second example are UTC microseconds, not days or seconds. IndexMaintenanceMode.DEFER_REBUILD rebuilds before a high-level write returns; graph.rebuild_deferred_indexes() can rebuild all stale families. A rebuild repairs derived indexes from valid canonical history, not corrupted history.

Commit IDs are never reused, so gaps alone are not proof of missing visible data. For an interrupted write, use Recovery and Retention rather than deleting markers, sidecars or records manually. Visible history has no pruning or TTL API; retention and complete backups are operational requirements.