chore: clippy composite retrieval

This commit is contained in:
Per Stark
2025-10-16 20:37:51 +02:00
parent 3c97d8ead5
commit 21e4ab1f42
3 changed files with 19 additions and 20 deletions

View File

@@ -42,8 +42,8 @@ pub struct LLMResponseFormat {
/// ///
/// # Arguments /// # Arguments
/// ///
/// * `surreal_db_client` - Client for SurrealDB interactions /// * `surreal_db_client` - Client for `SurrealDB` interactions
/// * `openai_client` - Client for OpenAI API calls /// * `openai_client` - Client for `OpenAI` API calls
/// * `query` - The user's query string /// * `query` - The user's query string
/// * `user_id` - The user's id /// * `user_id` - The user's id
/// ///
@@ -106,20 +106,19 @@ pub fn format_entities_json(entities: &[RetrievedEntity]) -> Value {
} }
fn round_score(value: f32) -> f64 { 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 { pub fn create_user_message(entities_json: &Value, query: &str) -> String {
format!( format!(
r#" r"
Context Information: Context Information:
================== ==================
{} {entities_json}
User Question: User Question:
================== ==================
{} {query}
"#, "
entities_json, query
) )
} }
@@ -129,7 +128,7 @@ pub fn create_user_message_with_history(
query: &str, query: &str,
) -> String { ) -> String {
format!( format!(
r#" r"
Chat history: Chat history:
================== ==================
{} {}
@@ -141,7 +140,7 @@ pub fn create_user_message_with_history(
User Question: User Question:
================== ==================
{} {}
"#, ",
format_history(history), format_history(history),
entities_json, entities_json,
query query
@@ -183,7 +182,7 @@ pub async fn process_llm_response(
)) ))
.and_then(|content| { .and_then(|content| {
serde_json::from_str::<LLMResponseFormat>(content).map_err(|e| { serde_json::from_str::<LLMResponseFormat>(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}"))
}) })
}) })
} }

View File

@@ -20,7 +20,7 @@ use common::storage::{
/// ///
/// * `source_id` - The identifier to search for in the database /// * `source_id` - The identifier to search for in the database
/// * `table_name` - The name of the table to search in /// * `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 /// # Type Parameters
/// ///

View File

@@ -27,22 +27,22 @@ impl<T> Scored<T> {
} }
} }
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.scores.vector = Some(score);
self 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.scores.fts = Some(score);
self 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.scores.graph = Some(score);
self self
} }
pub fn update_fused(&mut self, fused: f32) { pub const fn update_fused(&mut self, fused: f32) {
self.fused = fused; 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) value.clamp(0.0, 1.0)
} }
@@ -109,10 +109,10 @@ pub fn min_max_normalize(scores: &[f32]) -> Vec<f32> {
scores scores
.iter() .iter()
.map(|score| { .map(|score| {
if !score.is_finite() { if score.is_finite() {
0.0
} else {
clamp_unit((score - min) / (max - min)) clamp_unit((score - min) / (max - min))
} else {
0.0
} }
}) })
.collect() .collect()