From b5da0cb409714dd3b098b58c6503432e753d3d7d Mon Sep 17 00:00:00 2001 From: Per Stark Date: Mon, 5 May 2025 09:27:26 +0200 Subject: [PATCH] chore: corrected error type and clippy satisfaction --- common/src/error.rs | 4 ++- common/src/storage/db.rs | 54 ++------------------------------ composite-retrieval/src/graph.rs | 2 +- 3 files changed, 7 insertions(+), 53 deletions(-) diff --git a/common/src/error.rs b/common/src/error.rs index 1b90b64..e5e7b32 100644 --- a/common/src/error.rs +++ b/common/src/error.rs @@ -31,8 +31,10 @@ pub enum AppError { Reqwest(#[from] reqwest::Error), #[error("Tiktoken error: {0}")] Tiktoken(#[from] anyhow::Error), - #[error("Ingress Processing error: {0}")] + #[error("Ingestion Processing error: {0}")] Processing(String), #[error("DOM smoothie error: {0}")] DomSmoothie(#[from] dom_smoothie::ReadabilityError), + #[error("Internal service error: {0}")] + InternalError(String), } diff --git a/common/src/storage/db.rs b/common/src/storage/db.rs index 1b9801b..0d3a574 100644 --- a/common/src/storage/db.rs +++ b/common/src/storage/db.rs @@ -1,4 +1,4 @@ -use super::types::{analytics::Analytics, system_settings::SystemSettings, StoredObject}; +use super::types::StoredObject; use crate::error::AppError; use axum_session::{SessionConfig, SessionError, SessionStore}; use axum_session_surreal::SessionSurrealPool; @@ -65,72 +65,24 @@ impl SurrealDbClient { /// the database and selecting the appropriate namespace and database, but before /// the application starts performing operations that rely on the schema. pub async fn apply_migrations(&self) -> Result<(), AppError> { - // Instantiate the runner, load embedded files, and run 'up' MigrationRunner::new(&self.client) .load_files(&MIGRATIONS_DIR) .up() .await - .map_err(|e| AppError::Processing(e.to_string()))?; + .map_err(|e| AppError::InternalError(e.to_string()))?; Ok(()) } - // pub async fn ensure_initialized(&self) -> Result<(), AppError> { - // Self::build_indexes(self).await?; - // Self::setup_auth(self).await?; - - // Analytics::ensure_initialized(self).await?; - // SystemSettings::ensure_initialized(self).await?; - - // Ok(()) - // } - - // pub async fn setup_auth(&self) -> Result<(), Error> { - // self.client.query( - // "DEFINE TABLE user SCHEMALESS; - // DEFINE INDEX unique_name ON TABLE user FIELDS email UNIQUE; - // DEFINE ACCESS account ON DATABASE TYPE RECORD - // SIGNUP ( CREATE user SET email = $email, password = crypto::argon2::generate($password), anonymous = false, user_id = $user_id) - // SIGNIN ( SELECT * FROM user WHERE email = $email AND crypto::argon2::compare(password, $password) );", - // ) - // .await?; - // Ok(()) - // } - - // pub async fn build_indexes(&self) -> Result<(), Error> { - // self.client.query("DEFINE INDEX idx_embedding_chunks ON text_chunk FIELDS embedding HNSW DIMENSION 1536").await?; - // self.client.query("DEFINE INDEX idx_embedding_entities ON knowledge_entity FIELDS embedding HNSW DIMENSION 1536").await?; - - // self.client - // .query("DEFINE INDEX idx_job_status ON job FIELDS status") - // .await?; - // self.client - // .query("DEFINE INDEX idx_job_user ON job FIELDS user_id") - // .await?; - // self.client - // .query("DEFINE INDEX idx_job_created ON job FIELDS created_at") - // .await?; - - // Ok(()) - // } - + /// Operation to rebuild indexes pub async fn rebuild_indexes(&self) -> Result<(), Error> { self.client .query("REBUILD INDEX IF EXISTS idx_embedding_chunks ON text_chunk") - .await?; - self.client .query("REBUILD INDEX IF EXISTS idx_embeddings_entities ON knowledge_entity") .await?; Ok(()) } - pub async fn drop_table(&self) -> Result, Error> - where - T: StoredObject + Send + Sync + 'static, - { - self.client.delete(T::table_name()).await - } - /// Operation to store a object in SurrealDB, requires the struct to implement StoredObject /// /// # Arguments diff --git a/composite-retrieval/src/graph.rs b/composite-retrieval/src/graph.rs index 89c9a63..fa22ba4 100644 --- a/composite-retrieval/src/graph.rs +++ b/composite-retrieval/src/graph.rs @@ -292,7 +292,7 @@ mod tests { .await .expect("Failed to store related entity 2") .unwrap(); - let unrelated_entity = db + let _unrelated_entity = db .store_item(unrelated_entity.clone()) .await .expect("Failed to store unrelated entity")