typedb icon indicating copy to clipboard operation
typedb copied to clipboard

Running a scoped set of rules

Open maydanw opened this issue 3 years ago • 1 comments

Problem to Solve

Currently, we either run all the rules or none.

For example:
Say a user has a set of rules which are quite expensive but when making most of the queries this set of rules is irrelevant and could be ignored.

Current Workaround

Turning it fully on or off

Proposed Solution

It can be beneficial to have the ability to add tags/labels to the rules and when running the transaction instead of setting inference off/on as boolean send a list of the relevant tags, * (which means all) or None/empty list (for no inference at all). The sent list can be kept short as a user can put multiple tags on a single rule in the schema (this exclusion is not required).

How it should look?
An option I can think of is at the moment is below but there can be better solutions:

rule user_in_sup_group:
  when {
    $g1 isa user_group;
    $g2 isa user_group;
    (inside: $user, container: $g1) isa containment;
    (inside: $g1, container: $g2) isa containment;
  }
  then {
    (inside: $user, container: $g2) isa containment;
  }
  settings {
     labels: ["permission", "containment"]
  };
...
typedb_options = TypeDBOptions.core()
typedb_options.inference_scope = ["containment"]

with session.transaction(
            TransactionType.READ, options=get_db_options(typedb_options)
        ) as tx:
...

maydanw avatar Jun 01 '21 11:06 maydanw

To clarify, we already only run the set of rules that may be applicable to a query, rather than all rules. We do this primarily by filtering the types the query may require, and only run rules that can conclude those types.

A further feature request would be run a subset of rules according to user's domain knowledge (eg. ignore this set of rules for this query) - this is a feature though, and not necessarily an optimisation.

flyingsilverfin avatar Nov 02 '21 14:11 flyingsilverfin