1use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6use crate::types::Language;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
10pub struct EngineConfig {
11 pub index_dir: PathBuf,
13 pub chunking: ChunkingConfig,
15 pub embedding: EmbeddingConfig,
17 pub search: SearchConfig,
19 pub ignore: IgnoreConfig,
21 pub performance: PerformanceConfig,
23}
24
25impl EngineConfig {
26 pub fn new(index_dir: PathBuf) -> Self {
28 Self {
29 index_dir,
30 chunking: ChunkingConfig::default(),
31 embedding: EmbeddingConfig::default(),
32 search: SearchConfig::default(),
33 ignore: IgnoreConfig::default(),
34 performance: PerformanceConfig::default(),
35 }
36 }
37
38 pub fn with_chunking(mut self, config: ChunkingConfig) -> Self {
40 self.chunking = config;
41 self
42 }
43
44 pub fn with_embedding(mut self, config: EmbeddingConfig) -> Self {
46 self.embedding = config;
47 self
48 }
49
50 pub fn with_search(mut self, config: SearchConfig) -> Self {
52 self.search = config;
53 self
54 }
55
56 pub fn with_ignore(mut self, config: IgnoreConfig) -> Self {
58 self.ignore = config;
59 self
60 }
61
62 pub fn with_performance(mut self, config: PerformanceConfig) -> Self {
64 self.performance = config;
65 self
66 }
67}
68
69impl Default for EngineConfig {
70 fn default() -> Self {
71 Self::new(PathBuf::from(".aurora"))
72 }
73}
74
75#[derive(Debug, Clone, Serialize, Deserialize)]
77pub struct ChunkingConfig {
78 pub max_chunk_size: usize,
80 pub min_chunk_size: usize,
82 pub extract_comments: bool,
84}
85
86impl Default for ChunkingConfig {
87 fn default() -> Self {
88 Self {
89 max_chunk_size: 2000,
90 min_chunk_size: 50,
91 extract_comments: true,
92 }
93 }
94}
95
96#[derive(Debug, Clone, Serialize, Deserialize)]
98pub struct EmbeddingConfig {
99 pub dimension: usize,
101 pub batch_size: usize,
103 pub max_length: usize,
105 pub normalize: bool,
107}
108
109impl Default for EmbeddingConfig {
110 fn default() -> Self {
111 Self {
112 dimension: 768, batch_size: 32,
114 max_length: 512,
115 normalize: true,
116 }
117 }
118}
119
120#[derive(Debug, Clone, Serialize, Deserialize)]
122pub struct SearchConfig {
123 pub default_limit: usize,
125 pub max_limit: usize,
127 pub default_mode: SearchMode,
129 pub lexical_weight: f32,
131 pub semantic_weight: f32,
133 pub min_score: f32,
135 pub fuzzy_matching: bool,
137 pub fuzzy_distance: u8,
139}
140
141impl Default for SearchConfig {
142 fn default() -> Self {
143 Self {
144 default_limit: 20,
145 max_limit: 100,
146 default_mode: SearchMode::Hybrid,
147 lexical_weight: 0.4,
148 semantic_weight: 0.6,
149 min_score: 0.1,
150 fuzzy_matching: true,
151 fuzzy_distance: 2,
152 }
153 }
154}
155
156#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
158pub enum SearchMode {
159 Lexical,
161 Semantic,
163 Hybrid,
165}
166
167impl Default for SearchMode {
168 fn default() -> Self {
169 Self::Hybrid
170 }
171}
172
173#[derive(Debug, Clone, Serialize, Deserialize)]
175pub struct IgnoreConfig {
176 pub use_gitignore: bool,
178 pub use_ignore_files: bool,
180 pub patterns: Vec<String>,
182 pub ignored_extensions: Vec<String>,
184 pub ignored_directories: Vec<String>,
186 pub max_file_size: u64,
188}
189
190impl Default for IgnoreConfig {
191 fn default() -> Self {
192 Self {
193 use_gitignore: true,
194 use_ignore_files: true,
195 patterns: vec![],
196 ignored_extensions: vec![
197 "exe".into(), "dll".into(), "so".into(), "dylib".into(),
198 "bin".into(), "obj".into(), "o".into(), "a".into(), "lib".into(),
199 "png".into(), "jpg".into(), "jpeg".into(), "gif".into(), "ico".into(),
200 "svg".into(), "woff".into(), "woff2".into(), "ttf".into(), "eot".into(),
201 "mp3".into(), "mp4".into(), "avi".into(), "mov".into(),
202 "zip".into(), "tar".into(), "gz".into(), "rar".into(), "7z".into(),
203 "pdf".into(), "doc".into(), "docx".into(),
204 ],
205 ignored_directories: vec![
206 "node_modules".into(), ".git".into(), ".svn".into(), ".hg".into(),
207 "target".into(), "build".into(), "dist".into(), "out".into(),
208 ".next".into(), ".nuxt".into(), "__pycache__".into(),
209 ".pytest_cache".into(), ".mypy_cache".into(),
210 "venv".into(), ".venv".into(), "vendor".into(),
211 ".idea".into(), ".vscode".into(), ".vs".into(),
212 ],
213 max_file_size: 1024 * 1024, }
215 }
216}
217
218#[derive(Debug, Clone, Serialize, Deserialize)]
220pub struct PerformanceConfig {
221 pub num_threads: usize,
223 pub memory_limit: usize,
225 pub incremental: bool,
227}
228
229impl Default for PerformanceConfig {
230 fn default() -> Self {
231 Self {
232 num_threads: std::thread::available_parallelism()
233 .map(|p| p.get())
234 .unwrap_or(4),
235 memory_limit: 512 * 1024 * 1024, incremental: true,
237 }
238 }
239}
240
241#[derive(Debug, Clone, Serialize, Deserialize)]
243pub struct WorkspaceConfig {
244 pub root_path: PathBuf,
246 pub additional_ignores: Vec<String>,
248 pub languages: Option<Vec<Language>>,
250 pub watch_changes: bool,
252}
253
254impl WorkspaceConfig {
255 pub fn new(root_path: PathBuf) -> Self {
257 Self {
258 root_path,
259 additional_ignores: vec![],
260 languages: None,
261 watch_changes: false,
262 }
263 }
264
265 pub fn with_ignores(mut self, patterns: Vec<String>) -> Self {
267 self.additional_ignores = patterns;
268 self
269 }
270
271 pub fn with_languages(mut self, languages: Vec<Language>) -> Self {
273 self.languages = Some(languages);
274 self
275 }
276
277 pub fn with_watch(mut self) -> Self {
279 self.watch_changes = true;
280 self
281 }
282}