diff --git a/crates/meilisearch-types/src/error.rs b/crates/meilisearch-types/src/error.rs index bdf9bb162..077600a8e 100644 --- a/crates/meilisearch-types/src/error.rs +++ b/crates/meilisearch-types/src/error.rs @@ -447,6 +447,7 @@ impl ErrorCode for milli::Error { | UserError::InvalidSettingsDimensions { .. } | UserError::InvalidUrl { .. } | UserError::InvalidSettingsDocumentTemplateMaxBytes { .. } + | UserError::InvalidChatSettingsDocumentTemplateMaxBytes | UserError::InvalidPrompt(_) | UserError::InvalidDisableBinaryQuantization { .. } | UserError::InvalidSourceForNested { .. } diff --git a/crates/milli/src/error.rs b/crates/milli/src/error.rs index e129a31a0..2136ec97e 100644 --- a/crates/milli/src/error.rs +++ b/crates/milli/src/error.rs @@ -386,6 +386,8 @@ and can not be more than 511 bytes.", .document_id.to_string() DocumentEditionRuntimeError(Box), #[error("Document edition runtime error encountered while compiling the function: {0}")] DocumentEditionCompilationError(rhai::ParseError), + #[error("`.chat.documentTemplateMaxBytes`: `documentTemplateMaxBytes` cannot be zero")] + InvalidChatSettingsDocumentTemplateMaxBytes, #[error("{0}")] DocumentEmbeddingError(String), } diff --git a/crates/milli/src/update/settings.rs b/crates/milli/src/update/settings.rs index ae46cb5d9..05607d7a5 100644 --- a/crates/milli/src/update/settings.rs +++ b/crates/milli/src/update/settings.rs @@ -19,7 +19,7 @@ use crate::attribute_patterns::PatternMatch; use crate::constants::RESERVED_GEO_FIELD_NAME; use crate::criterion::Criterion; use crate::disabled_typos_terms::DisabledTyposTerms; -use crate::error::UserError; +use crate::error::UserError::{self, InvalidChatSettingsDocumentTemplateMaxBytes}; use crate::fields_ids_map::metadata::{FieldIdMapWithMetadata, MetadataBuilder}; use crate::filterable_attributes_rules::match_faceted_field; use crate::index::{ @@ -1249,7 +1249,7 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> { Ok(()) } - fn update_chat_config(&mut self) -> heed::Result { + fn update_chat_config(&mut self) -> Result { match &mut self.chat { Setting::Set(ChatSettings { description: new_description, @@ -1273,7 +1273,10 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> { Setting::NotSet => prompt.template.clone(), }, max_bytes: match new_document_template_max_bytes { - Setting::Set(m) => NonZeroUsize::new(*m), + Setting::Set(m) => Some( + NonZeroUsize::new(*m) + .ok_or(InvalidChatSettingsDocumentTemplateMaxBytes)?, + ), Setting::Reset => Some(default_max_bytes()), Setting::NotSet => prompt.max_bytes, }, @@ -1347,7 +1350,7 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> { Ok(true) } - Setting::Reset => self.index.delete_chat_config(self.wtxn), + Setting::Reset => self.index.delete_chat_config(self.wtxn).map_err(Into::into), Setting::NotSet => Ok(false), } }