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
///
/// * `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::<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
/// * `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
///

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
}
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<f32> {
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()