context_forge/config.rs
1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use crate::scrub::ScrubConfig;
6
7/// Default recency half-life in hours (72 hours = 3 days).
8pub const DEFAULT_RECENCY_HALF_LIFE_HOURS: f64 = 72.0;
9
10/// Default recency half-life in seconds (72 hours).
11pub const DEFAULT_RECENCY_HALF_LIFE_SECS: f64 = DEFAULT_RECENCY_HALF_LIFE_HOURS * 3600.0;
12
13/// Runtime configuration for the context engine.
14#[derive(Debug, Clone, Serialize, Deserialize)]
15#[non_exhaustive]
16pub struct Config {
17 /// Maximum number of entries to retain.
18 pub max_entries: usize,
19 /// Total token budget for context injection.
20 pub token_budget: usize,
21 /// Path to the backing database file.
22 ///
23 /// The default (`:memory:`) is an in-memory `SQLite` database that is
24 /// **ephemeral** — all data is lost when the connection pool is
25 /// dropped. Set a real filesystem path for durable persistence.
26 pub db_path: PathBuf,
27 /// Strategy used when the store reaches capacity.
28 pub eviction_policy: EvictionPolicy,
29 /// Recency decay half-life in seconds.
30 ///
31 /// Controls how fast older entries lose relevance. A value of 259200 (72 hours)
32 /// means an entry's score halves every 3 days.
33 pub recency_half_life_secs: f64,
34 /// Secret-scrubbing configuration applied to entry content at save time.
35 pub scrub: ScrubConfig,
36}
37
38impl Default for Config {
39 /// Defaults: 10,000 max entries, an 8,192-token budget, an in-memory
40 /// database (see [`Self::db_path`] for persistence caveats), LRU
41 /// eviction, the default 72-hour recency half-life, and secret
42 /// scrubbing enabled.
43 fn default() -> Self {
44 Self {
45 max_entries: 10_000,
46 token_budget: 8192,
47 db_path: PathBuf::from(":memory:"),
48 eviction_policy: EvictionPolicy::Lru,
49 recency_half_life_secs: DEFAULT_RECENCY_HALF_LIFE_SECS,
50 scrub: ScrubConfig::default(),
51 }
52 }
53}
54
55/// Strategy for evicting entries when at capacity.
56#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
57#[non_exhaustive]
58pub enum EvictionPolicy {
59 /// Least-recently-used entries are evicted first.
60 Lru,
61}