use std::path::PathBuf;
const DEFAULT_EMBEDDINGS_MODEL: &str = "BAAI/bge-small-en-v1.5";
const DEFAULT_HYBRID_ALPHA: f32 = 0.25;
#[derive(Debug, Clone)]
pub struct Config {
pub vault_path: PathBuf,
pub watch: bool,
pub log_level: String,
pub tantivy: bool,
pub embeddings: bool,
pub embeddings_model: String,
pub hybrid_alpha: f32,
}
impl Config {
pub fn load() -> Result<Self, String> {
let vault_path = std::env::args()
.nth(1)
.or_else(|| std::env::var("OBSIDIAN_VAULT_PATH").ok())
.map(PathBuf::from)
.ok_or_else(|| {
"Vault path required: pass as first argument or set OBSIDIAN_VAULT_PATH".to_string()
})?;
let watch = std::env::var("OBSIDIAN_WATCH")
.unwrap_or_else(|_| "true".into())
.eq_ignore_ascii_case("true");
let log_level = std::env::var("OBSIDIAN_LOG_LEVEL").unwrap_or_else(|_| "info".into());
let tantivy = std::env::var("OBSIDIAN_TANTIVY")
.unwrap_or_else(|_| "true".into())
.eq_ignore_ascii_case("true");
let embeddings = std::env::var("OBSIDIAN_EMBEDDINGS")
.unwrap_or_else(|_| "false".into())
.eq_ignore_ascii_case("true");
let embeddings_model = std::env::var("OBSIDIAN_EMBEDDINGS_MODEL")
.unwrap_or_else(|_| DEFAULT_EMBEDDINGS_MODEL.into());
let hybrid_alpha = std::env::var("OBSIDIAN_HYBRID_ALPHA")
.ok()
.and_then(|v| v.parse::<f32>().ok())
.unwrap_or(DEFAULT_HYBRID_ALPHA)
.clamp(0.0, 1.0);
Ok(Self {
vault_path,
watch,
log_level,
tantivy,
embeddings,
embeddings_model,
hybrid_alpha,
})
}
}