From 21e4ab1f424d3ef8a788a38ae00889e00a1b6005 Mon Sep 17 00:00:00 2001 From: Per Stark Date: Thu, 16 Oct 2025 20:37:51 +0200 Subject: [PATCH] chore: clippy composite retrieval --- composite-retrieval/src/answer_retrieval.rs | 21 ++++++++++----------- composite-retrieval/src/graph.rs | 2 +- composite-retrieval/src/scoring.rs | 16 ++++++++-------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/composite-retrieval/src/answer_retrieval.rs b/composite-retrieval/src/answer_retrieval.rs index 87c5c58..9c61149 100644 --- a/composite-retrieval/src/answer_retrieval.rs +++ b/composite-retrieval/src/answer_retrieval.rs @@ -42,8 +42,8 @@ pub struct LLMResponseFormat { /// /// # Arguments /// -/// * `surreal_db_client` - Client for SurrealDB interactions -/// * `openai_client` - Client for OpenAI API calls +/// * `surreal_db_client` - Client for `SurrealDB` interactions +/// * `openai_client` - Client for `OpenAI` API calls /// * `query` - The user's query string /// * `user_id` - The user's id /// @@ -106,20 +106,19 @@ pub fn format_entities_json(entities: &[RetrievedEntity]) -> Value { } fn round_score(value: f32) -> f64 { - ((value as f64) * 1000.0).round() / 1000.0 + (f64::from(value) * 1000.0).round() / 1000.0 } pub fn create_user_message(entities_json: &Value, query: &str) -> String { format!( - r#" + r" Context Information: ================== - {} + {entities_json} User Question: ================== - {} - "#, - entities_json, query + {query} + " ) } @@ -129,7 +128,7 @@ pub fn create_user_message_with_history( query: &str, ) -> String { format!( - r#" + r" Chat history: ================== {} @@ -141,7 +140,7 @@ pub fn create_user_message_with_history( User Question: ================== {} - "#, + ", format_history(history), entities_json, query @@ -183,7 +182,7 @@ pub async fn process_llm_response( )) .and_then(|content| { serde_json::from_str::(content).map_err(|e| { - AppError::LLMParsing(format!("Failed to parse LLM response into analysis: {}", e)) + AppError::LLMParsing(format!("Failed to parse LLM response into analysis: {e}")) }) }) } diff --git a/composite-retrieval/src/graph.rs b/composite-retrieval/src/graph.rs index 9eb740a..bf7ae37 100644 --- a/composite-retrieval/src/graph.rs +++ b/composite-retrieval/src/graph.rs @@ -20,7 +20,7 @@ use common::storage::{ /// /// * `source_id` - The identifier to search for in the database /// * `table_name` - The name of the table to search in -/// * `db_client` - The SurrealDB client instance for database operations +/// * `db_client` - The `SurrealDB` client instance for database operations /// /// # Type Parameters /// diff --git a/composite-retrieval/src/scoring.rs b/composite-retrieval/src/scoring.rs index 6862eef..560c086 100644 --- a/composite-retrieval/src/scoring.rs +++ b/composite-retrieval/src/scoring.rs @@ -27,22 +27,22 @@ impl Scored { } } - pub fn with_vector_score(mut self, score: f32) -> Self { + pub const fn with_vector_score(mut self, score: f32) -> Self { self.scores.vector = Some(score); self } - pub fn with_fts_score(mut self, score: f32) -> Self { + pub const fn with_fts_score(mut self, score: f32) -> Self { self.scores.fts = Some(score); self } - pub fn with_graph_score(mut self, score: f32) -> Self { + pub const fn with_graph_score(mut self, score: f32) -> Self { self.scores.graph = Some(score); self } - pub fn update_fused(&mut self, fused: f32) { + pub const fn update_fused(&mut self, fused: f32) { self.fused = fused; } } @@ -67,7 +67,7 @@ impl Default for FusionWeights { } } -pub fn clamp_unit(value: f32) -> f32 { +pub const fn clamp_unit(value: f32) -> f32 { value.clamp(0.0, 1.0) } @@ -109,10 +109,10 @@ pub fn min_max_normalize(scores: &[f32]) -> Vec { scores .iter() .map(|score| { - if !score.is_finite() { - 0.0 - } else { + if score.is_finite() { clamp_unit((score - min) / (max - min)) + } else { + 0.0 } }) .collect()