@@ -55,8 +55,9 @@ pub enum Embedder {
5555#[ serde( rename_all = "camelCase" ) ]
5656pub struct HuggingFaceEmbedderSettings {
5757 /// the BERT embedding model you want to use from HuggingFace
58- /// Example: `bge-base-en-v1.5`
59- pub model : String ,
58+ /// Defaults to `BAAI/bge-base-en-v1.5`
59+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
60+ pub model : Option < String > ,
6061 #[ serde( skip_serializing_if = "Option::is_none" ) ]
6162 pub revision : Option < String > ,
6263 /// if present, document_template must be a [Liquid template](https://shopify.github.io/liquid/).
@@ -77,9 +78,12 @@ pub struct OpenapiEmbedderSettings {
7778 /// Use [tier 2 keys](https://platform.openai.com/docs/guides/rate-limits/usage-tiers?context=tier-two) or above for optimal performance.
7879 pub api_key : String ,
7980 /// The openapi model name
80- /// Example: `text-embedding-ada-002`
81- pub model : String ,
82- pub dimensions : usize ,
81+ /// Default: `text-embedding-ada-002`
82+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
83+ pub model : Option < String > ,
84+ /// Defaults to the default for said model name
85+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
86+ pub dimensions : Option < usize > ,
8387 /// if present, document_template must be a [Liquid template](https://shopify.github.io/liquid/).
8488 /// Use `{{ doc.attribute }}` to access document field values.
8589 /// Meilisearch also exposes a `{{ fields }}` array containing one object per document field, which you may access with `{{ field.name }}` and `{{ field.value }}`.
@@ -836,6 +840,49 @@ impl<Http: HttpClient> Index<Http> {
836840 . await
837841 }
838842
843+ /// Get [embedders](https://www.meilisearch.com/docs/learn/experimental/vector_search) of the [Index].
844+ ///
845+ /// ```
846+ /// # use std::collections::HashMap;
847+ /// # use std::string::String;
848+ /// use meilisearch_sdk::{client::*, CustomEmbedderSettings, Embedder, ExperimentalFeatures, indexes::*, Settings};
849+ /// #
850+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
851+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
852+ /// #
853+ /// # futures::executor::block_on(async move {
854+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
855+ /// # client.create_index("get_embedders", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
856+ /// let index = client.index("get_embedders");
857+ ///
858+ /// # let mut features = ExperimentalFeatures::new(&client);
859+ /// # features.set_vector_store(true);
860+ /// # let res = features.update().await.unwrap();
861+ /// #
862+ /// # let t=index.set_settings(&Settings{
863+ /// # embedders:Some(HashMap::from([(String::from("default"),Embedder::UserProvided(CustomEmbedderSettings{dimensions:1}))])),
864+ /// # ..Settings::default()
865+ /// # }).await.unwrap();
866+ /// # t.wait_for_completion(&client, None, None).await.unwrap();
867+ /// let embedders = index.get_embedders().await.unwrap();
868+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
869+ /// # });
870+ /// ```
871+ #[ cfg( feature = "experimental-vector-search" ) ]
872+ pub async fn get_embedders ( & self ) -> Result < HashMap < String , Embedder > , Error > {
873+ request :: < ( ) , ( ) , Option < HashMap < String , Embedder > > > (
874+ & format ! (
875+ "{}/indexes/{}/settings/embedders" ,
876+ self . client. host, self . uid
877+ ) ,
878+ self . client . get_api_key ( ) ,
879+ Method :: Get { query : ( ) } ,
880+ 200 ,
881+ )
882+ . await
883+ . map ( |r| r. unwrap_or_default ( ) )
884+ }
885+
839886 /// Update [settings](../settings/struct.Settings) of the [Index].
840887 ///
841888 /// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged.
@@ -1891,6 +1938,39 @@ impl<Http: HttpClient> Index<Http> {
18911938 )
18921939 . await
18931940 }
1941+
1942+ /// Reset [embedders](https://www.meilisearch.com/docs/learn/experimental/vector_search) of the [Index].
1943+ ///
1944+ /// # Example
1945+ ///
1946+ /// ```
1947+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1948+ /// #
1949+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1950+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1951+ /// #
1952+ /// # futures::executor::block_on(async move {
1953+ /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
1954+ /// # client.create_index("reset_embedders", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1955+ /// let mut index = client.index("reset_embedders");
1956+ ///
1957+ /// let task = index.reset_embedders().await.unwrap();
1958+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1959+ /// # });
1960+ /// ```
1961+ #[ cfg( feature = "experimental-vector-search" ) ]
1962+ pub async fn reset_embedders ( & self ) -> Result < TaskInfo , Error > {
1963+ request :: < ( ) , ( ) , TaskInfo > (
1964+ & format ! (
1965+ "{}/indexes/{}/settings/embedders" ,
1966+ self . client. host, self . uid
1967+ ) ,
1968+ self . client . get_api_key ( ) ,
1969+ Method :: Delete { query : ( ) } ,
1970+ 202 ,
1971+ )
1972+ . await
1973+ }
18941974}
18951975
18961976#[ cfg( test) ]
@@ -1926,6 +2006,14 @@ mod tests {
19262006 assert_eq ! ( faceting, res) ;
19272007 }
19282008
2009+ #[ cfg( feature = "experimental-vector-search" ) ]
2010+ #[ meilisearch_test]
2011+ async fn test_get_embeddings ( index : Index ) {
2012+ let res = index. get_embedders ( ) . await . unwrap ( ) ;
2013+
2014+ assert_eq ! ( HashMap :: new( ) , res) ;
2015+ }
2016+
19292017 #[ meilisearch_test]
19302018 async fn test_set_faceting ( client : Client , index : Index ) {
19312019 let faceting = FacetingSettings {
@@ -1952,6 +2040,23 @@ mod tests {
19522040 assert_eq ! ( faceting, res) ;
19532041 }
19542042
2043+ #[ cfg( feature = "experimental-vector-search" ) ]
2044+ #[ meilisearch_test]
2045+ async fn test_reset_embedders ( client : Client , index : Index ) {
2046+ let features = crate :: ExperimentalFeatures :: new ( & client)
2047+ . set_vector_store ( true )
2048+ . update ( )
2049+ . await
2050+ . expect ( "could not enable the vector store" ) ;
2051+ assert_eq ! ( features. vector_store, true ) ;
2052+ let task_info = index. reset_embedders ( ) . await . unwrap ( ) ;
2053+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2054+
2055+ let res = index. get_embedders ( ) . await . unwrap ( ) ;
2056+
2057+ assert_eq ! ( HashMap :: new( ) , res) ;
2058+ }
2059+
19552060 #[ meilisearch_test]
19562061 async fn test_get_dictionary ( index : Index ) {
19572062 let dictionary: Vec < String > = vec ! [ ] ;
@@ -2128,6 +2233,28 @@ mod tests {
21282233 assert_eq ! ( expected, res) ;
21292234 }
21302235
2236+ #[ cfg( feature = "experimental-vector-search" ) ]
2237+ #[ meilisearch_test]
2238+ async fn test_set_embedding_settings ( client : Client , index : Index ) {
2239+ let features = crate :: ExperimentalFeatures :: new ( & client)
2240+ . set_vector_store ( true )
2241+ . update ( )
2242+ . await
2243+ . expect ( "could not enable the vector store" ) ;
2244+ assert_eq ! ( features. vector_store, true ) ;
2245+
2246+ let custom_embedder = Embedder :: UserProvided ( CustomEmbedderSettings { dimensions : 2 } ) ;
2247+ let embeddings = HashMap :: from ( [ ( "default" . into ( ) , custom_embedder) ] ) ;
2248+ let settings = Settings :: new ( ) . with_embedders ( embeddings. clone ( ) ) ;
2249+
2250+ let task_info = index. set_settings ( & settings) . await . unwrap ( ) ;
2251+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2252+
2253+ let res = index. get_embedders ( ) . await . unwrap ( ) ;
2254+
2255+ assert_eq ! ( embeddings, res) ;
2256+ }
2257+
21312258 #[ meilisearch_test]
21322259 async fn test_reset_proximity_precision ( index : Index ) {
21332260 let expected = "byWord" . to_string ( ) ;
0 commit comments