Hi James, and thanks for the quick response! A little more about the project: we’re building a knowledge base of cultural and historical information. Our approach to handling uncertain nature of humanities knowledge is to accept potentially contradictory facts into the knowledge base, and when someone asks a question, they’ll get back all of the answers we have with the evidence we have for each perspective. That’s why we’re keen to preserve all of the reasoning chains that lead to a fact, because more supporting evidence for a claim strengthens the claim.
With regard to fact duplication, I might’ve communicated my question poorly. The behavior I’ve observed is that when a rule infers a fact that already exists, that fact has no explainables. It’s as if the inference didn’t happen at all. For our project, because we’ll have a mix of “expert opinions” with no modeled evidence and facts derived from evidence via rules, it would be useful for a fact to be both manually-entered and inferred, because then the expert opinion and the evidence work together to strengthen the claim.
About multiple reasoning chains: I was using the client, but maybe I was doing something wrong. Here’s an example of the behavior I observed:
# TypeQL
define
attr1 sub attribute, value string;
attr2 sub attribute, value string;
attr3 sub attribute, value string;
foo sub entity, owns attr1, owns attr2, owns attr3;
insert $foo isa foo, has attr1 "foo", has attr3 "baz";
define rule rule1:
when { $foo isa foo, has attr1 "foo"; }
then { $foo has attr2 "bar"; };
define rule rule2:
when { $foo isa foo, has attr3 "baz"; }
then { $foo has attr2 "bar"; };
# Python
from typedb.client import *
with TypeDB.core_client("localhost:1729") as client:
with client.session("testing", SessionType.DATA, TypeDBOptions.core().set_infer(True).set_explain(True)) as session:
with session.transaction(TransactionType.READ) as txn:
r = list(txn.query().match("match $x isa foo, has attr2 $a; $a \"bar\"; get $a;"))
print("results", len(r))
print("ownerships", r[0].explainables().ownerships().keys())
print("attributes", r[0].explainables().attributes().keys())
print("relations", r[0].explainables().relations().keys())
explainable = r[0].explainables().ownerships()[('x', 'a')]
ex = list(txn.query().explain(explainable))
print("explanations", len(ex))
print("rule", ex[0].rule().get_label())
# Result
results 1
ownerships dict_keys([('x', 'a')])
attributes dict_keys([])
relations dict_keys([])
explanations 1
rule rule2
What I was hoping to see was multiple explanations returned. Instead, only one of the two possible explanations was returned, and the one that was returned seems to be picked arbitrarily.
With the duplicate fact thing I mentioned above, if I run match $foo isa foo, has attr1 "foo"; insert $foo has attr2 "bar";
, then ownerships, attributes, and relations all have empty dict_keys. I had hoped that ownerships would still have the explainable allowing me to discern that the fact was both manually added and inferred.
I’ll definitely ask in the discord server if I have questions on other topics, thanks again for the help and I look forward to learning more!