uni_locy/config.rs
1use std::collections::HashMap;
2use std::time::Duration;
3
4use uni_common::Value;
5
6/// Configuration for the Locy orchestrator.
7#[derive(Debug, Clone)]
8pub struct LocyConfig {
9 /// Maximum fixpoint iterations per recursive stratum.
10 pub max_iterations: usize,
11 /// Overall evaluation timeout.
12 pub timeout: Duration,
13 /// Maximum recursion depth for EXPLAIN derivation trees.
14 pub max_explain_depth: usize,
15 /// Maximum recursion depth for SLG resolution.
16 pub max_slg_depth: usize,
17 /// Maximum candidate modifications to generate during ABDUCE.
18 pub max_abduce_candidates: usize,
19 /// Maximum validated results to return from ABDUCE.
20 pub max_abduce_results: usize,
21 /// Maximum bytes of derived facts to hold in memory per relation.
22 pub max_derived_bytes: usize,
23 /// When true, BEST BY applies a secondary sort on remaining columns for
24 /// deterministic tie-breaking. Set to false for non-deterministic (faster)
25 /// selection.
26 pub deterministic_best_by: bool,
27 /// When true, MNOR/MPROD reject values outside \[0,1\] with an error instead
28 /// of clamping. When false (default), values are clamped silently.
29 pub strict_probability_domain: bool,
30 /// Underflow threshold for MPROD log-space switch (spec ยง5.3).
31 ///
32 /// When the running product drops below this value, `product_f64`
33 /// switches to log-space accumulation to prevent floating-point
34 /// underflow.
35 pub probability_epsilon: f64,
36 /// When true, groups flagged with shared probabilistic dependencies use
37 /// exact BDD-based probability computation instead of the independence
38 /// assumption (MNOR/MPROD). Defaults to false (independence mode).
39 pub exact_probability: bool,
40 /// Maximum number of BDD variables (unique base facts) allowed per
41 /// aggregation group. If a group exceeds this limit, it falls back to
42 /// the independence-mode result and emits a `BddLimitExceeded` warning.
43 pub max_bdd_variables: usize,
44 /// Top-k proof filtering (Scallop, Huang et al. 2021): retain at most k
45 /// proofs per derived fact, ranked by proof probability. When 0 (default),
46 /// all proofs are retained (unlimited mode).
47 pub top_k_proofs: usize,
48 /// Override `top_k_proofs` during training. When `Some(k)`, training
49 /// evaluation uses this value instead of `top_k_proofs`. When `None`,
50 /// `top_k_proofs` is used for both training and inference.
51 pub top_k_proofs_training: Option<usize>,
52 /// Parameters bound to `$name` references inside rules and QUERY/RETURN
53 /// expressions. Equivalent to the parameter map passed to `db.query()`.
54 /// Keys are parameter names **without** the leading `$` (e.g., `"agent_id"`
55 /// binds `$agent_id`).
56 pub params: HashMap<String, Value>,
57}
58
59impl Default for LocyConfig {
60 fn default() -> Self {
61 Self {
62 max_iterations: 1000,
63 timeout: Duration::from_secs(300),
64 max_explain_depth: 100,
65 max_slg_depth: 1000,
66 max_abduce_candidates: 20,
67 max_abduce_results: 10,
68 max_derived_bytes: 256 * 1024 * 1024,
69 deterministic_best_by: true,
70 strict_probability_domain: false,
71 probability_epsilon: 1e-15,
72 exact_probability: false,
73 max_bdd_variables: 1000,
74 top_k_proofs: 0,
75 top_k_proofs_training: None,
76 params: HashMap::new(),
77 }
78 }
79}