From 0d1f07f45e6d48c4661310c2357fe876c8f893da Mon Sep 17 00:00:00 2001 From: Frank Elsinga Date: Mon, 8 Jul 2024 15:05:01 +0200 Subject: [PATCH] chore: formatting fixes --- src/search.rs | 30 +++++++++++++++++++++--------- src/settings.rs | 8 ++++---- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/src/search.rs b/src/search.rs index 842df7af..13b0d494 100644 --- a/src/search.rs +++ b/src/search.rs @@ -379,7 +379,7 @@ pub struct SearchQuery<'a, Http: HttpClient> { /// /// **Default: `false`** #[serde(skip_serializing_if = "Option::is_none")] - retrieve_vectors: Option + retrieve_vectors: Option, } #[allow(missing_docs)] @@ -715,6 +715,7 @@ mod tests { }; use big_s::S; use meilisearch_test_macro::meilisearch_test; + use mockito::Matcher; use serde::{Deserialize, Serialize}; use serde_json::{json, Map, Value}; @@ -734,18 +735,24 @@ mod tests { _vectors: Option, } - #[derive(Debug, Serialize, Deserialize, PartialEq)] struct Vector { embeddings: Vec>, regenerate: bool, } + #[derive(Debug, Serialize, Deserialize, PartialEq)] struct Vectors(HashMap); impl From<&[f32; 1]> for Vectors { - fn from(value: &[f32;1]) -> Self { - Vectors(HashMap::from([(S("default"), Vector { embeddings: Vec::from([value.to_vec()]), regenerate:false })])) + fn from(value: &[f32; 1]) -> Self { + Vectors(HashMap::from([( + S("default"), + Vector { + embeddings: Vec::from([value.to_vec()]), + regenerate: false, + }, + )])) } } @@ -1376,7 +1383,8 @@ mod tests { .await .expect("could not enable the vector store"); assert_eq!(features.vector_store, true); - let embedder_setting = Embedder::UserProvided(UserProvidedEmbedderSettings { dimensions: 1 }); + let embedder_setting = + Embedder::UserProvided(UserProvidedEmbedderSettings { dimensions: 1 }); let t3 = index .set_settings(&crate::settings::Settings { embedders: Some(HashMap::from([("default".to_string(), embedder_setting)])), @@ -1392,18 +1400,22 @@ mod tests { setup_hybrid_searching(&client, &index).await?; setup_test_index(&client, &index).await?; - let results: SearchResults = index.search() + let results: SearchResults = index + .search() .with_query("lorem ipsum") .with_retrieve_vectors(true) - .execute().await?; + .execute() + .await?; assert_eq!(results.hits.len(), 1); let expected = Vectors::from(&[1000.0]); assert_eq!(results.hits[0].result._vectors, Some(expected)); - let results: SearchResults = index.search() + let results: SearchResults = index + .search() .with_query("lorem ipsum") .with_retrieve_vectors(false) - .execute().await?; + .execute() + .await?; assert_eq!(results.hits.len(), 1); assert_eq!(results.hits[0].result._vectors, None); Ok(()) diff --git a/src/settings.rs b/src/settings.rs index 2cd7ba4d..d699e520 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -68,7 +68,7 @@ pub enum Embedder { /// ..Default::default() /// }; /// # let expected = r#"{"model":"BAAI/bge-base-en-v1.5","documentTemplate":"A document titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}"}"#; -/// # let expected: HuggingFaceEmbedderSettings = serde_json::from_str(expected).unwrap(); +/// # let expected: HuggingFaceEmbedderSettings = serde_json::from_str(expected).unwrap(); /// # assert_eq!(embedder_setting, expected); /// ``` #[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)] @@ -109,7 +109,7 @@ pub struct HuggingFaceEmbedderSettings { /// ..Default::default() /// }; /// # let expected = r#"{"apiKey":"anOpenAiApiKey","model":"text-embedding-3-small","documentTemplate":"A document titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}","dimensions": 1536"}"#; -/// # let expected: OpenapiEmbedderSettings = serde_json::from_str(expected).unwrap(); +/// # let expected: OpenapiEmbedderSettings = serde_json::from_str(expected).unwrap(); /// # assert_eq!(embedder_setting, expected); /// ``` #[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)] @@ -150,7 +150,7 @@ pub struct OpenapiEmbedderSettings { /// document_template: Some("A document titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}".to_string()), /// }; /// # let expected = r#"{"url":"http://localhost:11434/api/embeddings","apiKey":"foobarbaz","model":"nomic-embed-text","documentTemplate":"A document titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}"}"#; -/// # let expected: OllamaEmbedderSettings = serde_json::from_str(expected).unwrap(); +/// # let expected: OllamaEmbedderSettings = serde_json::from_str(expected).unwrap(); /// # assert_eq!(embedder_setting, expected); /// ``` #[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)] @@ -208,7 +208,7 @@ pub struct OllamaEmbedderSettings { /// embedding_object: vec!["embedding".to_string()], /// }; /// # let expected = r#"{"url":"http://localhost:12345/api/v1/embed","apiKey":"SOURCE_API_KEY","dimensions":512,"documentTemplate":"A document titled {{doc.title}} whose description starts with {{doc.overview|truncatewords: 20}}","inputField":["data","text"],"inputType":"text","query":{"dimensions":512,"model":"MODEL_NAME"},"pathToEmbeddings":["data"],"embeddingObject":["embedding"]}"#; -/// # let expected: GenericRestEmbedderSettings = serde_json::from_str(expected).unwrap(); +/// # let expected: GenericRestEmbedderSettings = serde_json::from_str(expected).unwrap(); /// # assert_eq!(embedder_setting, expected); /// ``` #[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)]