@@ -9,6 +9,16 @@ The search engine:
991 . Maintains a collection of rules and facts
10102 . Iteratively applies rules to generate new facts
11113 . Notifies you of each new inference via a callback
12+ 4 . Automatically prevents duplicate inferences
13+
14+ !!! info "How It Works"
15+ The search engine uses a forward-chaining inference approach:
16+
17+ 1. When you call ` execute() ` , the engine tries to match the first premise of each rule with existing facts
18+ 2. When a match is found, variables in the rule are substituted and a new rule (with one fewer premise) is created
19+ 3. If the new rule has no premises, it becomes a new fact
20+ 4. The callback is invoked for each newly derived rule
21+ 5. Duplicate rules are automatically filtered out
1222
1323## Creating a Search Engine
1424
@@ -21,7 +31,7 @@ The search engine:
2131 search = apyds.Search()
2232
2333 # Create with custom sizes
24- search = apyds.Search(limit_size=2000 , buffer_size=20000 )
34+ search = apyds.Search(limit_size=1000 , buffer_size=10000 )
2535 ```
2636
2737=== "TypeScript"
@@ -33,7 +43,7 @@ The search engine:
3343 const search = new search_t();
3444
3545 // Create with custom sizes
36- const search2 = new search_t(2000, 20000 );
46+ const search2 = new search_t(1000, 10000 );
3747 ```
3848
3949=== "C++"
@@ -47,8 +57,8 @@ The search engine:
4757
4858### Parameters
4959
50- - ** limit_size** : Maximum size (in bytes) for each stored rule/fact (default: 1000)
51- - ** buffer_size** : Size of the internal buffer for intermediate operations (default: 10000)
60+ - ** limit_size** : Maximum size (in bytes) for each stored rule/fact (default: 1000). Rules or facts larger than this are rejected.
61+ - ** buffer_size** : Size of the internal buffer for intermediate operations (default: 10000). Increase this if you work with complex rules.
5262
5363## Adding Rules and Facts
5464
@@ -66,11 +76,6 @@ Use the `add()` method to add rules and facts to the knowledge base.
6676
6777 # Add a rule with premises
6878 search.add("(father `X `Y)\n----------\n(parent `X `Y)\n")
69-
70- # Add multiple facts and rules
71- search.add("(father john mary)")
72- search.add("(father john bob)")
73- search.add("(mother mary alice)")
7479 ```
7580
7681=== "TypeScript"
@@ -298,6 +303,7 @@ Clears all rules and facts:
2983032 . ** Limit Size** : Restricts maximum rule/fact complexity - too small may reject valid rules
2993043 . ** Iterative Execution** : Call ` execute() ` in a loop to continue inference until convergence
3003054 . ** Early Termination** : Return ` true ` from callback to stop as soon as target is found
306+ 5 . ** Deduplication** : The engine automatically deduplicates facts, avoiding redundant computation
301307
302308## See Also
303309
0 commit comments