fix: EmbeddingConfig::from_bot_config fallback to default bot config
All checks were successful
BotServer CI/CD / build (push) Successful in 6m9s

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.
This commit is contained in:
Rodrigo Rodriguez (Pragmatismo) 2026-04-13 08:19:42 -03:00
parent 782618e265
commit 1148069652

View file

@ -56,94 +56,47 @@ impl EmbeddingConfig {
Self::default() 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 { pub fn from_bot_config(pool: &DbPool, _bot_id: &uuid::Uuid) -> Self {
use crate::core::shared::models::schema::bot_configuration::dsl::*; use crate::core::config::ConfigManager;
use diesel::prelude::*;
let embedding_url = match pool.get() { let config_manager = ConfigManager::new(pool.clone());
Ok(mut conn) => bot_configuration
.filter(bot_id.eq(_bot_id))
.filter(config_key.eq("embedding-url"))
.select(config_value)
.first::<String>(&mut conn)
.ok()
.filter(|s| !s.is_empty()),
Err(_) => None,
}.unwrap_or_else(|| "".to_string());
let embedding_model = match pool.get() { let embedding_url = config_manager
Ok(mut conn) => bot_configuration .get_config(_bot_id, "embedding-url", Some(""))
.filter(bot_id.eq(_bot_id)) .unwrap_or_default();
.filter(config_key.eq("embedding-model"))
.select(config_value)
.first::<String>(&mut conn)
.ok()
.filter(|s| !s.is_empty()),
Err(_) => None,
}.unwrap_or_else(|| "BAAI/bge-multilingual-gemma2".to_string());
let embedding_key = match pool.get() { let embedding_model = config_manager
Ok(mut conn) => bot_configuration .get_config(_bot_id, "embedding-model", Some("BAAI/bge-multilingual-gemma2"))
.filter(bot_id.eq(_bot_id)) .unwrap_or_else(|_| "BAAI/bge-multilingual-gemma2".to_string());
.filter(config_key.eq("embedding-key"))
.select(config_value)
.first::<String>(&mut conn)
.ok()
.filter(|s| !s.is_empty()),
Err(_) => None,
};
let dimensions = match pool.get() { let embedding_key = config_manager
Ok(mut conn) => bot_configuration .get_config(_bot_id, "embedding-key", Some(""))
.filter(bot_id.eq(_bot_id)) .ok()
.filter(config_key.eq("embedding-dimensions")) .filter(|s| !s.is_empty());
.select(config_value)
.first::<String>(&mut conn)
.ok()
.and_then(|v| v.parse().ok()),
Err(_) => None,
}.unwrap_or_else(|| Self::detect_dimensions(&embedding_model));
let batch_size = match pool.get() { let dimensions = config_manager
Ok(mut conn) => bot_configuration .get_config(_bot_id, "embedding-dimensions", Some(""))
.filter(bot_id.eq(_bot_id)) .ok()
.filter(config_key.eq("embedding-batch-size")) .and_then(|v| v.parse().ok())
.select(config_value) .unwrap_or_else(|| Self::detect_dimensions(&embedding_model));
.first::<String>(&mut conn)
.ok()
.and_then(|v| v.parse().ok()),
Err(_) => None,
}.unwrap_or(16);
let timeout_seconds = match pool.get() { let batch_size = config_manager
Ok(mut conn) => bot_configuration .get_config(_bot_id, "embedding-batch-size", Some("16"))
.filter(bot_id.eq(_bot_id)) .ok()
.filter(config_key.eq("embedding-timeout")) .and_then(|v| v.parse().ok())
.select(config_value) .unwrap_or(16);
.first::<String>(&mut conn)
.ok()
.and_then(|v| v.parse().ok()),
Err(_) => None,
}.unwrap_or(60);
let max_concurrent_requests = match pool.get() { let timeout_seconds = config_manager
Ok(mut conn) => bot_configuration .get_config(_bot_id, "embedding-timeout", Some("60"))
.filter(bot_id.eq(_bot_id)) .ok()
.filter(config_key.eq("embedding-concurrent")) .and_then(|v| v.parse().ok())
.select(config_value) .unwrap_or(60);
.first::<String>(&mut conn)
.ok() let max_concurrent_requests = config_manager
.and_then(|v| v.parse().ok()), .get_config(_bot_id, "embedding-concurrent", Some("1"))
Err(_) => None, .ok()
}.unwrap_or(1); .and_then(|v| v.parse().ok())
.unwrap_or(1);
Self { Self {
embedding_url, embedding_url,