From dfa5e41ea6fa37f1d5df6710da543b00050417d9 Mon Sep 17 00:00:00 2001 From: Louis Dureuil Date: Mon, 25 Mar 2024 10:05:58 +0100 Subject: [PATCH] Check validity of the URL setting --- Cargo.lock | 1 + meilisearch-types/src/error.rs | 1 + meilisearch/src/routes/indexes/settings.rs | 1 + milli/Cargo.toml | 1 + milli/src/error.rs | 2 ++ milli/src/update/settings.rs | 8 ++++++++ 6 files changed, 14 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6a8c20f12..214ba368f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3376,6 +3376,7 @@ dependencies = [ "tokenizers", "tracing", "ureq", + "url", "uuid", ] diff --git a/meilisearch-types/src/error.rs b/meilisearch-types/src/error.rs index aed77411a..1b94201f2 100644 --- a/meilisearch-types/src/error.rs +++ b/meilisearch-types/src/error.rs @@ -353,6 +353,7 @@ impl ErrorCode for milli::Error { | UserError::InvalidOpenAiModelDimensions { .. } | UserError::InvalidOpenAiModelDimensionsMax { .. } | UserError::InvalidSettingsDimensions { .. } + | UserError::InvalidUrl { .. } | UserError::InvalidPrompt(_) => Code::InvalidSettingsEmbedders, UserError::TooManyEmbedders(_) => Code::InvalidSettingsEmbedders, UserError::InvalidPromptForEmbeddings(..) => Code::InvalidSettingsEmbedders, diff --git a/meilisearch/src/routes/indexes/settings.rs b/meilisearch/src/routes/indexes/settings.rs index 5dabd7b0d..99c3d0fbb 100644 --- a/meilisearch/src/routes/indexes/settings.rs +++ b/meilisearch/src/routes/indexes/settings.rs @@ -605,6 +605,7 @@ fn embedder_analytics( EmbedderSource::HuggingFace => sources.insert("huggingFace"), EmbedderSource::UserProvided => sources.insert("userProvided"), EmbedderSource::Ollama => sources.insert("ollama"), + EmbedderSource::Rest => sources.insert("rest"), }; } }; diff --git a/milli/Cargo.toml b/milli/Cargo.toml index 4833ad00b..9f5803f4e 100644 --- a/milli/Cargo.toml +++ b/milli/Cargo.toml @@ -86,6 +86,7 @@ arroy = "0.2.0" rand = "0.8.5" tracing = "0.1.40" ureq = { version = "2.9.6", features = ["json"] } +url = "2.5.0" [dev-dependencies] mimalloc = { version = "0.1.39", default-features = false } diff --git a/milli/src/error.rs b/milli/src/error.rs index 1147085dd..aba80b475 100644 --- a/milli/src/error.rs +++ b/milli/src/error.rs @@ -243,6 +243,8 @@ only composed of alphanumeric characters (a-z A-Z 0-9), hyphens (-) and undersco }, #[error("`.embedders.{embedder_name}.dimensions`: `dimensions` cannot be zero")] InvalidSettingsDimensions { embedder_name: String }, + #[error("`.embedders.{embedder_name}.url`: could not parse `{url}`: {inner_error}")] + InvalidUrl { embedder_name: String, inner_error: url::ParseError, url: String }, } impl From for Error { diff --git a/milli/src/update/settings.rs b/milli/src/update/settings.rs index 4c7289eb7..e902badc0 100644 --- a/milli/src/update/settings.rs +++ b/milli/src/update/settings.rs @@ -1199,6 +1199,14 @@ pub fn validate_embedding_settings( .into()); } + if let Some(url) = url.as_ref().set() { + url::Url::parse(url).map_err(|error| crate::error::UserError::InvalidUrl { + embedder_name: name.to_owned(), + inner_error: error, + url: url.to_owned(), + })?; + } + let Some(inferred_source) = source.set() else { return Ok(Setting::Set(EmbeddingSettings { source,