# Why inference doesn't work?

**URL:** <https://forum.typedb.com/t/why-inference-doesnt-work/490>\
**Category:** TypeDB\
**Created:** [13 May 2024 15:54 UTC](https://forum.typedb.com/t/why-inference-doesnt-work/490 "2024-05-13T15:54:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![zack](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/zack/32/99_2.png) [@zack](https://forum.typedb.com/u/zack)\
**Post date:** [13 May 2024 15:54 UTC](https://forum.typedb.com/t/why-inference-doesnt-work/490/1 "2024-05-13T15:54:42Z")

</div>

When testing the rule-based inference, can’t get the expected answer, need some help to figure out why.

shema:

```auto
define

ID sub attribute, value string;
x sub attribute, value long;

next sub relation, owns ID, relates left, relates right;
zhi sub entity, owns ID, owns x, plays next:left, plays next:right;

rule r1: when {
    $z1 isa zhi, has x $x1, has ID $n1;
    $z2 isa zhi, has x $x2, has ID $n2;
    $n1 = $n2;
    $x2 = 1;
    $x1 = 0;
} then {
    (left: $z1, right: $z2) isa next;
};

```

data:

```auto
insert $e isa zhi, has ID "sz", has x 0;
insert $e isa zhi, has ID "sz", has x 1;
insert $e isa zhi, has ID "sz", has x 2;
insert $e isa zhi, has ID "sz", has x 3;

insert $e isa zhi, has ID "s", has x 0;
insert $e isa zhi, has ID "s", has x 1;
insert $e isa zhi, has ID "s", has x 2;
insert $e isa zhi, has ID "s", has x 3;

```

query:

```auto
match $r isa next; fetch $r:ID;

```

As shown, it’s a simple test about rule based inference for a relation next. For the entity ‘zhi’ with the same ID, as long as x value is 0/1, the two ‘zhi’ have a relation ‘next’.

I’ve run the schema, inserted data and query with no error, but I can’t get the expect answer. Actually no result at all:

```auto
## Result> Fetch query did not retrieve any data from the database.

```

What’s wrong here?

Thanks for your help.

---

<div class="post-metadata">

**Author:** ![Christoph](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/christoph/32/208_2.png) [@Christoph](https://forum.typedb.com/u/Christoph)\
**Post date:** [14 May 2024 08:34 UTC](https://forum.typedb.com/t/why-inference-doesnt-work/490/2 "2024-05-14T08:34:08Z")

</div>

Hi @zack !

Did you enable the “infer” Option when running the read query?  
See here for more information [TypeDB | Docs \> Manual \> Inference](https://typedb.com/docs/manual/reading/infer)

---

<div class="post-metadata">

**Author:** ![zack](https://dub1.discourse-cdn.com/flex005/user_avatar/forum.typedb.com/zack/32/99_2.png) [@zack](https://forum.typedb.com/u/zack)\
**Post date:** [15 May 2024 04:16 UTC](https://forum.typedb.com/t/why-inference-doesnt-work/490/3 "2024-05-15T04:16:38Z")

</div>

I did NOT, my bad. Thanks for your help!
