Introduce a new executeAfterUpdate index setting

This commit is contained in:
Clément Renault
2025-04-16 22:50:33 +02:00
committed by Kerollmops
parent 84cf389354
commit 128a4629f9
9 changed files with 108 additions and 2 deletions

View File

@@ -84,6 +84,7 @@ pub mod main_key {
pub const SEARCH_CUTOFF: &str = "search_cutoff";
pub const LOCALIZED_ATTRIBUTES_RULES: &str = "localized_attributes_rules";
pub const FACET_SEARCH: &str = "facet_search";
pub const EXECUTE_AFTER_UPDATE: &str = "execute-after-update";
pub const PREFIX_SEARCH: &str = "prefix_search";
pub const DOCUMENTS_STATS: &str = "documents_stats";
pub const DISABLED_TYPOS_TERMS: &str = "disabled_typos_terms";
@@ -1761,6 +1762,22 @@ impl Index {
self.main.remap_key_type::<Str>().delete(txn, main_key::CHAT)
}
pub fn execute_after_update<'t>(&self, txn: &'t RoTxn<'_>) -> heed::Result<Option<&'t str>> {
self.main.remap_types::<Str, Str>().get(txn, main_key::EXECUTE_AFTER_UPDATE)
}
pub(crate) fn put_execute_after_update(
&self,
txn: &mut RwTxn<'_>,
val: &str,
) -> heed::Result<()> {
self.main.remap_types::<Str, Str>().put(txn, main_key::EXECUTE_AFTER_UPDATE, &val)
}
pub(crate) fn delete_execute_after_update(&self, txn: &mut RwTxn<'_>) -> heed::Result<bool> {
self.main.remap_key_type::<Str>().delete(txn, main_key::EXECUTE_AFTER_UPDATE)
}
pub fn localized_attributes_rules(
&self,
rtxn: &RoTxn<'_>,

View File

@@ -202,6 +202,7 @@ pub struct Settings<'a, 't, 'i> {
facet_search: Setting<bool>,
chat: Setting<ChatSettings>,
vector_store: Setting<VectorStoreBackend>,
execute_after_update: Setting<String>,
}
impl<'a, 't, 'i> Settings<'a, 't, 'i> {
@@ -242,6 +243,7 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> {
facet_search: Setting::NotSet,
chat: Setting::NotSet,
vector_store: Setting::NotSet,
execute_after_update: Setting::NotSet,
indexer_config,
}
}
@@ -488,6 +490,14 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> {
self.vector_store = Setting::Reset;
}
pub fn set_execute_after_update(&mut self, value: String) {
self.execute_after_update = Setting::Set(value);
}
pub fn reset_execute_after_update(&mut self) {
self.execute_after_update = Setting::Reset;
}
#[tracing::instrument(
level = "trace"
skip(self, progress_callback, should_abort, settings_diff, embedder_stats),
@@ -1059,6 +1069,18 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> {
Ok(changed)
}
fn update_execute_after_update(&mut self) -> Result<()> {
match self.execute_after_update.as_ref() {
Setting::Set(new) => {
self.index.put_execute_after_update(self.wtxn, &new).map_err(Into::into)
}
Setting::Reset => {
self.index.delete_execute_after_update(self.wtxn).map(drop).map_err(Into::into)
}
Setting::NotSet => Ok(()),
}
}
fn update_embedding_configs(&mut self) -> Result<BTreeMap<String, EmbedderAction>> {
match std::mem::take(&mut self.embedder_settings) {
Setting::Set(configs) => self.update_embedding_configs_set(configs),
@@ -1469,6 +1491,7 @@ impl<'a, 't, 'i> Settings<'a, 't, 'i> {
self.update_proximity_precision()?;
self.update_prefix_search()?;
self.update_facet_search()?;
self.update_execute_after_update()?;
self.update_localized_attributes_rules()?;
self.update_disabled_typos_terms()?;
self.update_chat_config()?;

View File

@@ -899,6 +899,7 @@ fn test_correct_settings_init() {
disable_on_numbers,
chat,
vector_store,
execute_after_update,
} = settings;
assert!(matches!(searchable_fields, Setting::NotSet));
assert!(matches!(displayed_fields, Setting::NotSet));
@@ -929,6 +930,7 @@ fn test_correct_settings_init() {
assert!(matches!(disable_on_numbers, Setting::NotSet));
assert!(matches!(chat, Setting::NotSet));
assert!(matches!(vector_store, Setting::NotSet));
assert!(matches!(execute_after_update, Setting::NotSet));
})
.unwrap();
}