Sourced claims and conflicting evidence
Use graph.epistemic to record who asserted or denied a proposition, where it
came from, and when it applies. A claim is not a mutable graph edge or an
independently verified fact. Read Temporal and bitemporal data for valid versus
recorded time; claims use the same immutable temporal history.
Evidence is not a single Boolean
Polarity distinguishes positive evidence supporting a proposition from explicit negative evidence refuting it. Both can coexist without making unrelated propositions follow (paraconsistent). Missing evidence is unknown, not false.
Positive evidence |
Negative evidence |
|
|---|---|---|
Present |
Absent |
|
Absent |
Present |
|
Present |
Present |
|
Absent |
Absent |
|
Confidence is optional finite metadata in [0, 1], not a logical probability
or a vote deciding polarity. A high-confidence positive does not erase a
lower-confidence denial. An absence check is different again: it tests for
missing positive evidence under an explicit closed-world scope, rather than
asserting a negative claim.
Assert, derive, explain and withdraw support
This complete example records conflicting reports of Alice’s employment. A stored rule derives affiliation from the positive report; the explicit denial does not silently override that report or create an unrelated conclusion. After withdrawing the positive source, maintenance retracts the unsupported derived affiliation. The historical explanation remains readable at its recorded horizon.
Standalone example. Choose the capability-qualified installation tab below.
Sourced claim history and stored-rule publication use temporal services. Entity codec choice is independent of canonical claim encoding; backend transaction and recovery guarantees remain qualified.
1python -m pip install "gestaltdb[lmdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='json')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[lmdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='pickle')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[lmdb,msgpack]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='messagepack')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[lmdb,protobuf]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='lmdb', serializer='protobuf')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[leveldb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='json')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[leveldb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='pickle')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[leveldb,msgpack]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='messagepack')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[leveldb,protobuf]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='leveldb', serializer='protobuf')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='json')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='pickle')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[msgpack,rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='messagepack')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
1python -m pip install "gestaltdb[protobuf,rocksdb]"
1from tempfile import TemporaryDirectory
2from gestaltdb import ClaimStatus
3from gestaltdb.graphdb import GraphDB
4
5with TemporaryDirectory() as root:
6 graph = GraphDB.create(f"{root}/graph", backend='pyrex', serializer='protobuf')
7 try:
8 positive = graph.epistemic.assert_claim(
9 subject="alice", predicate="WORKS_FOR", object="acme",
10 polarity="positive", agent="hr", source="hr.csv", confidence=0.97,
11 world="reported", valid=(0, 100),
12 )
13 negative = graph.epistemic.assert_claim(
14 subject="alice", predicate="WORKS_FOR", object="acme",
15 polarity="negative", agent="auditor", source="interview", confidence=0.6,
16 world="reported", valid=(0, 100),
17 )
18 assert graph.epistemic.claim_status(
19 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
20 ) is ClaimStatus.BOTH
21 assert graph.epistemic.claim_status(
22 "alice", "LOCATED_IN", "paris", valid_time=50, world="reported",
23 ) is ClaimStatus.UNKNOWN
24 graph.rules.create_rule(
25 "employment-affiliation", when=[("?p", "WORKS_FOR", "?c")],
26 then=("?p", "AFFILIATED_WITH", "?c"),
27 )
28 limits = dict(max_iterations=20, max_derivations=100, max_justifications=1000)
29 run = graph.rules.run(as_of=50, world="reported", **limits)
30 assert run.derived_count == 1
31 derived = run.versions[0]
32 explanation = graph.rules.explain(
33 derived.logical_id, valid_time=50, max_depth=8, max_nodes=100,
34 )
35 assert not explanation.truncated
36 evidence_ids = {node.node_id for node in explanation.nodes}
37 assert positive.version_id in evidence_ids and negative.version_id not in evidence_ids
38 graph.epistemic.retract_claim(
39 positive.logical_id, supersedes_version_id=positive.version_id,
40 )
41 maintained = graph.rules.maintain(as_of=50, world="reported", **limits)
42 assert maintained.retracted_count == 1
43 assert graph.epistemic.get_claim_as_of(derived.logical_id, valid_time=50) is None
44 assert graph.epistemic.claim_status(
45 "alice", "WORKS_FOR", "acme", valid_time=50, world="reported",
46 ) is ClaimStatus.REFUTED
47 historical = graph.rules.explain(
48 derived.logical_id, valid_time=50, system_time=derived.system_time,
49 )
50 assert historical.root_version_id == derived.version_id
51 assert graph.get_node("alice") is None # claims do not create current graph records
52 finally:
53 graph.close()
Here integers are UTC microseconds on a schematic timeline. Use timezone-aware instants or explicit UTC strings for application dates. Stored rules consume positive entity-object claims in one world; they do not infer arbitrary facts from a contradiction. A negative claim is not a rule’s scoped absence check.
Identity and revision
statement_id identifies the proposition. claim_id also binds polarity,
agent, source and world, so independent sources remain distinguishable.
Confidence/provenance are not identity fields; correct_claim revises them
without replacing the sourced identity. Corrections/retractions append history
and can be valid-interval-local. Entity IDs are the default object kind; use
object_kind="literal" for canonical JSON-compatible values.
Claims do not require preexisting Node objects. Graph payload serializer choice
does not change their canonical JSON claim encoding. Indexed reads still require
fresh temporal indexes; exhaust historical iterators and discard partial output
on failure (Read one historical account consistently).
Continue by task
Stored rules and support maintenance: independent supports, bounded maintenance, scoped absence, and the difference from standalone Datalog.
Bounded Modal and Epistemic Evaluation: explicitly linked worlds, belief/knowledge/possibility and one authenticated read horizon.
Unified inference audit: tagged model-output evidence and bounded audit exports. Confidence scores and exported explanations are not proof verification.
Epistemic Claims and Provenance: exact claim lookup, correction and identity contracts. Append and revise historical records covers shared index/recovery boundaries.