mirror of
https://gitea.ingwaz.work/Ingwaz/openbrain-mcp.git
synced 2026-06-16 06:17:08 +00:00
feat(config): add TruthConfig for truth scoring engine (#30)
Add TruthConfig struct to config.rs with all truth engine parameters: - enabled, scoring_interval_seconds, batch_size, rescore_after_seconds - pln_base_confidence, ecan_decay_rate, ecan_spread_factor - contradiction_threshold, verification_threshold, cross_ref_limit All settings configurable via OPENBRAIN__TRUTH__* env vars with sensible defaults. Update .env.example with full documentation of new variables. Update Config::load() builder and Default impl. Part of #29
This commit is contained in:
116
src/config.rs
116
src/config.rs
@@ -15,6 +15,7 @@ pub struct Config {
|
||||
pub dedup: DedupConfig,
|
||||
pub ttl: TtlConfig,
|
||||
pub auth: AuthConfig,
|
||||
pub truth: TruthConfig,
|
||||
}
|
||||
|
||||
/// Server configuration
|
||||
@@ -71,6 +72,41 @@ pub struct TtlConfig {
|
||||
pub cleanup_interval_seconds: u64,
|
||||
}
|
||||
|
||||
/// Truth scoring engine configuration
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct TruthConfig {
|
||||
/// Enable truth scoring background worker
|
||||
#[serde(default = "default_truth_enabled")]
|
||||
pub enabled: bool,
|
||||
/// Seconds between scoring cycles
|
||||
#[serde(default = "default_scoring_interval_seconds")]
|
||||
pub scoring_interval_seconds: u64,
|
||||
/// Number of memories to score per cycle
|
||||
#[serde(default = "default_truth_batch_size")]
|
||||
pub batch_size: usize,
|
||||
/// Seconds before a scored memory is re-evaluated
|
||||
#[serde(default = "default_rescore_after_seconds")]
|
||||
pub rescore_after_seconds: u64,
|
||||
/// Base confidence for PLN deduction chains
|
||||
#[serde(default = "default_pln_base_confidence")]
|
||||
pub pln_base_confidence: f32,
|
||||
/// ECAN STI decay rate per cycle (0.0–1.0)
|
||||
#[serde(default = "default_ecan_decay_rate")]
|
||||
pub ecan_decay_rate: f32,
|
||||
/// ECAN attention spread factor
|
||||
#[serde(default = "default_ecan_spread_factor")]
|
||||
pub ecan_spread_factor: f32,
|
||||
/// Similarity threshold above which conflicting memories are contradictions
|
||||
#[serde(default = "default_contradiction_threshold")]
|
||||
pub contradiction_threshold: f32,
|
||||
/// Truth value threshold for "verified" categorization
|
||||
#[serde(default = "default_verification_threshold")]
|
||||
pub verification_threshold: f32,
|
||||
/// Max related memories to cross-reference per scoring
|
||||
#[serde(default = "default_cross_ref_limit")]
|
||||
pub cross_ref_limit: i64,
|
||||
}
|
||||
|
||||
/// Authentication configuration
|
||||
#[derive(Debug, Clone, Deserialize)]
|
||||
pub struct AuthConfig {
|
||||
@@ -139,6 +175,38 @@ fn default_auth_enabled() -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
// Truth engine defaults
|
||||
fn default_truth_enabled() -> bool {
|
||||
false
|
||||
}
|
||||
fn default_scoring_interval_seconds() -> u64 {
|
||||
300
|
||||
}
|
||||
fn default_truth_batch_size() -> usize {
|
||||
50
|
||||
}
|
||||
fn default_rescore_after_seconds() -> u64 {
|
||||
86400
|
||||
}
|
||||
fn default_pln_base_confidence() -> f32 {
|
||||
0.85
|
||||
}
|
||||
fn default_ecan_decay_rate() -> f32 {
|
||||
0.95
|
||||
}
|
||||
fn default_ecan_spread_factor() -> f32 {
|
||||
0.05
|
||||
}
|
||||
fn default_contradiction_threshold() -> f32 {
|
||||
0.85
|
||||
}
|
||||
fn default_verification_threshold() -> f32 {
|
||||
0.8
|
||||
}
|
||||
fn default_cross_ref_limit() -> i64 {
|
||||
10
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Load configuration from environment variables
|
||||
pub fn load() -> Result<Self> {
|
||||
@@ -167,6 +235,41 @@ impl Config {
|
||||
)?
|
||||
// Auth settings
|
||||
.set_default("auth.enabled", default_auth_enabled())?
|
||||
// Truth engine settings
|
||||
.set_default("truth.enabled", default_truth_enabled())?
|
||||
.set_default(
|
||||
"truth.scoring_interval_seconds",
|
||||
default_scoring_interval_seconds() as i64,
|
||||
)?
|
||||
.set_default("truth.batch_size", default_truth_batch_size() as i64)?
|
||||
.set_default(
|
||||
"truth.rescore_after_seconds",
|
||||
default_rescore_after_seconds() as i64,
|
||||
)?
|
||||
.set_default(
|
||||
"truth.pln_base_confidence",
|
||||
default_pln_base_confidence() as f64,
|
||||
)?
|
||||
.set_default(
|
||||
"truth.ecan_decay_rate",
|
||||
default_ecan_decay_rate() as f64,
|
||||
)?
|
||||
.set_default(
|
||||
"truth.ecan_spread_factor",
|
||||
default_ecan_spread_factor() as f64,
|
||||
)?
|
||||
.set_default(
|
||||
"truth.contradiction_threshold",
|
||||
default_contradiction_threshold() as f64,
|
||||
)?
|
||||
.set_default(
|
||||
"truth.verification_threshold",
|
||||
default_verification_threshold() as f64,
|
||||
)?
|
||||
.set_default(
|
||||
"truth.cross_ref_limit",
|
||||
default_cross_ref_limit(),
|
||||
)?
|
||||
// Load from environment with OPENBRAIN_ prefix
|
||||
.add_source(
|
||||
config::Environment::with_prefix("OPENBRAIN")
|
||||
@@ -231,6 +334,17 @@ impl Default for Config {
|
||||
enabled: default_auth_enabled(),
|
||||
api_keys: Vec::new(),
|
||||
},
|
||||
}
|
||||
truth: TruthConfig {
|
||||
enabled: default_truth_enabled(),
|
||||
scoring_interval_seconds: default_scoring_interval_seconds(),
|
||||
batch_size: default_truth_batch_size(),
|
||||
rescore_after_seconds: default_rescore_after_seconds(),
|
||||
pln_base_confidence: default_pln_base_confidence(),
|
||||
ecan_decay_rate: default_ecan_decay_rate(),
|
||||
ecan_spread_factor: default_ecan_spread_factor(),
|
||||
contradiction_threshold: default_contradiction_threshold(),
|
||||
verification_threshold: default_verification_threshold(),
|
||||
cross_ref_limit: default_cross_ref_limit(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user