offline_intelligence/cache_management/
cache_config.rs1use serde::{Deserialize, Serialize};
4
5#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct KVCacheConfig {
8 pub enabled: bool,
10
11 pub retrieval_enabled: bool,
13
14 pub clear_after_conversations: usize,
16
17 pub memory_threshold_percent: f32,
19
20 pub bridge_enabled: bool,
22
23 pub max_cache_entries: usize,
25
26 pub min_importance_to_preserve: f32,
28
29 pub generate_cache_embeddings: bool,
31
32 pub retrieval_strategy: RetrievalStrategy,
34
35 pub preserve_system_prompts: bool,
37
38 pub preserve_code_entries: bool,
40
41 pub snapshot_strategy: SnapshotStrategy,
43}
44
45impl Default for KVCacheConfig {
46 fn default() -> Self {
47 Self {
48 enabled: true,
49 retrieval_enabled: true,
50 clear_after_conversations: 16, memory_threshold_percent: 0.6, bridge_enabled: true,
53 max_cache_entries: 1000,
54 min_importance_to_preserve: 0.7,
55 generate_cache_embeddings: true,
56 retrieval_strategy: RetrievalStrategy::KeywordThenSemantic,
57 preserve_system_prompts: true,
58 preserve_code_entries: true,
59 snapshot_strategy: SnapshotStrategy::Incremental {
60 interval_conversations: 4, max_snapshots: 4, },
63 }
64 }
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize)]
69pub enum RetrievalStrategy {
70 KeywordOnly,
72 SemanticOnly,
74 KeywordThenSemantic,
76 SemanticThenKeyword,
78 Hybrid {
80 keyword_weight: f32,
81 semantic_weight: f32,
82 },
83}
84
85#[derive(Debug, Clone, Serialize, Deserialize)]
87pub enum SnapshotStrategy {
88 None,
90 Full {
92 interval_conversations: usize,
93 },
94 Incremental {
96 interval_conversations: usize,
97 max_snapshots: usize,
98 },
99 Adaptive {
101 min_importance_threshold: f32,
102 max_snapshots: usize,
103 },
104}
105
106#[derive(Debug, Clone, Serialize, Deserialize)]
108pub struct CachePreservationConfig {
109 pub preserve_attention_keys: bool,
111
112 pub preserve_attention_values: bool,
114
115 pub preserve_ffn_keys: bool,
117
118 pub preserve_ffn_values: bool,
120
121 pub preserve_early_layers: bool,
123
124 pub preserve_late_layers: bool,
126
127 pub custom_patterns: Vec<String>,
129}
130
131impl Default for CachePreservationConfig {
132 fn default() -> Self {
133 Self {
134 preserve_attention_keys: true,
135 preserve_attention_values: true,
136 preserve_ffn_keys: false,
137 preserve_ffn_values: false,
138 preserve_early_layers: true,
139 preserve_late_layers: false,
140 custom_patterns: Vec::new(),
141 }
142 }
143}