diff --git a/crates/meilisearch/src/routes/chats/chat_completions.rs b/crates/meilisearch/src/routes/chats/chat_completions.rs index ed8df3c8b..01e22d6f8 100644 --- a/crates/meilisearch/src/routes/chats/chat_completions.rs +++ b/crates/meilisearch/src/routes/chats/chat_completions.rs @@ -119,7 +119,7 @@ fn setup_search_tool( prompts: &DbChatCompletionPrompts, ) -> Result { let tools = chat_completion.tools.get_or_insert_default(); - if tools.iter().find(|t| t.function.name == MEILI_SEARCH_IN_INDEX_FUNCTION_NAME).is_some() { + if tools.iter().any(|t| t.function.name == MEILI_SEARCH_IN_INDEX_FUNCTION_NAME) { panic!("{MEILI_SEARCH_IN_INDEX_FUNCTION_NAME} function already set"); } @@ -149,7 +149,7 @@ fn setup_search_tool( let mut function_description = prompts.search_description.clone(); index_scheduler.try_for_each_index::<_, ()>(|name, index| { // Make sure to skip unauthorized indexes - if !filters.is_index_authorized(&name) { + if !filters.is_index_authorized(name) { return Ok(()); } @@ -350,7 +350,7 @@ async fn non_streamed_chat( &index_scheduler, auth_ctrl.clone(), &search_queue, - &auth_token, + auth_token, index_uid, q, ) @@ -461,6 +461,7 @@ async fn streamed_chat( /// Updates the chat completion with the new messages, streams the LLM tokens, /// and report progress and errors. +#[allow(clippy::too_many_arguments)] async fn run_conversation( index_scheduler: &GuardedData, Data>, auth_ctrl: &web::Data, @@ -515,7 +516,7 @@ async fn run_conversation( } }); - if global_tool_calls.get(index).map_or(false, Call::is_external) { + if global_tool_calls.get(index).is_some_and(Call::is_external) { todo!("Support forwarding external tool calls"); } } @@ -553,10 +554,10 @@ async fn run_conversation( ); handle_meili_tools( - &index_scheduler, - &auth_ctrl, - &search_queue, - &auth_token, + index_scheduler, + auth_ctrl, + search_queue, + auth_token, chat_settings, tx, meili_calls, @@ -586,6 +587,7 @@ async fn run_conversation( } } +#[allow(clippy::too_many_arguments)] async fn handle_meili_tools( index_scheduler: &GuardedData, Data>, auth_ctrl: &web::Data, @@ -621,10 +623,10 @@ async fn handle_meili_tools( let result = match serde_json::from_str(&call.function.arguments) { Ok(SearchInIndexParameters { index_uid, q }) => process_search_request( - &index_scheduler, + index_scheduler, auth_ctrl.clone(), - &search_queue, - &auth_token, + search_queue, + auth_token, index_uid, q, ) diff --git a/crates/meilisearch/src/routes/chats/settings.rs b/crates/meilisearch/src/routes/chats/settings.rs index e118a3ef1..a87fbed70 100644 --- a/crates/meilisearch/src/routes/chats/settings.rs +++ b/crates/meilisearch/src/routes/chats/settings.rs @@ -16,12 +16,11 @@ use meilisearch_types::milli::update::Setting; use serde::{Deserialize, Serialize}; use utoipa::ToSchema; +use super::ChatsParam; use crate::extractors::authentication::policies::ActionPolicy; use crate::extractors::authentication::GuardedData; use crate::extractors::sequential_extractor::SeqHandler; -use super::ChatsParam; - pub fn configure(cfg: &mut web::ServiceConfig) { cfg.service( web::resource("") @@ -70,8 +69,7 @@ async fn patch_settings( // TODO do a spawn_blocking here let mut wtxn = index_scheduler.write_txn()?; - let old_settings = - index_scheduler.chat_settings(&mut wtxn, &workspace_uid)?.unwrap_or_default(); + let old_settings = index_scheduler.chat_settings(&wtxn, &workspace_uid)?.unwrap_or_default(); let prompts = match new.prompts { Setting::Set(new_prompts) => DbChatCompletionPrompts { diff --git a/crates/meilisearch/src/routes/chats/utils.rs b/crates/meilisearch/src/routes/chats/utils.rs index 424b4ea64..b29747bc9 100644 --- a/crates/meilisearch/src/routes/chats/utils.rs +++ b/crates/meilisearch/src/routes/chats/utils.rs @@ -208,8 +208,8 @@ impl SseEventSender { /// Format documents based on the provided template and maximum bytes. /// /// This formatting function is usually used to generate a summary of the documents for LLMs. -pub fn format_documents<'t, 'doc>( - rtxn: &RoTxn<'t>, +pub fn format_documents<'doc>( + rtxn: &RoTxn<'_>, index: &Index, doc_alloc: &'doc Bump, internal_docids: Vec, diff --git a/crates/meilisearch/src/search/mod.rs b/crates/meilisearch/src/search/mod.rs index 037083b2d..27369591b 100644 --- a/crates/meilisearch/src/search/mod.rs +++ b/crates/meilisearch/src/search/mod.rs @@ -204,7 +204,7 @@ impl std::convert::TryFrom for RankingScoreThreshold { impl From for RankingScoreThreshold { fn from(threshold: index::RankingScoreThreshold) -> Self { let threshold = threshold.as_f64(); - assert!(threshold >= 0.0 && threshold <= 1.0); + assert!((0.0..=1.0).contains(&threshold)); RankingScoreThreshold(threshold) } } diff --git a/crates/milli/src/index.rs b/crates/milli/src/index.rs index b2df46af3..6ff972ae0 100644 --- a/crates/milli/src/index.rs +++ b/crates/milli/src/index.rs @@ -1984,7 +1984,7 @@ impl TryFrom for RankingScoreThreshold { type Error = InvalidSearchRankingScoreThreshold; fn try_from(value: f64) -> StdResult { - if value < 0.0 || value > 1.0 { + if !(0.0..=1.0).contains(&value) { Err(InvalidSearchRankingScoreThreshold) } else { Ok(RankingScoreThreshold(value)) diff --git a/crates/milli/src/update/chat.rs b/crates/milli/src/update/chat.rs index ae95ddfd9..c52ede029 100644 --- a/crates/milli/src/update/chat.rs +++ b/crates/milli/src/update/chat.rs @@ -69,11 +69,6 @@ impl From for ChatSettings { HybridQuery { semantic_ratio: SemanticRatio(semantic_ratio), embedder } }); - let matching_strategy = matching_strategy.map(MatchingStrategy::from); - - let ranking_score_threshold = - ranking_score_threshold.map(RankingScoreThreshold::from); - ChatSearchParams { hybrid: Setting::some_or_not_set(hybrid), limit: Setting::some_or_not_set(limit), diff --git a/crates/milli/src/update/settings.rs b/crates/milli/src/update/settings.rs index 9f152710a..0e44654a5 100644 --- a/crates/milli/src/update/settings.rs +++ b/crates/milli/src/update/settings.rs @@ -23,7 +23,7 @@ use crate::error::UserError; use crate::fields_ids_map::metadata::{FieldIdMapWithMetadata, MetadataBuilder}; use crate::filterable_attributes_rules::match_faceted_field; use crate::index::{ - ChatConfig, IndexEmbeddingConfig, MatchingStrategy, PrefixSearch, RankingScoreThreshold, + ChatConfig, IndexEmbeddingConfig, PrefixSearch, SearchParameters, DEFAULT_MIN_WORD_LEN_ONE_TYPO, DEFAULT_MIN_WORD_LEN_TWO_TYPOS, }; use crate::order_by_map::OrderByMap; @@ -1326,7 +1326,7 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> { }, matching_strategy: match matching_strategy { Setting::Set(matching_strategy) => { - Some(MatchingStrategy::from(*matching_strategy)) + Some(*matching_strategy) } Setting::Reset => None, Setting::NotSet => search_parameters.matching_strategy, @@ -1341,7 +1341,7 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> { } }, ranking_score_threshold: match ranking_score_threshold { - Setting::Set(rst) => Some(RankingScoreThreshold::from(*rst)), + Setting::Set(rst) => Some(*rst), Setting::Reset => None, Setting::NotSet => search_parameters.ranking_score_threshold, },