From 1148069652be53412dec16a712fabf1d99bc0ef3 Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Mon, 13 Apr 2026 08:19:42 -0300 Subject: [PATCH] fix: EmbeddingConfig::from_bot_config fallback to default bot config When a bot lacks embedding-url in its own config, from_bot_config now falls back to the default bot's config via ConfigManager::get_config. Previously it returned empty string, causing embedding server connection failures for bots without explicit embedding configuration. --- src/core/kb/embedding_generator.rs | 113 +++++++++-------------------- 1 file changed, 33 insertions(+), 80 deletions(-) diff --git a/src/core/kb/embedding_generator.rs b/src/core/kb/embedding_generator.rs index edf23244..1ec096b2 100644 --- a/src/core/kb/embedding_generator.rs +++ b/src/core/kb/embedding_generator.rs @@ -56,94 +56,47 @@ impl EmbeddingConfig { Self::default() } - /// Load embedding config from bot's config.csv (similar to llm-url, llm-model) - /// This allows configuring embedding server per-bot in config.csv: - /// embedding-url, - /// embedding-model,bge-small-en-v1.5 - /// embedding-dimensions,384 - /// embedding-batch-size,16 - /// embedding-timeout,60 - /// embedding-key,hf_xxxxx (for HuggingFace API) pub fn from_bot_config(pool: &DbPool, _bot_id: &uuid::Uuid) -> Self { - use crate::core::shared::models::schema::bot_configuration::dsl::*; - use diesel::prelude::*; + use crate::core::config::ConfigManager; - let embedding_url = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-url")) - .select(config_value) - .first::(&mut conn) - .ok() - .filter(|s| !s.is_empty()), - Err(_) => None, - }.unwrap_or_else(|| "".to_string()); + let config_manager = ConfigManager::new(pool.clone()); - let embedding_model = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-model")) - .select(config_value) - .first::(&mut conn) - .ok() - .filter(|s| !s.is_empty()), - Err(_) => None, - }.unwrap_or_else(|| "BAAI/bge-multilingual-gemma2".to_string()); + let embedding_url = config_manager + .get_config(_bot_id, "embedding-url", Some("")) + .unwrap_or_default(); - let embedding_key = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-key")) - .select(config_value) - .first::(&mut conn) - .ok() - .filter(|s| !s.is_empty()), - Err(_) => None, - }; + let embedding_model = config_manager + .get_config(_bot_id, "embedding-model", Some("BAAI/bge-multilingual-gemma2")) + .unwrap_or_else(|_| "BAAI/bge-multilingual-gemma2".to_string()); - let dimensions = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-dimensions")) - .select(config_value) - .first::(&mut conn) - .ok() - .and_then(|v| v.parse().ok()), - Err(_) => None, - }.unwrap_or_else(|| Self::detect_dimensions(&embedding_model)); + let embedding_key = config_manager + .get_config(_bot_id, "embedding-key", Some("")) + .ok() + .filter(|s| !s.is_empty()); - let batch_size = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-batch-size")) - .select(config_value) - .first::(&mut conn) - .ok() - .and_then(|v| v.parse().ok()), - Err(_) => None, - }.unwrap_or(16); + let dimensions = config_manager + .get_config(_bot_id, "embedding-dimensions", Some("")) + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or_else(|| Self::detect_dimensions(&embedding_model)); - let timeout_seconds = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-timeout")) - .select(config_value) - .first::(&mut conn) - .ok() - .and_then(|v| v.parse().ok()), - Err(_) => None, - }.unwrap_or(60); + let batch_size = config_manager + .get_config(_bot_id, "embedding-batch-size", Some("16")) + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(16); - let max_concurrent_requests = match pool.get() { - Ok(mut conn) => bot_configuration - .filter(bot_id.eq(_bot_id)) - .filter(config_key.eq("embedding-concurrent")) - .select(config_value) - .first::(&mut conn) - .ok() - .and_then(|v| v.parse().ok()), - Err(_) => None, - }.unwrap_or(1); + let timeout_seconds = config_manager + .get_config(_bot_id, "embedding-timeout", Some("60")) + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(60); + + let max_concurrent_requests = config_manager + .get_config(_bot_id, "embedding-concurrent", Some("1")) + .ok() + .and_then(|v| v.parse().ok()) + .unwrap_or(1); Self { embedding_url,