From 572fb3a51d76d0e92d7e0841e770758757509106 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Wed, 27 Mar 2024 11:48:00 +0100 Subject: [PATCH] Finer granularity for embedder needs reindex --- milli/src/update/settings.rs | 7 ++++- milli/src/vector/settings.rs | 60 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 9f47768c1..b784b3f92 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -976,7 +976,12 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> { match joined { // updated config EitherOrBoth::Both((name, mut old), (_, new)) => { - changed |= old.apply(new); + changed |= EmbeddingSettings::apply_and_need_reindex(&mut old, new); + if changed { + tracing::debug!(embedder = name, "need reindex"); + } else { + tracing::debug!(embedder = name, "skip reindex"); + } let new = validate_embedding_settings(old, &name)?; new_configs.insert(name, new); } diff --git a/milli/src/vector/settings.rs b/milli/src/vector/settings.rs index 78f83cbea..18a86368f 100644 --- a/milli/src/vector/settings.rs +++ b/milli/src/vector/settings.rs @@ -210,6 +210,66 @@ impl EmbeddingSettings { *model = Setting::Set(openai::EmbeddingModel::default().name().to_owned()) } } + + pub(crate) fn apply_and_need_reindex( + old: &mut Setting, + new: Setting, + ) -> bool { + match (old, new) { + ( + Setting::Set(EmbeddingSettings { + source: old_source, + model: old_model, + revision: old_revision, + api_key: old_api_key, + dimensions: old_dimensions, + document_template: old_document_template, + url: old_url, + query: old_query, + input_field: old_input_field, + path_to_embeddings: old_path_to_embeddings, + embedding_object: old_embedding_object, + input_type: old_input_type, + distribution: old_distribution, + }), + Setting::Set(EmbeddingSettings { + source: new_source, + model: new_model, + revision: new_revision, + api_key: new_api_key, + dimensions: new_dimensions, + document_template: new_document_template, + url: new_url, + query: new_query, + input_field: new_input_field, + path_to_embeddings: new_path_to_embeddings, + embedding_object: new_embedding_object, + input_type: new_input_type, + distribution: new_distribution, + }), + ) => { + let mut needs_reindex = false; + + needs_reindex |= old_source.apply(new_source); + needs_reindex |= old_model.apply(new_model); + needs_reindex |= old_revision.apply(new_revision); + needs_reindex |= old_dimensions.apply(new_dimensions); + needs_reindex |= old_document_template.apply(new_document_template); + needs_reindex |= old_url.apply(new_url); + needs_reindex |= old_query.apply(new_query); + needs_reindex |= old_input_field.apply(new_input_field); + needs_reindex |= old_path_to_embeddings.apply(new_path_to_embeddings); + needs_reindex |= old_embedding_object.apply(new_embedding_object); + needs_reindex |= old_input_type.apply(new_input_type); + + old_distribution.apply(new_distribution); + old_api_key.apply(new_api_key); + needs_reindex + } + (Setting::Reset, Setting::Reset) | (_, Setting::NotSet) => false, + _ => true, + } + } } #[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, PartialEq, Eq, Deserr)]