Chapter 5 Query Features Overview : Two Common Ways to Use Queries

Two Common Ways to Use Queries
The following sections show two ways queries can be used.
Triggering a Query from a Rule (in an Inference Agent)
Queries can only run in a query agent. Rules can only run in an inference agent. In order for a rule to trigger a query to execute, the rule must send an event to the query agent. In order for the query results to be used in a rule, the query agent must send them in an event to an inference agent.
Inference Agent
1.
Query Agent
2.
3.
4.
Inference Agent
5.
6.
Using a Query as a Pre-filter
Query agents can act as pre-filters and routers. Suppose you want to check for the existence of a concept in the cache, using properties of an event. If the concept does not exist, you want to create it. You can achieve this result as follows:
Query Agent
1.
2.
On receiving a message (event A) at D1, the query agent executes the query statement to determine if the corresponding concept exists in cache.
Inference Agent
3.
4.