From bc41a619cec2b71be53b50411da8a9ea7805bc5e Mon Sep 17 00:00:00 2001 From: Per Stark Date: Fri, 29 May 2026 09:34:32 +0200 Subject: [PATCH] chore: move serde helpers to common utils Relocate SurrealDB serde helpers out of storage types so they can be reused broadly, and align retrieval-pipeline test setup with configured embedding dimensions. --- common/src/storage/types/analytics.rs | 3 ++- common/src/storage/types/knowledge_relationship.rs | 2 +- common/src/storage/types/mod.rs | 3 +-- common/src/storage/types/system_settings.rs | 2 +- common/src/utils/mod.rs | 1 + common/src/{storage/types => utils}/serde_helpers.rs | 0 html-router/src/routes/search/handlers.rs | 8 ++------ retrieval-pipeline/src/lib.rs | 12 ++++++++++++ 8 files changed, 20 insertions(+), 11 deletions(-) rename common/src/{storage/types => utils}/serde_helpers.rs (100%) diff --git a/common/src/storage/types/analytics.rs b/common/src/storage/types/analytics.rs index 0156854..62e5768 100644 --- a/common/src/storage/types/analytics.rs +++ b/common/src/storage/types/analytics.rs @@ -1,4 +1,5 @@ -use crate::storage::types::{serde_helpers::deserialize_flexible_id, user::User, StoredObject}; +use crate::storage::types::{user::User, StoredObject}; +use crate::utils::serde_helpers::deserialize_flexible_id; use serde::{Deserialize, Serialize}; use crate::{error::AppError, storage::db::SurrealDbClient}; diff --git a/common/src/storage/types/knowledge_relationship.rs b/common/src/storage/types/knowledge_relationship.rs index f73a6f3..2f6cd07 100644 --- a/common/src/storage/types/knowledge_relationship.rs +++ b/common/src/storage/types/knowledge_relationship.rs @@ -1,4 +1,4 @@ -use crate::storage::types::serde_helpers::deserialize_flexible_id; +use crate::utils::serde_helpers::deserialize_flexible_id; use crate::storage::types::user::User; use crate::{error::AppError, storage::db::SurrealDbClient}; use serde::{Deserialize, Serialize}; diff --git a/common/src/storage/types/mod.rs b/common/src/storage/types/mod.rs index 02abb1f..f9a4d62 100644 --- a/common/src/storage/types/mod.rs +++ b/common/src/storage/types/mod.rs @@ -10,7 +10,6 @@ pub mod knowledge_entity_embedding; pub mod knowledge_relationship; pub mod message; pub mod scratchpad; -pub mod serde_helpers; pub mod system_prompts; pub mod system_settings; pub mod text_chunk; @@ -29,7 +28,7 @@ macro_rules! stored_object { use serde::{Deserialize, Serialize}; use $crate::storage::types::StoredObject; #[allow(unused_imports)] - use $crate::storage::types::serde_helpers::{ + use $crate::utils::serde_helpers::{ deserialize_flexible_id, serialize_datetime, deserialize_datetime, serialize_option_datetime, deserialize_option_datetime, }; diff --git a/common/src/storage/types/system_settings.rs b/common/src/storage/types/system_settings.rs index ae51e50..0e39bee 100644 --- a/common/src/storage/types/system_settings.rs +++ b/common/src/storage/types/system_settings.rs @@ -1,4 +1,4 @@ -use crate::storage::types::serde_helpers::deserialize_flexible_id; +use crate::utils::serde_helpers::deserialize_flexible_id; use serde::{Deserialize, Serialize}; use crate::{error::AppError, storage::db::SurrealDbClient, storage::types::StoredObject}; diff --git a/common/src/utils/mod.rs b/common/src/utils/mod.rs index 2801c3f..afbd30c 100644 --- a/common/src/utils/mod.rs +++ b/common/src/utils/mod.rs @@ -1,4 +1,5 @@ pub mod config; pub mod embedding; pub mod ingest_limits; +pub mod serde_helpers; pub mod template_engine; diff --git a/common/src/storage/types/serde_helpers.rs b/common/src/utils/serde_helpers.rs similarity index 100% rename from common/src/storage/types/serde_helpers.rs rename to common/src/utils/serde_helpers.rs diff --git a/html-router/src/routes/search/handlers.rs b/html-router/src/routes/search/handlers.rs index 85f05e4..248fd2b 100644 --- a/html-router/src/routes/search/handlers.rs +++ b/html-router/src/routes/search/handlers.rs @@ -8,12 +8,8 @@ use axum::{ extract::{Query, State}, response::IntoResponse, }; -use common::storage::types::{ - serde_helpers::deserialize_flexible_id, - text_content::TextContent, - user::User, - StoredObject, -}; +use common::storage::types::{text_content::TextContent, user::User, StoredObject}; +use common::utils::serde_helpers::deserialize_flexible_id; use retrieval_pipeline::{RetrievalConfig, SearchResult, SearchTarget, StrategyOutput}; use serde::{de, Deserialize, Deserializer, Serialize}; use surrealdb::RecordId; diff --git a/retrieval-pipeline/src/lib.rs b/retrieval-pipeline/src/lib.rs index 00595e6..15bc7af 100644 --- a/retrieval-pipeline/src/lib.rs +++ b/retrieval-pipeline/src/lib.rs @@ -94,6 +94,7 @@ mod tests { use anyhow::{self}; use async_openai::Client; use common::storage::indexes::ensure_runtime; + use common::storage::types::system_settings::SystemSettings; use uuid::Uuid; fn test_embedding() -> Vec { @@ -108,6 +109,16 @@ mod tests { vec![0.2, 0.8, 0.0] } + async fn configure_embedding_dimension( + db: &SurrealDbClient, + dimension: u32, + ) -> anyhow::Result<()> { + let mut settings = SystemSettings::get_current(db).await?; + settings.embedding_dimensions = dimension; + SystemSettings::update(db, settings).await?; + Ok(()) + } + async fn setup_test_db() -> anyhow::Result { let namespace = "test_ns"; let database = &Uuid::new_v4().to_string(); @@ -115,6 +126,7 @@ mod tests { db.apply_migrations().await?; + configure_embedding_dimension(&db, 3).await?; ensure_runtime(&db, 3).await?; Ok(db)