use std::path::PathBuf;
const DEFAULT_EMBEDDINGS_MODEL: &str = "BAAI/bge-small-en-v1.5";
#[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,
}
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());
Ok(Self {
vault_path,
watch,
log_level,
tantivy,
embeddings,
embeddings_model,
})
}
}