@@ -53,8 +53,9 @@ pub enum Embedder {
53
53
#[ serde( rename_all = "camelCase" ) ]
54
54
pub struct HuggingFaceEmbedderSettings {
55
55
/// the BERT embedding model you want to use from HuggingFace
56
- /// Example: `bge-base-en-v1.5`
57
- pub model : String ,
56
+ /// Defaults to `BAAI/bge-base-en-v1.5`
57
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
58
+ pub model : Option < String > ,
58
59
#[ serde( skip_serializing_if = "Option::is_none" ) ]
59
60
pub revision : Option < String > ,
60
61
/// if present, document_template must be a [Liquid template](https://shopify.github.io/liquid/).
@@ -75,9 +76,12 @@ pub struct OpenapiEmbedderSettings {
75
76
/// Use [tier 2 keys](https://platform.openai.com/docs/guides/rate-limits/usage-tiers?context=tier-two) or above for optimal performance.
76
77
pub api_key : String ,
77
78
/// The openapi model name
78
- /// Example: `text-embedding-ada-002`
79
- pub model : String ,
80
- pub dimensions : usize ,
79
+ /// Default: `text-embedding-ada-002`
80
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
81
+ pub model : Option < String > ,
82
+ /// Defaults to the default for said model name
83
+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
84
+ pub dimensions : Option < usize > ,
81
85
/// if present, document_template must be a [Liquid template](https://shopify.github.io/liquid/).
82
86
/// Use `{{ doc.attribute }}` to access document field values.
83
87
/// Meilisearch also exposes a `{{ fields }}` array containing one object per document field, which you may access with `{{ field.name }}` and `{{ field.value }}`.
@@ -820,6 +824,49 @@ impl Index {
820
824
. await
821
825
}
822
826
827
+ /// Get [embedders](https://www.meilisearch.com/docs/learn/experimental/vector_search) of the [Index].
828
+ ///
829
+ /// ```
830
+ /// # use std::collections::HashMap;
831
+ /// # use std::string::String;
832
+ /// use meilisearch_sdk::{client::*, CustomEmbedderSettings, Embedder, ExperimentalFeatures, indexes::*, Settings};
833
+ /// #
834
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
835
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
836
+ /// #
837
+ /// # futures::executor::block_on(async move {
838
+ /// let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
839
+ /// # client.create_index("get_embedders", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
840
+ /// let index = client.index("get_embedders");
841
+ ///
842
+ /// # let mut features = ExperimentalFeatures::new(&client);
843
+ /// # features.set_vector_store(true);
844
+ /// # let res = features.update().await.unwrap();
845
+ /// #
846
+ /// # let t=index.set_settings(&Settings{
847
+ /// # embedders:Some(HashMap::from([(String::from("default"),Embedder::UserProvided(CustomEmbedderSettings{dimensions:1}))])),
848
+ /// # ..Settings::default()
849
+ /// # }).await.unwrap();
850
+ /// # t.wait_for_completion(&client, None, None).await.unwrap();
851
+ /// let embedders = index.get_embedders().await.unwrap();
852
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
853
+ /// # });
854
+ /// ```
855
+ #[ cfg( feature = "experimental-vector-search" ) ]
856
+ pub async fn get_embedders ( & self ) -> Result < HashMap < String , Embedder > , Error > {
857
+ request :: < ( ) , ( ) , Option < HashMap < String , Embedder > > > (
858
+ & format ! (
859
+ "{}/indexes/{}/settings/embedders" ,
860
+ self . client. host, self . uid
861
+ ) ,
862
+ self . client . get_api_key ( ) ,
863
+ Method :: Get { query : ( ) } ,
864
+ 200 ,
865
+ )
866
+ . await
867
+ . map ( |r| r. unwrap_or_default ( ) )
868
+ }
869
+
823
870
/// Update [settings](../settings/struct.Settings) of the [Index].
824
871
///
825
872
/// Updates in the settings are partial. This means that any parameters corresponding to a `None` value will be left unchanged.
@@ -1847,6 +1894,39 @@ impl Index {
1847
1894
)
1848
1895
. await
1849
1896
}
1897
+
1898
+ /// Reset [embedders](https://www.meilisearch.com/docs/learn/experimental/vector_search) of the [Index].
1899
+ ///
1900
+ /// # Example
1901
+ ///
1902
+ /// ```
1903
+ /// # use meilisearch_sdk::{client::*, indexes::*, settings::Settings};
1904
+ /// #
1905
+ /// # let MEILISEARCH_URL = option_env!("MEILISEARCH_URL").unwrap_or("http://localhost:7700");
1906
+ /// # let MEILISEARCH_API_KEY = option_env!("MEILISEARCH_API_KEY").unwrap_or("masterKey");
1907
+ /// #
1908
+ /// # futures::executor::block_on(async move {
1909
+ /// # let client = Client::new(MEILISEARCH_URL, Some(MEILISEARCH_API_KEY));
1910
+ /// # client.create_index("reset_embedders", None).await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1911
+ /// let mut index = client.index("reset_embedders");
1912
+ ///
1913
+ /// let task = index.reset_embedders().await.unwrap();
1914
+ /// # index.delete().await.unwrap().wait_for_completion(&client, None, None).await.unwrap();
1915
+ /// # });
1916
+ /// ```
1917
+ #[ cfg( feature = "experimental-vector-search" ) ]
1918
+ pub async fn reset_embedders ( & self ) -> Result < TaskInfo , Error > {
1919
+ request :: < ( ) , ( ) , TaskInfo > (
1920
+ & format ! (
1921
+ "{}/indexes/{}/settings/embedders" ,
1922
+ self . client. host, self . uid
1923
+ ) ,
1924
+ self . client . get_api_key ( ) ,
1925
+ Method :: Delete { query : ( ) } ,
1926
+ 202 ,
1927
+ )
1928
+ . await
1929
+ }
1850
1930
}
1851
1931
1852
1932
#[ cfg( test) ]
@@ -1882,6 +1962,14 @@ mod tests {
1882
1962
assert_eq ! ( faceting, res) ;
1883
1963
}
1884
1964
1965
+ #[ cfg( feature = "experimental-vector-search" ) ]
1966
+ #[ meilisearch_test]
1967
+ async fn test_get_embeddings ( index : Index ) {
1968
+ let res = index. get_embedders ( ) . await . unwrap ( ) ;
1969
+
1970
+ assert_eq ! ( HashMap :: new( ) , res) ;
1971
+ }
1972
+
1885
1973
#[ meilisearch_test]
1886
1974
async fn test_set_faceting ( client : Client , index : Index ) {
1887
1975
let faceting = FacetingSettings {
@@ -1908,6 +1996,23 @@ mod tests {
1908
1996
assert_eq ! ( faceting, res) ;
1909
1997
}
1910
1998
1999
+ #[ cfg( feature = "experimental-vector-search" ) ]
2000
+ #[ meilisearch_test]
2001
+ async fn test_reset_embedders ( client : Client , index : Index ) {
2002
+ let features = crate :: ExperimentalFeatures :: new ( & client)
2003
+ . set_vector_store ( true )
2004
+ . update ( )
2005
+ . await
2006
+ . expect ( "could not enable the vector store" ) ;
2007
+ assert_eq ! ( features. vector_store, true ) ;
2008
+ let task_info = index. reset_embedders ( ) . await . unwrap ( ) ;
2009
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2010
+
2011
+ let res = index. get_embedders ( ) . await . unwrap ( ) ;
2012
+
2013
+ assert_eq ! ( HashMap :: new( ) , res) ;
2014
+ }
2015
+
1911
2016
#[ meilisearch_test]
1912
2017
async fn test_get_dictionary ( index : Index ) {
1913
2018
let dictionary: Vec < String > = vec ! [ ] ;
@@ -2084,6 +2189,28 @@ mod tests {
2084
2189
assert_eq ! ( expected, res) ;
2085
2190
}
2086
2191
2192
+ #[ cfg( feature = "experimental-vector-search" ) ]
2193
+ #[ meilisearch_test]
2194
+ async fn test_set_embedding_settings ( client : Client , index : Index ) {
2195
+ let features = crate :: ExperimentalFeatures :: new ( & client)
2196
+ . set_vector_store ( true )
2197
+ . update ( )
2198
+ . await
2199
+ . expect ( "could not enable the vector store" ) ;
2200
+ assert_eq ! ( features. vector_store, true ) ;
2201
+
2202
+ let custom_embedder = Embedder :: UserProvided ( CustomEmbedderSettings { dimensions : 2 } ) ;
2203
+ let embeddings = HashMap :: from ( [ ( "default" . into ( ) , custom_embedder) ] ) ;
2204
+ let settings = Settings :: new ( ) . with_embedders ( embeddings. clone ( ) ) ;
2205
+
2206
+ let task_info = index. set_settings ( & settings) . await . unwrap ( ) ;
2207
+ client. wait_for_task ( task_info, None , None ) . await . unwrap ( ) ;
2208
+
2209
+ let res = index. get_embedders ( ) . await . unwrap ( ) ;
2210
+
2211
+ assert_eq ! ( embeddings, res) ;
2212
+ }
2213
+
2087
2214
#[ meilisearch_test]
2088
2215
async fn test_reset_proximity_precision ( index : Index ) {
2089
2216
let expected = "byWord" . to_string ( ) ;
0 commit comments