typedb
typedb copied to clipboard
Always add isa concludables to variables
Problem to Solve
To solve both the issue of not having explainable inferred concepts (for example when querying match $x has $y
, where $x is inferred as well but not explainable at the top level), as well as normalising queries and providing maximum information to the reasoner query planner, we should augment the Concludable
objects generated from a user's query or rule to include extra isa
concludables for every variable without a type.
We should also rename the Isa
concludable to something more generic such as ConceptConcludable
or something like that.
Proposed Solution
- in reasoner, when generating
Concludable
objects from a user's query, we should augment the variables that are missingisa
with a new Concludable that contains the most specific type possible - this should guarantee that user queries
match $x has $y
,match $x isa thing, has $y;
andmatch $x isa thing, has attribute $y;
should all be equivalent - we shift all the burden of efficiently executing the larger set of
Resolvable
s to reasoner query planning
Example
We take a rules:
when {
$x isa dog-ownership;
$a isa date;
} then {
$x has $a;
}
when {
<something>
} then {
(...) isa dog-ownership;
If a query is written as match $x has $y;
, we will currently generate one Has
concludable, which will immediately trigger the has
rule. This will in turn trigger the dog-ownership
rule via the Isa
concludable in its condition.
If we conceptually augment the query to be match $x isa relation; $x has $y;
(or something slightly more specific that isn't quite as specific as dog-ownership
), we open ourselves up to executing a much more generic isa relation
concludable first -- which may trigger a huge number of rules concluding relations. Most of these are irrelevant to the rule concluding the ownership. Thus, the planning will have to balance the cost of executing the $x isa relation
first, against doing the has
first that will chain into the rule about dog-ownership
.
It can be more efficient to execute a more generic isa
earlier, and have it be filtered by a concludable too. For example, if the isa
concludable generates 100 concepts that have to be filtered against the next concludable, vs. the rule having to recurse through 10 rules to get to a more specific isa
. We have to balance the cost of inferring the isa
immediately and filtering at the top rule for the concludable against the concludable recursing through 10 rules to get to a more specific rule, which again is a planning problem.
Intermediate Solution
To start with, we can swallow a larger cost when the user enables explanations. With explanations enabled, we can augument the queries and rules with the required IsaConcludables
(ie. ConceptConcludable
or whatever else we will generalise it to). In the future, when planning is implemented, we can add the extra information all the time.