Avoiding duplicate linked facts without infinite loops? #333
Replies: 2 comments 5 replies
-
@douglasg14b I assume you are using Yield to produce linked facts. So, the way I understand the problem is that your rule files and Yields a fact that is already in the session, which causes an update of that fact, causing any rules that match that fact to fire multiple times.
So, instead of using Yield action, you can use Do action and manually code deduplication logic:
Use |
Beta Was this translation helpful? Give feedback.
-
It looks like there is confusion about the linked fact key - it simply identifies the linked fact within the current rule activation, in case the rule yields more than one type of fact. In your case you are only yielding one thing, so you can put anything there, or just put a string unique within the current rule, like A linked fact is still a fact, and so it has to be unique in the session, as determined by its equality comparison. If it's a record, it's equality comparison is just a structural value equality comparison. |
Beta Was this translation helpful? Give feedback.
-
The data streams I'm working with are not always pure, and often contain events that are functionally duplicates of each other.
This results in the session throwing an exception that a fact has already been added. However, for a linked fact, I cannot add a
.Not()
condition that enforces that the fact produced by this rule cannot refire if it has the same Id of an already existing fact (The rule can fire many time, but only for different fact output). The.Not()
causes an infinite loop of fact retraction & insertion, since it's linked. If it was unlinked this would work 🤔I was reading this & the linked thread: #234
But am still scratching my head on how to avoid duplicate facts inside the rules engine, when those facts are linked.
Beta Was this translation helpful? Give feedback.
All reactions