Discussion Forum

Inference examples from Quickstart not working

Hey everyone, this is going to be a bit lengthy, but I’ll try to describe my problem as best as possible.

I’m currently trying to get started with TypeDB running in Docker, but have not been able to cleanly get through the Quickstart because the examples on inference don’t return any results and I’m not able to figure out why.

The Docker image I am running is vaticle/typedb:latest@1262b4878b5f, which has TypeDB 2.5.0 bundled. I have downloaded both, the schema, and the data files linked in the Quickstart and mounted them as local volumes into the container, which I am sure works without problems as anything else from the Quickstart works just as expected.

However, when running the queries found in the Store Knowledge section where relations should be inferred from the queries, I don’t get any results at all, even though the data seems to be correct.

My investigation of the first example so far:

Both, the Quickstart and the actual schema define

define
  
content-permission sub relation,
  relates grantee,
  relates content;

Furthermore, the schema defines the abstract entity post to play the role of content-permission:content, and person to play the role of content-permission:grantee. The data file has the following instances defined:

insert
# ...
$per-3 isa person, has full-name "Julie Hutchinson", has gender "female", has email "julie.hutchinson@gmail.com", has phone-number "+44-1632-960166", has phone-number "+61-491-570-110";
# ...

$per-1-pos-1 isa status-update, has content "$per-1-pos-1-content", has identifier "$per-1-pos-1";
$per-1-pos-1-sha (content: $per-1-pos-1, by: $per-1, in: $tim-1, with: $per-3) isa inclusive-sharing;

In the schema, we can see that $per-1-pos-1 as a status-update is a subtype of post and should thus also be able to play the role of content-permission:content.

Summing everything up, if I got everything right, the query

match 
$p isa person, has email "julie.hutchinson@gmail.com"; 
(grantee: $p, content: $c)isa content-permission; 
get $c;

as seen in the Quickstart should infer a content-permission relation between the person “Julie Hutchinson” and the status-update $per-1-pos-1 because of the $per-1-pos-1-sha relation. However, no such relation is returned upon executing the query, 0 results are returned.

The next example concerning an inferred relation using a rules does not work as well. The rule is

define

mutual-friendship sub relation,
  relates mutual-friend,
  relates one-degree-friend;

rule people-have-mutual-friends:
  when {
	($p1, $p2) isa friendship;
	($p2, $p3) isa friendship;
  } then {
	(one-degree-friend: $p1, one-degree-friend: $p3, mutual-friend: $p2) isa mutual-friendship;
  };

And again, executing the query

match 
$p isa person, has email "julie.hutchinson@gmail.com"; 
$p2 isa person, has full-name $name; 
(one-degree-friend: $p2, mutual-friend: $p) isa mutual-friendship; 
get $p2, $name;

yields no results at all. This is a lot easier to track down, though, by executing these three queries:

match
$p isa person, has email "julie.hutchinson@gmail.com";
$p2 isa person, has email $mail;
($p, $p2) isa friendship;
get $p2, $mail;

which returns

{ $p2 iid 0x966e800d8000000000000009 isa person; $mail "miriam.morton@gmail.com" isa email; }
{ $p2 iid 0x966e800d8000000000000006 isa person; $mail "solomon.tran@gmail.com" isa email; }
{ $p2 iid 0x966e800d8000000000000001 isa person; $mail "jeremy.kelley@gmail.com" isa email; }

then

match
$p isa person, has email "miriam.morton@gmail.com";
$p2 isa person, has email $mail;
($p, $p2) isa friendship;
get $p2, $mail;

returning

{ $p2 iid 0x966e800d8000000000000002 isa person; $mail "julie.hutchinson@gmail.com" isa email; }
{ $p2 iid 0x966e800d8000000000000006 isa person; $mail "solomon.tran@gmail.com" isa email; }

and finally

match
$p isa person, has email "solomon.tran@gmail.com";
$p2 isa person, has email $mail;
($p, $p2) isa friendship;
get $p2, $mail;

from which I get

{ $p2 iid 0x966e800d8000000000000002 isa person; $mail "julie.hutchinson@gmail.com" isa email; }
{ $p2 iid 0x966e800d800000000000000a isa person; $mail "leona.rice@gmail.com" isa email; }
{ $p2 iid 0x966e800d8000000000000009 isa person; $mail "miriam.morton@gmail.com" isa email; }

This shows us that miriam.morton@gmail.com and solomon.tran@gmail.com are both friends with each other and also friends with julie.hutchinson@gmail.com, which satisfies the definition of the mutual-friendship relation and should thus return these two person entities, but again, no results.

So as demonstrated, schema and data are perfectly valid, but the whole inference mechanism does not seem to be working. I wanted to upload the schema and data files in question but I can’t as I’m a new user, but they’re the exact same ones as found on the Quickstart page, so can also be downloaded from there.

As I am just getting started myself, this is about the limit of debugging/troubleshooting I am able to do at this moment and I have run out of ideas what to try or what to look for, so any help is greatly appreciated.

Many thanks!

Hi Kvist
I’ve loaded the social network schema and data and took your first query. To get the work easy done I used the TypeDB-Studio. The first run showed the same result you’ve reported it. Afterwards I enabled the reasoning and explanations. The next run comes up with the results you expected.
On the console you can use the following:

  • Start the typedb console
  • transaction social_network data read --infer true

the last point will start reading data with using inference switching on. This will give you the result for your query you’ve expected. Here the example:

social_network::data::read> match 
                            $p isa person, has email "julie.hutchinson@gmail.com"; 
                            $p2 isa person, has full-name $name; 
                            (one-degree-friend: $p2, mutual-friend: $p) isa mutual-friendship; 
                            get $p2, $name;
                            
{ $p2 iid 0x966e800c8000000000000000 isa person; $name "Jeremy Kelley" isa full-name; }
{ $p2 iid 0x966e800c800000000000000e isa person; $name "Solomon Tran" isa full-name; }
{ $p2 iid 0x966e800c800000000000000d isa person; $name "Miriam Morton" isa full-name; }
answers: 3, duration: 104 ms
social_network::data::read> 

HTH Frank

Hello Frank,

thank you so much! Worked right away, and of course, makes total sense. Just checked to see if I missed that, but the Quickstart doesn’t mention to start the console with the --infer flag enabled, only the Java code sets this.

I’m definitely going to give TypeDB Studio a try, but I usually prefer to start out as low-level as possible in order to understand the software I am using without functionality being “optimized away” by tools, and also to understand what these tools might be doing under the hood and appreciate the work they do.

In the end, I’m glad the issue wasn’t an issue after all and am actually glad it was only something this trivial. Thanks again for the quick help!

Hello Kvist
You are welcome. Maybe the guys from Vaticle reads this and change the documentation of the example. If you like there is a Discord server where the guys from Vaticle and the whole community around TypeDB meets. Here is the link: https://discord.gg/bFFsBnm4.

Best, Frank

Thanks, noted and added and reminder in the quickstart