Stored rules and support maintenance

Use graph.rules when rules should derive persisted claims from sourced temporal evidence. Begin with Sourced claims and conflicting evidence for polarity and four-valued status. A Horn rule derives a head proposition when its body premises match; head variables must be bound by positive body atoms.

Stored rules versus standalone Datalog

Choice

graph.rules

Standalone evaluators

Input

Selected temporal positive entity claims in one world

Explicit programs and caller-supplied facts

Result

Versioned derived claims with rule/premise justifications

In-memory closure; database publication is a separate adapter operation

Features

Safe Horn rules and declared scoped absence

Binary/typed APIs have their own literals, aggregates and proof contracts

Start here

This guide and Positive Horn Rules

Facts, Rules, and Explanations, Typed Datalog: literals, filters, aggregates

Do not assume that every standalone rule feature is accepted by the stored-rule service, or that evaluating a standalone program changes database records.

Keep a conclusion until its final support disappears

One displayed witness is not necessarily every independent support. Two sources can justify the same conclusion. Removing the first changes its justifications; only removing the final support retracts the conclusion. This standalone example checks both transitions and an older explanation.

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

Support maintenance uses temporal publication and exact historical claims, not a mutable current snapshot. These alternatives do not imply identical backend rollback or maintenance latency.

1python -m pip install "gestaltdb[lmdb]"
 1from tempfile import TemporaryDirectory
 2from gestaltdb.graphdb import GraphDB
 3
 4with TemporaryDirectory() as root:
 5    graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json')
 6    try:
 7        first, second = [graph.epistemic.assert_claim(
 8            subject="alice", predicate="WORKS_FOR", object="acme",
 9            polarity="positive", agent=agent, source=agent + ".csv",
10            world="reported", valid=(0, 100),
11        ) for agent in ("hr", "registry")]
12        graph.rules.create_rule(
13            "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
14            then=("?p", "AFFILIATED_WITH", "?c"),
15        )
16        limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
17        derived = graph.rules.run(as_of=50, world="reported", **limits).versions[0]
18        graph.epistemic.retract_claim(first.logical_id, supersedes_version_id=first.version_id)
19        changed = graph.rules.maintain(as_of=50, world="reported", **limits)
20        assert changed.corrected_count == 1 and changed.retracted_count == 0
21        assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is not None
22        graph.epistemic.retract_claim(second.logical_id, supersedes_version_id=second.version_id)
23        removed = graph.rules.maintain(as_of=50, world="reported", **limits)
24        assert removed.retracted_count == 1
25        assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
26        historical = graph.rules.explain(
27            derived.logical_id, valid_time=50, system_time=derived.system_time,
28            max_depth=8, max_nodes=100,
29        )
30        assert {first.version_id, second.version_id} <= {
31            node.node_id for node in historical.nodes
32        }
33    finally:
34        graph.close()

Rules intersect premise validity within a justification and preserve independent supports. Derived claims use the reserved gestaltdb:rules agent; they are not authoritative base seeds that can keep an unsupported cycle alive. Reusing a rule name appends a rule version. Call maintenance after changing premises or rules; an unchanged repeat is idempotent. Use explicit valid/system horizons when comparing historical explanations.

Absence is not an explicit denial

not_when=[...] checks that no matching positive premise is present under a declared closed-world scope (closed_world predicates). It does not consume an explicit negative claim, infer one, or make every missing predicate false. Negated variables must be safely bound; undeclared negation and negative dependency cycles reject before the catalog changes.

Stored-rule absence is conservative over a candidate conclusion interval: any overlap with a disqualifying positive claim blocks the derivation. It does not split out a surviving subinterval automatically. See the complete scoped-absence example in Closed-world negation and stratification for exact behavior; do not transfer standalone range-negation contracts to this service.

Bounds, persistence and explanations

Set max_iterations, max_derivations and max_justifications for the workload. RuleEvaluationLimitError publishes no partial staged conclusions. Successful conclusions publish in one temporal commit; backend transaction and marker-last guarantees remain distinct (Append and revise historical records). Maintenance recomputes a bounded closure and persists changes; it is not a promise of deletion-local latency or constant memory.

explain returns exact historical claim/rule versions and premise/absence edges. max_depth/max_nodes bound explanation traversal; inspect truncated before presenting it as complete. A historical evidence graph is not independent proof verification. Unified inference audit adds explicitly tagged model outputs and bounded export without certifying model predictions or lineage.