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.
This commit is contained in:
Per Stark
2026-05-29 09:34:32 +02:00
parent ba8c36da1e
commit bc41a619ce
8 changed files with 20 additions and 11 deletions
+2 -1
View File
@@ -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 serde::{Deserialize, Serialize};
use crate::{error::AppError, storage::db::SurrealDbClient}; use crate::{error::AppError, storage::db::SurrealDbClient};
@@ -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::storage::types::user::User;
use crate::{error::AppError, storage::db::SurrealDbClient}; use crate::{error::AppError, storage::db::SurrealDbClient};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
+1 -2
View File
@@ -10,7 +10,6 @@ pub mod knowledge_entity_embedding;
pub mod knowledge_relationship; pub mod knowledge_relationship;
pub mod message; pub mod message;
pub mod scratchpad; pub mod scratchpad;
pub mod serde_helpers;
pub mod system_prompts; pub mod system_prompts;
pub mod system_settings; pub mod system_settings;
pub mod text_chunk; pub mod text_chunk;
@@ -29,7 +28,7 @@ macro_rules! stored_object {
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use $crate::storage::types::StoredObject; use $crate::storage::types::StoredObject;
#[allow(unused_imports)] #[allow(unused_imports)]
use $crate::storage::types::serde_helpers::{ use $crate::utils::serde_helpers::{
deserialize_flexible_id, serialize_datetime, deserialize_datetime, deserialize_flexible_id, serialize_datetime, deserialize_datetime,
serialize_option_datetime, deserialize_option_datetime, serialize_option_datetime, deserialize_option_datetime,
}; };
+1 -1
View File
@@ -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 serde::{Deserialize, Serialize};
use crate::{error::AppError, storage::db::SurrealDbClient, storage::types::StoredObject}; use crate::{error::AppError, storage::db::SurrealDbClient, storage::types::StoredObject};
+1
View File
@@ -1,4 +1,5 @@
pub mod config; pub mod config;
pub mod embedding; pub mod embedding;
pub mod ingest_limits; pub mod ingest_limits;
pub mod serde_helpers;
pub mod template_engine; pub mod template_engine;
+2 -6
View File
@@ -8,12 +8,8 @@ use axum::{
extract::{Query, State}, extract::{Query, State},
response::IntoResponse, response::IntoResponse,
}; };
use common::storage::types::{ use common::storage::types::{text_content::TextContent, user::User, StoredObject};
serde_helpers::deserialize_flexible_id, use common::utils::serde_helpers::deserialize_flexible_id;
text_content::TextContent,
user::User,
StoredObject,
};
use retrieval_pipeline::{RetrievalConfig, SearchResult, SearchTarget, StrategyOutput}; use retrieval_pipeline::{RetrievalConfig, SearchResult, SearchTarget, StrategyOutput};
use serde::{de, Deserialize, Deserializer, Serialize}; use serde::{de, Deserialize, Deserializer, Serialize};
use surrealdb::RecordId; use surrealdb::RecordId;
+12
View File
@@ -94,6 +94,7 @@ mod tests {
use anyhow::{self}; use anyhow::{self};
use async_openai::Client; use async_openai::Client;
use common::storage::indexes::ensure_runtime; use common::storage::indexes::ensure_runtime;
use common::storage::types::system_settings::SystemSettings;
use uuid::Uuid; use uuid::Uuid;
fn test_embedding() -> Vec<f32> { fn test_embedding() -> Vec<f32> {
@@ -108,6 +109,16 @@ mod tests {
vec![0.2, 0.8, 0.0] 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<SurrealDbClient> { async fn setup_test_db() -> anyhow::Result<SurrealDbClient> {
let namespace = "test_ns"; let namespace = "test_ns";
let database = &Uuid::new_v4().to_string(); let database = &Uuid::new_v4().to_string();
@@ -115,6 +126,7 @@ mod tests {
db.apply_migrations().await?; db.apply_migrations().await?;
configure_embedding_dimension(&db, 3).await?;
ensure_runtime(&db, 3).await?; ensure_runtime(&db, 3).await?;
Ok(db) Ok(db)