mirror of
				https://github.com/meilisearch/meilisearch.git
				synced 2025-10-31 16:06:31 +00:00 
			
		
		
		
	Merge #4600
4600: Fix embedders api r=ManyTheFish a=ManyTheFish # Pull Request ## Related issue Fixes #4594 Fixes #4595 Co-authored-by: ManyTheFish <many@meilisearch.com>
This commit is contained in:
		| @@ -256,8 +256,8 @@ pub(crate) mod test { | ||||
|  | ||||
|     pub fn create_test_settings() -> Settings<Checked> { | ||||
|         let settings = Settings { | ||||
|             displayed_attributes: Setting::Set(vec![S("race"), S("name")]), | ||||
|             searchable_attributes: Setting::Set(vec![S("name"), S("race")]), | ||||
|             displayed_attributes: Setting::Set(vec![S("race"), S("name")]).into(), | ||||
|             searchable_attributes: Setting::Set(vec![S("name"), S("race")]).into(), | ||||
|             filterable_attributes: Setting::Set(btreeset! { S("race"), S("age") }), | ||||
|             sortable_attributes: Setting::Set(btreeset! { S("age") }), | ||||
|             ranking_rules: Setting::NotSet, | ||||
|   | ||||
| @@ -315,8 +315,8 @@ impl From<v5::ResponseError> for v6::ResponseError { | ||||
| impl<T> From<v5::Settings<T>> for v6::Settings<v6::Unchecked> { | ||||
|     fn from(settings: v5::Settings<T>) -> Self { | ||||
|         v6::Settings { | ||||
|             displayed_attributes: settings.displayed_attributes.into(), | ||||
|             searchable_attributes: settings.searchable_attributes.into(), | ||||
|             displayed_attributes: v6::Setting::from(settings.displayed_attributes).into(), | ||||
|             searchable_attributes: v6::Setting::from(settings.searchable_attributes).into(), | ||||
|             filterable_attributes: settings.filterable_attributes.into(), | ||||
|             sortable_attributes: settings.sortable_attributes.into(), | ||||
|             ranking_rules: { | ||||
|   | ||||
| @@ -6,7 +6,7 @@ source: index-scheduler/src/lib.rs | ||||
| [] | ||||
| ---------------------------------------------------------------------- | ||||
| ### All Tasks: | ||||
| 0 {uid: 0, status: enqueued, details: { settings: Settings { displayed_attributes: NotSet, searchable_attributes: NotSet, filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> } }, kind: SettingsUpdate { index_uid: "doggos", new_settings: Settings { displayed_attributes: NotSet, searchable_attributes: NotSet, filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> }, is_deletion: false, allow_index_creation: true }} | ||||
| 0 {uid: 0, status: enqueued, details: { settings: Settings { displayed_attributes: WildcardSetting(NotSet), searchable_attributes: WildcardSetting(NotSet), filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> } }, kind: SettingsUpdate { index_uid: "doggos", new_settings: Settings { displayed_attributes: WildcardSetting(NotSet), searchable_attributes: WildcardSetting(NotSet), filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> }, is_deletion: false, allow_index_creation: true }} | ||||
| ---------------------------------------------------------------------- | ||||
| ### Status: | ||||
| enqueued [0,] | ||||
|   | ||||
| @@ -6,7 +6,7 @@ source: index-scheduler/src/lib.rs | ||||
| [] | ||||
| ---------------------------------------------------------------------- | ||||
| ### All Tasks: | ||||
| 0 {uid: 0, status: succeeded, details: { settings: Settings { displayed_attributes: NotSet, searchable_attributes: NotSet, filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> } }, kind: SettingsUpdate { index_uid: "doggos", new_settings: Settings { displayed_attributes: NotSet, searchable_attributes: NotSet, filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> }, is_deletion: false, allow_index_creation: true }} | ||||
| 0 {uid: 0, status: succeeded, details: { settings: Settings { displayed_attributes: WildcardSetting(NotSet), searchable_attributes: WildcardSetting(NotSet), filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> } }, kind: SettingsUpdate { index_uid: "doggos", new_settings: Settings { displayed_attributes: WildcardSetting(NotSet), searchable_attributes: WildcardSetting(NotSet), filterable_attributes: NotSet, sortable_attributes: NotSet, ranking_rules: NotSet, stop_words: NotSet, non_separator_tokens: NotSet, separator_tokens: NotSet, dictionary: NotSet, synonyms: NotSet, distinct_attribute: NotSet, proximity_precision: NotSet, typo_tolerance: NotSet, faceting: NotSet, pagination: NotSet, embedders: Set({"default": Set(EmbeddingSettings { source: Set(Rest), model: NotSet, revision: NotSet, api_key: Set("My super secret"), dimensions: Set(4), document_template: NotSet, url: Set("http://localhost:7777"), query: NotSet, input_field: NotSet, path_to_embeddings: NotSet, embedding_object: NotSet, input_type: NotSet, distribution: NotSet })}), search_cutoff_ms: NotSet, _kind: PhantomData<meilisearch_types::settings::Unchecked> }, is_deletion: false, allow_index_creation: true }} | ||||
| ---------------------------------------------------------------------- | ||||
| ### Status: | ||||
| enqueued [] | ||||
|   | ||||
| @@ -3,7 +3,7 @@ use std::convert::Infallible; | ||||
| use std::fmt; | ||||
| use std::marker::PhantomData; | ||||
| use std::num::NonZeroUsize; | ||||
| use std::ops::ControlFlow; | ||||
| use std::ops::{ControlFlow, Deref}; | ||||
| use std::str::FromStr; | ||||
|  | ||||
| use deserr::{DeserializeError, Deserr, ErrorKind, MergeWithError, ValuePointerRef}; | ||||
| @@ -143,21 +143,13 @@ impl MergeWithError<milli::CriterionError> for DeserrJsonError<InvalidSettingsRa | ||||
| )] | ||||
| #[deserr(error = DeserrJsonError, rename_all = camelCase, deny_unknown_fields)] | ||||
| pub struct Settings<T> { | ||||
|     #[serde( | ||||
|         default, | ||||
|         serialize_with = "serialize_with_wildcard", | ||||
|         skip_serializing_if = "Setting::is_not_set" | ||||
|     )] | ||||
|     #[serde(default, skip_serializing_if = "Setting::is_not_set")] | ||||
|     #[deserr(default, error = DeserrJsonError<InvalidSettingsDisplayedAttributes>)] | ||||
|     pub displayed_attributes: Setting<Vec<String>>, | ||||
|     pub displayed_attributes: WildcardSetting, | ||||
|  | ||||
|     #[serde( | ||||
|         default, | ||||
|         serialize_with = "serialize_with_wildcard", | ||||
|         skip_serializing_if = "Setting::is_not_set" | ||||
|     )] | ||||
|     #[serde(default, skip_serializing_if = "Setting::is_not_set")] | ||||
|     #[deserr(default, error = DeserrJsonError<InvalidSettingsSearchableAttributes>)] | ||||
|     pub searchable_attributes: Setting<Vec<String>>, | ||||
|     pub searchable_attributes: WildcardSetting, | ||||
|  | ||||
|     #[serde(default, skip_serializing_if = "Setting::is_not_set")] | ||||
|     #[deserr(default, error = DeserrJsonError<InvalidSettingsFilterableAttributes>)] | ||||
| @@ -251,8 +243,8 @@ impl<T> Settings<T> { | ||||
| impl Settings<Checked> { | ||||
|     pub fn cleared() -> Settings<Checked> { | ||||
|         Settings { | ||||
|             displayed_attributes: Setting::Reset, | ||||
|             searchable_attributes: Setting::Reset, | ||||
|             displayed_attributes: Setting::Reset.into(), | ||||
|             searchable_attributes: Setting::Reset.into(), | ||||
|             filterable_attributes: Setting::Reset, | ||||
|             sortable_attributes: Setting::Reset, | ||||
|             ranking_rules: Setting::Reset, | ||||
| @@ -319,7 +311,7 @@ impl Settings<Checked> { | ||||
|  | ||||
| impl Settings<Unchecked> { | ||||
|     pub fn check(self) -> Settings<Checked> { | ||||
|         let displayed_attributes = match self.displayed_attributes { | ||||
|         let displayed_attributes = match self.displayed_attributes.0 { | ||||
|             Setting::Set(fields) => { | ||||
|                 if fields.iter().any(|f| f == "*") { | ||||
|                     Setting::Reset | ||||
| @@ -330,7 +322,7 @@ impl Settings<Unchecked> { | ||||
|             otherwise => otherwise, | ||||
|         }; | ||||
|  | ||||
|         let searchable_attributes = match self.searchable_attributes { | ||||
|         let searchable_attributes = match self.searchable_attributes.0 { | ||||
|             Setting::Set(fields) => { | ||||
|                 if fields.iter().any(|f| f == "*") { | ||||
|                     Setting::Reset | ||||
| @@ -342,8 +334,8 @@ impl Settings<Unchecked> { | ||||
|         }; | ||||
|  | ||||
|         Settings { | ||||
|             displayed_attributes, | ||||
|             searchable_attributes, | ||||
|             displayed_attributes: displayed_attributes.into(), | ||||
|             searchable_attributes: searchable_attributes.into(), | ||||
|             filterable_attributes: self.filterable_attributes, | ||||
|             sortable_attributes: self.sortable_attributes, | ||||
|             ranking_rules: self.ranking_rules, | ||||
| @@ -412,13 +404,13 @@ pub fn apply_settings_to_builder( | ||||
|         _kind, | ||||
|     } = settings; | ||||
|  | ||||
|     match searchable_attributes { | ||||
|     match searchable_attributes.deref() { | ||||
|         Setting::Set(ref names) => builder.set_searchable_fields(names.clone()), | ||||
|         Setting::Reset => builder.reset_searchable_fields(), | ||||
|         Setting::NotSet => (), | ||||
|     } | ||||
|  | ||||
|     match displayed_attributes { | ||||
|     match displayed_attributes.deref() { | ||||
|         Setting::Set(ref names) => builder.set_displayed_fields(names.clone()), | ||||
|         Setting::Reset => builder.reset_displayed_fields(), | ||||
|         Setting::NotSet => (), | ||||
| @@ -690,11 +682,13 @@ pub fn settings( | ||||
|         displayed_attributes: match displayed_attributes { | ||||
|             Some(attrs) => Setting::Set(attrs), | ||||
|             None => Setting::Reset, | ||||
|         }, | ||||
|         } | ||||
|         .into(), | ||||
|         searchable_attributes: match searchable_attributes { | ||||
|             Some(attrs) => Setting::Set(attrs), | ||||
|             None => Setting::Reset, | ||||
|         }, | ||||
|         } | ||||
|         .into(), | ||||
|         filterable_attributes: Setting::Set(filterable_attributes), | ||||
|         sortable_attributes: Setting::Set(sortable_attributes), | ||||
|         ranking_rules: Setting::Set(criteria.iter().map(|c| c.clone().into()).collect()), | ||||
| @@ -848,6 +842,41 @@ impl From<ProximityPrecisionView> for ProximityPrecision { | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[derive(Debug, Clone, Default, Deserialize, PartialEq, Eq)] | ||||
| pub struct WildcardSetting(Setting<Vec<String>>); | ||||
|  | ||||
| impl From<Setting<Vec<String>>> for WildcardSetting { | ||||
|     fn from(setting: Setting<Vec<String>>) -> Self { | ||||
|         Self(setting) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl Serialize for WildcardSetting { | ||||
|     fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||||
|     where | ||||
|         S: Serializer, | ||||
|     { | ||||
|         serialize_with_wildcard(&self.0, serializer) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl<E: deserr::DeserializeError> Deserr<E> for WildcardSetting { | ||||
|     fn deserialize_from_value<V: deserr::IntoValue>( | ||||
|         value: deserr::Value<V>, | ||||
|         location: ValuePointerRef<'_>, | ||||
|     ) -> Result<Self, E> { | ||||
|         Ok(Self(Setting::deserialize_from_value(value, location)?)) | ||||
|     } | ||||
| } | ||||
|  | ||||
| impl std::ops::Deref for WildcardSetting { | ||||
|     type Target = Setting<Vec<String>>; | ||||
|  | ||||
|     fn deref(&self) -> &Self::Target { | ||||
|         &self.0 | ||||
|     } | ||||
| } | ||||
|  | ||||
| #[cfg(test)] | ||||
| pub(crate) mod test { | ||||
|     use super::*; | ||||
| @@ -856,8 +885,8 @@ pub(crate) mod test { | ||||
|     fn test_setting_check() { | ||||
|         // test no changes | ||||
|         let settings = Settings { | ||||
|             displayed_attributes: Setting::Set(vec![String::from("hello")]), | ||||
|             searchable_attributes: Setting::Set(vec![String::from("hello")]), | ||||
|             displayed_attributes: Setting::Set(vec![String::from("hello")]).into(), | ||||
|             searchable_attributes: Setting::Set(vec![String::from("hello")]).into(), | ||||
|             filterable_attributes: Setting::NotSet, | ||||
|             sortable_attributes: Setting::NotSet, | ||||
|             ranking_rules: Setting::NotSet, | ||||
| @@ -883,8 +912,9 @@ pub(crate) mod test { | ||||
|         // test wildcard | ||||
|         // test no changes | ||||
|         let settings = Settings { | ||||
|             displayed_attributes: Setting::Set(vec![String::from("*")]), | ||||
|             searchable_attributes: Setting::Set(vec![String::from("hello"), String::from("*")]), | ||||
|             displayed_attributes: Setting::Set(vec![String::from("*")]).into(), | ||||
|             searchable_attributes: Setting::Set(vec![String::from("hello"), String::from("*")]) | ||||
|                 .into(), | ||||
|             filterable_attributes: Setting::NotSet, | ||||
|             sortable_attributes: Setting::NotSet, | ||||
|             ranking_rules: Setting::NotSet, | ||||
| @@ -904,7 +934,7 @@ pub(crate) mod test { | ||||
|         }; | ||||
|  | ||||
|         let checked = settings.check(); | ||||
|         assert_eq!(checked.displayed_attributes, Setting::Reset); | ||||
|         assert_eq!(checked.searchable_attributes, Setting::Reset); | ||||
|         assert_eq!(checked.displayed_attributes, Setting::Reset.into()); | ||||
|         assert_eq!(checked.searchable_attributes, Setting::Reset.into()); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -137,10 +137,8 @@ macro_rules! make_setting_route { | ||||
|                 let settings = settings(&index, &rtxn, meilisearch_types::settings::SecretPolicy::HideSecrets)?; | ||||
|  | ||||
|                 debug!(returns = ?settings, "Update settings"); | ||||
|                 let mut json = serde_json::json!(&settings); | ||||
|                 let val = json[$camelcase_attr].take(); | ||||
|  | ||||
|                 Ok(HttpResponse::Ok().json(val)) | ||||
|                 Ok(HttpResponse::Ok().json(settings.$attr)) | ||||
|             } | ||||
|  | ||||
|             pub fn resources() -> Resource { | ||||
|   | ||||
| @@ -335,7 +335,7 @@ impl From<EmbeddingConfig> for EmbeddingSettings { | ||||
|                 source: Setting::Set(EmbedderSource::Ollama), | ||||
|                 model: Setting::Set(options.embedding_model.to_owned()), | ||||
|                 revision: Setting::NotSet, | ||||
|                 api_key: Setting::NotSet, | ||||
|                 api_key: options.api_key.map(Setting::Set).unwrap_or_default(), | ||||
|                 dimensions: Setting::NotSet, | ||||
|                 document_template: Setting::Set(prompt.template), | ||||
|                 url: Setting::NotSet, | ||||
|   | ||||
		Reference in New Issue
	
	Block a user