engine.rete.network¶
RETE network construction, node sharing, and matching.
Classes¶
First layer of the RETE network. |
|
Specialized alpha node that wraps read-only predicate callables. |
|
Join node maintaining partial-match memory for conjunctive rule bodies. |
|
Schedule engine-managed consequents from one completed match. |
|
Canonicalizing store for structurally shared network nodes. |
|
Orchestrator for RETE network assembly from compiled rule representations. |
|
Minimal read-only rule context for builtin predicate evaluation. |
|
Minimal matching pass over alpha, beta, predicate, and terminal nodes. |
Module Contents¶
- class engine.rete.network.AlphaNode(/, **data: Any)¶
Bases:
pydantic.BaseModelFirst layer of the RETE network.
Filters individual facts based on literal constant constraints before any join work occurs.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- condition: engine.rete.compiler.CompiledTripleCondition = None¶
- constraints: tuple[engine.rete.compiler.AlphaConstraint, Ellipsis] = None¶
- class engine.rete.network.PredicateNode(/, **data: Any)¶
Bases:
pydantic.BaseModelSpecialized alpha node that wraps read-only predicate callables.
Predicate nodes represent body-side evaluation only; they are not callback hooks and they do not emit logical consequences directly.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- condition: engine.rete.compiler.CompiledPredicateCondition = None¶
- class engine.rete.network.BetaNode(/, **data: Any)¶
Bases:
pydantic.BaseModelJoin node maintaining partial-match memory for conjunctive rule bodies.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class engine.rete.network.TerminalNode(/, **data: Any)¶
Bases:
pydantic.BaseModelSchedule engine-managed consequents from one completed match.
Terminal nodes handle logical production, optional observational callbacks, and contradiction diagnostics.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- rule: engine.rete.compiler.CompiledRule = None¶
- class engine.rete.network.NodeRegistry(/, **data: Any)¶
Bases:
pydantic.BaseModelCanonicalizing store for structurally shared network nodes.
Node sharing is part of the intended RETE optimization strategy and should remain independent from proof reconstruction concerns.
- model_config¶
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- predicate_nodes: dict[str, PredicateNode] = None¶
- terminal_nodes: dict[str, TerminalNode] = None¶
- get_or_create_alpha(node: AlphaNode) AlphaNode¶
Return a shared alpha node, creating
nodewhen needed.
- get_or_create_predicate(node: PredicateNode) PredicateNode¶
Return a shared predicate node, creating
nodewhen needed.
- add_terminal(node: TerminalNode) TerminalNode¶
Register
nodeas a terminal and return it.
- evict_partial_matches_referencing(fact_ids: frozenset[str]) None¶
Drop persisted partial matches that reference any of these fact ids.
Network alpha and beta memories accumulate
PartialMatchrecords across calls toNetworkMatcher.match_terminals. When the engine retracts triples, the correspondingFactobjects leave working memory; the persisted partial matches must also be evicted so that subsequent join passes do not produce activations grounded in removed facts.
- class engine.rete.network.NetworkBuilder(registry: NodeRegistry | None = None)¶
Orchestrator for RETE network assembly from compiled rule representations.
The builder turns compiled rules into canonical alpha, beta, and predicate nodes plus per-rule terminal nodes using a left-deep join assembly.
- registry: NodeRegistry¶
- build_rule(rule: engine.rete.compiler.CompiledRule) TerminalNode¶
Build the terminal node and join chain for one compiled rule.
- build_rules(rules: tuple[engine.rete.compiler.CompiledRule, Ellipsis]) tuple[TerminalNode, Ellipsis]¶
Build terminal nodes for every compiled rule in
rules.
- class engine.rete.network.MatcherContext(terminal: TerminalNode)¶
Bases:
engine.builtins.RuleContextMinimal read-only rule context for builtin predicate evaluation.
- terminal¶
- class engine.rete.network.NetworkMatcher(registry: NodeRegistry, *, predicates: dict[str, engine.builtins.PredicateHook] | None = None)¶
Minimal matching pass over alpha, beta, predicate, and terminal nodes.
- registry: NodeRegistry¶
- predicates: dict[str, engine.builtins.PredicateHook]¶
- match_terminal(terminal: TerminalNode, facts: collections.abc.Iterable[engine.rete.facts.Fact | axiom.common.Triple]) tuple[engine.rete.consequents.ActionInstance, Ellipsis]¶
Match
terminalagainstfactsand return scheduled actions.
- match_terminals(terminals: collections.abc.Iterable[TerminalNode], facts: collections.abc.Iterable[engine.rete.facts.Fact | axiom.common.Triple]) tuple[engine.rete.consequents.ActionInstance, Ellipsis]¶
Match every terminal in
terminalsagainstfacts.