Rule Semantics¶
Evaluation Pipeline¶
- Parse Locy program.
- Build dependency graph.
- Validate types/schema compatibility.
- Stratify rules.
- Evaluate each stratum to fixpoint.
- Execute command phase (
QUERY,DERIVE,EXPLAIN,ABDUCE,ASSUMEbody).
Two-Phase Execution¶
Locy execution is split into two distinct phases with different execution engines:
Phase 1 — Strata Evaluation (DataFusion)
Rules compile to DataFusion LogicalPlan nodes. The query engine runs them through a fixpoint loop per stratum. Expression functions (similar_to(), etc.) have full access to storage, schema, and the Xervo embedding runtime.
Phase 2 — Command Dispatch (Row-Level)
After strata converge, commands (QUERY, DERIVE, ABDUCE, ASSUME) execute on materialized Vec<Row> facts. WHERE filters use a lightweight row-level evaluator. This path supports vector cosine similarity but not auto-embedding, FTS, or multi-source fusion.
| Context | Execution | Vector | Auto-Embed | FTS |
|---|---|---|---|---|
Rule MATCH ... WHERE/YIELD |
DataFusion | ✓ | ✓ | ✓ |
Rule ALONG / FOLD / post-FOLD WHERE |
DataFusion | ✓ | ✓ | ✓ |
DERIVE ... WHERE |
In-memory | ✓ | ✗ | ✗ |
ABDUCE ... WHERE |
In-memory | ✓ | ✗ | ✗ |
ASSUME ... WHERE |
In-memory | ✓ | ✗ | ✗ |
Semi-Naive Evaluation¶
Within a recursive stratum, Locy only re-evaluates rules using newly derived facts (the delta) rather than all known facts each iteration. This provides exponential speedup for transitive closures:
Iteration 0: delta₀ = base facts from MATCH
Iteration 1: delta₁ = evaluate(rules, delta₀) − known_facts
Iteration 2: delta₂ = evaluate(rules, delta₁) − known_facts
...
Iteration n: deltaₙ = ∅ → fixpoint reached
Overloaded Rules¶
Multiple CREATE RULE clauses sharing one name define one logical relation. Clauses can be prioritized where supported.
Negation Rules¶
IS NOT requires stratification-safe dependencies. Cyclic negation is rejected at compile time.
If the referenced rule exposes a PROB column, IS NOT becomes probabilistic complement (1 - p) rather than Boolean anti-join. Rules without a PROB column keep standard Boolean negation.
Monotonic Recursion¶
Recursive aggregation requires monotonic operators where specified. Non-monotonic recursive shapes are rejected.
MNOR and MPROD are monotonic and therefore legal inside recursive strata. They assume independent derivations unless exact_probability is enabled.
Determinism¶
BEST BY can use deterministic tie-breaking through config (deterministic_best_by = true).
Limits and Guardrails¶
Key guardrails come from LocyConfig:
max_iterationstimeoutmax_derived_bytesmax_explain_depthmax_slg_depthstrict_probability_domainprobability_epsilonexact_probabilitymax_bdd_variablestop_k_proofsdeterministic_best_by
See Errors & Limits for operational guidance.