Sample historical graph structure

Use a temporal snapshot when a draw must respect when nodes and relationships were available. A valid-time filter selects modeled time; a system-time horizon selects which recorded history the build knows. These are separate dimensions (bitemporal; see Temporal and bitemporal data for a two-horizon timeline). Recording temporal versions does not run temporal reasoning or train a model. Start with Sampling for graph learning for snapshot basics.

Draw at a boundary and across a window

This complete database example uses integer UTC microseconds for a tiny timeline. a -> b holds on [0, 10) and a -> c on [10, 20). The endpoint 10 belongs only to the second interval. Nodes are available on [0, 30).

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

Temporal history is built from an authenticated immutable-history read view, not a mutable current snapshot. Publication and transaction capabilities remain backend-qualified.

1python -m pip install "gestaltdb[lmdb]"
 1from tempfile import TemporaryDirectory
 2from gestaltdb.graphdb import Edge, GraphDB, Node
 3from gestaltdb.sampling import SamplerEngine
 4from gestaltdb.temporal import TemporalContext
 5from gestaltdb.versioning import EdgeVersionWrite, NodeVersionWrite
 6
 7with TemporaryDirectory() as root:
 8    graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json')
 9    try:
10        graph.temporal.commit_versions([
11            *(NodeVersionWrite.assertion(Node(name), (0, 30)) for name in ("a", "b", "c")),
12            EdgeVersionWrite.assertion(Edge("ab", "a", "b", properties={"type": "R"}), (0, 10)),
13            EdgeVersionWrite.assertion(Edge("ac", "a", "c", properties={"type": "R"}), (10, 20)),
14        ])
15        snapshot = graph.build_sampler_snapshot(
16            f"{root}/history", temporal=True, time_bucket="none",
17        )
18    finally:
19        graph.close()
20
21    engine = SamplerEngine.load(snapshot.path, mode="memmap", seed=7)
22    point = engine.sample_neighbors_external(
23        ["a"], 10, relations=["R"], temporal=TemporalContext.as_of(10),
24    )
25    assert list(point.to_external(engine.snapshot)["neighbor_nodes"]) == ["c"]
26    assert len(point.edge_version_ids) == len(point.edge_indices) == 1
27    window = TemporalContext.during(5, 15)
28    overlap = engine.sample_neighbors_external(["a"], 10, temporal=window)
29    contained = engine.sample_neighbors_external(
30        ["a"], 10, temporal=window, window_policy="contained",
31    )
32    assert set(overlap.to_external(engine.snapshot)["neighbor_nodes"]) == {"b", "c"}
33    assert contained.edge_indices.size == 0

overlap (the default) requires a nonempty intersection. contained requires the entire edge interval inside the query window, so neither edge above qualifies. Temporal, relation and direction filters run before fanout selection. Filtering after a draw is not equivalent and can reduce the effective fanout.

Avoid time leakage deliberately

  • The build pins one authenticated recorded-history horizon. Supply system_time=... to build from a chosen historical horizon rather than the current visible prefix. Later database writes do not change the artifact.

  • sample_nodes(..., temporal=...) filters node availability; sample_edges(..., temporal=...) filters edge-version rows. A repeated external edge ID can refer to multiple temporal rows; use compact rows when ambiguous.

  • sample_multihop and sample_subgraph accept valid-start ordering through causal_policy="nondecreasing" or "nonincreasing". That is not the interval/event clock policy for walks; use Random-walk embedding pipelines for those clocks.

  • Temporal neighbor/subgraph outputs retain aligned version IDs and validity arrays. Supplying temporal filters to a static/legacy snapshot fails explicitly.

  • Time-aware negative rejection and future-candidate eligibility are separate choices. Read Build negative training examples before using historical positives for training; a point-filtered positive does not by itself define every negative policy.

The artifact format, integrity checks and compatibility boundaries remain in Temporal Sampler Snapshots and Snapshot consistency: staleness, appends and compaction. These guarantees do not imply constant memory or lower latency than a static draw.