From 11329830647bd3c37d526f5a6bfcc56b2e680cae Mon Sep 17 00:00:00 2001 From: "Rodrigo Rodriguez (Pragmatismo)" Date: Sat, 21 Mar 2026 18:55:36 -0300 Subject: [PATCH] feat(kb): add with_bot_config to load embedding from bot config - Adds KnowledgeBaseManager::with_default_config() as alias to new() - Adds KnowledgeBaseManager::with_bot_config() to load embedding_url, embedding_model, and qdrant config from bot's config.csv - Updates bootstrap to use with_bot_config with default_bot_id - Enables per-bot embedding configuration instead of global env vars --- src/core/kb/mod.rs | 27 +++++++++++++++++++++++++++ src/main_module/bootstrap.rs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/core/kb/mod.rs b/src/core/kb/mod.rs index 3f515fc5..aa4692d8 100644 --- a/src/core/kb/mod.rs +++ b/src/core/kb/mod.rs @@ -20,6 +20,8 @@ use std::sync::Arc; use tokio::sync::RwLock; use uuid::Uuid; +use crate::core::shared::utils::DbPool; + #[derive(Debug)] pub struct KnowledgeBaseManager { indexer: Arc, @@ -29,6 +31,10 @@ pub struct KnowledgeBaseManager { impl KnowledgeBaseManager { pub fn new(work_root: impl Into) -> Self { + Self::with_default_config(work_root) + } + + pub fn with_default_config(work_root: impl Into) -> Self { let work_root = work_root.into(); let embedding_config = EmbeddingConfig::from_env(); let qdrant_config = QdrantConfig::default(); @@ -47,6 +53,27 @@ impl KnowledgeBaseManager { } } + pub fn with_bot_config(work_root: impl Into, pool: DbPool, bot_id: Uuid) -> Self { + let work_root = work_root.into(); + let embedding_config = EmbeddingConfig::from_bot_config(&pool, &bot_id); + info!("KB Manager using embedding config from bot {}: url={}, model={}", + bot_id, embedding_config.embedding_url, embedding_config.embedding_model); + let qdrant_config = QdrantConfig::from_config(pool, &bot_id); + + let indexer = Arc::new(KbIndexer::new(embedding_config.clone(), qdrant_config)); + let processor = Arc::new(DocumentProcessor::default()); + let monitor = Arc::new(RwLock::new(KbFolderMonitor::new( + work_root, + embedding_config, + ))); + + Self { + indexer, + processor, + monitor, + } + } + pub async fn index_kb_folder( &self, bot_id: Uuid, diff --git a/src/main_module/bootstrap.rs b/src/main_module/bootstrap.rs index 5f00fefc..b7d4f702 100644 --- a/src/main_module/bootstrap.rs +++ b/src/main_module/bootstrap.rs @@ -509,7 +509,7 @@ pub async fn create_app_state( ); #[cfg(any(feature = "research", feature = "llm"))] - let kb_manager = Arc::new(crate::core::kb::KnowledgeBaseManager::new("work")); + let kb_manager = Arc::new(crate::core::kb::KnowledgeBaseManager::with_bot_config("work", pool.clone(), default_bot_id)); #[cfg(feature = "tasks")] let task_engine = Arc::new(crate::tasks::TaskEngine::new(pool.clone()));