@@ -55,8 +55,9 @@ pub enum Embedder {
55
55
#[ serde( rename_all = "camelCase" ) ]
56
56
pub struct HuggingFaceEmbedderSettings {
57
57
/// 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 > ,
60
61
#[ serde( skip_serializing_if = "Option::is_none" ) ]
61
62
pub revision : Option < String > ,
62
63
/// if present, document_template must be a [Liquid template](https://shopify.github.io/liquid/).
@@ -77,9 +78,12 @@ pub struct OpenapiEmbedderSettings {
77
78
/// Use [tier 2 keys](https://platform.openai.com/docs/guides/rate-limits/usage-tiers?context=tier-two) or above for optimal performance.
78
79
pub api_key : String ,
79
80
/// 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 > ,
83
87
/// if present, document_template must be a [Liquid template](https://shopify.github.io/liquid/).
84
88
/// Use `{{ doc.attribute }}` to access document field values.
85
89
/// 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> {
836
840
. await
837
841
}
838
842
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
+
839
886
/// Update [settings](../settings/struct.Settings) of the [Index].
840
887
///
841
888
/// 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> {
1891
1938
)
1892
1939
. await
1893
1940
}
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
+ }
1894
1974
}
1895
1975
1896
1976
#[ cfg( test) ]
@@ -1926,6 +2006,14 @@ mod tests {
1926
2006
assert_eq ! ( faceting, res) ;
1927
2007
}
1928
2008
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
+
1929
2017
#[ meilisearch_test]
1930
2018
async fn test_set_faceting ( client : Client , index : Index ) {
1931
2019
let faceting = FacetingSettings {
@@ -1952,6 +2040,23 @@ mod tests {
1952
2040
assert_eq ! ( faceting, res) ;
1953
2041
}
1954
2042
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
+
1955
2060
#[ meilisearch_test]
1956
2061
async fn test_get_dictionary ( index : Index ) {
1957
2062
let dictionary: Vec < String > = vec ! [ ] ;
@@ -2128,6 +2233,28 @@ mod tests {
2128
2233
assert_eq ! ( expected, res) ;
2129
2234
}
2130
2235
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
+
2131
2258
#[ meilisearch_test]
2132
2259
async fn test_reset_proximity_precision ( index : Index ) {
2133
2260
let expected = "byWord" . to_string ( ) ;
0 commit comments