The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix ai proxied /embeddings (#74526)
lbrdnk58f267e85276
diff --git a/enterprise/backend/src/metabase_enterprise/semantic_search/embedding.clj b/enterprise/backend/src/metabase_enterprise/semantic_search/embedding.cljindex 719b2822cb9..e71735ba49a 100644--- a/enterprise/backend/src/metabase_enterprise/semantic_search/embedding.clj+++ b/enterprise/backend/src/metabase_enterprise/semantic_search/embedding.clj@@ -6,6 +6,7 @@[metabase-enterprise.semantic-search.settings :as semantic-settings][metabase.analytics-interface.core :as analytics][metabase.analytics.core :as analytics.core]+ [metabase.premium-features.core :as premium-features][metabase.tracing.core :as tracing][metabase.util :as u][metabase.util.json :as json]@@ -194,7 +195,8 @@`:provider` — label for analytics (e.g. \"ai-service\", \"openai\")`:endpoint` — full URL including /v1/embeddings- `:api-key` — Bearer token+ `:api-key` — Bearer token. If empty ai service proxying is assumed and premium-embedding-token is+ used for authentication`:model-name` — model identifier sent in the request body`:texts` — collection of input strings`:record-tokens?` — true writes a `semantic_search_token_tracking` row, false skips it.@@ -205,7 +207,7 @@:- [:map[:provider :string][:endpoint :string]- [:api-key :string]+ [:api-key {:optional true} [:maybe :string]][:model-name :string][:texts [:sequential :string]][:record-tokens? :boolean]@@ -216,8 +218,16 @@{:endpoint endpoint :documents (count texts) :tokens (count-tokens-batch texts)})(let [start-ms (u/start-timer){:keys [usage data]} (-> (http/post endpoint- {:headers {"Content-Type" "application/json"- "Authorization" (str "Bearer " api-key)}+ {:headers+ (merge {"Content-Type" "application/json"}+ (if (and (empty? api-key)+ (= "ai-service" provider))+ {"x-metabase-instance-token"+ (u/prog1 (premium-features/premium-embedding-token)+ (when (nil? <>)+ (throw (ex-info "Premium embedding token not set"+ {:provider provider}))))}+ {"Authorization" (str "Bearer " api-key)})):body (json/encode (merge {:model model-name:input texts:encoding_format "base64"}@@ -257,16 +267,14 @@;;;; Embedding-service provider(defn- embedding-service-resolve-config!- "Returns [endpoint api-key] or throws if not configured."+ "Returns [endpoint api-key]. Throws if base url is not configured. When api key is not set+ the ai service proxying is assumed. In that case premium-embedding-token is used for authentication."[](let [base-url (semantic-settings/ee-embedding-service-base-url)api-key (semantic-settings/ee-embedding-service-api-key)](when-not base-url(throw (ex-info "Embedding service base URL not configured"{:setting "ee-embedding-service-base-url"})))- (when-not api-key- (throw (ex-info "Embedding service API key not configured"- {:setting "ee-embedding-service-api-key"})))[(str base-url "/v1/embeddings") api-key]))(defmethod get-embedding "ai-service"diff --git a/enterprise/backend/src/metabase_enterprise/semantic_search/settings.clj b/enterprise/backend/src/metabase_enterprise/semantic_search/settings.cljindex 62d0d6dc7c2..7ff99205cb7 100644--- a/enterprise/backend/src/metabase_enterprise/semantic_search/settings.clj+++ b/enterprise/backend/src/metabase_enterprise/semantic_search/settings.clj@@ -61,7 +61,8 @@:doc false)(defsetting ee-embedding-service-api-key- (deferred-tru "API key for authenticating with the embedding service.")+ (deferred-tru (str "API key for authenticating with the embedding service. Leave empty for proxying thorugh"+ " ai-service. In that case premium-embedding-token is used for authentication.")):sensitive? true:visibility :settings-manager:export? falsediff --git a/enterprise/backend/test/metabase_enterprise/semantic_search/embedding_test.clj b/enterprise/backend/test/metabase_enterprise/semantic_search/embedding_test.cljindex 9624292217e..d73d87ee20b 100644--- a/enterprise/backend/test/metabase_enterprise/semantic_search/embedding_test.clj+++ b/enterprise/backend/test/metabase_enterprise/semantic_search/embedding_test.clj@@ -233,16 +233,6 @@(is (thrown-with-msg?clojure.lang.ExceptionInfo#"Embedding service base URL not configured"- (embedding/get-embedding {:provider "ai-service"- :model-name "test-model"- :vector-dimensions 4}- "test text")))))- (testing "ai-service throws when API key not configured"- (mt/with-temporary-setting-values [ee-embedding-service-base-url "http://localhost:1234"- ee-embedding-service-api-key nil]- (is (thrown-with-msg?- clojure.lang.ExceptionInfo- #"Embedding service API key not configured"(embedding/get-embedding {:provider "ai-service":model-name "test-model":vector-dimensions 4}diff --git a/src/metabase/llm/settings.clj b/src/metabase/llm/settings.cljindex 9310c9010f0..6fc8a6fab83 100644--- a/src/metabase/llm/settings.clj+++ b/src/metabase/llm/settings.clj@@ -123,7 +123,8 @@;;; --------------------------------------------------- Proxy ---------------------------------------------------(defsetting llm-proxy-base-url- (deferred-tru "Base URL for the LLM proxy. When set, requests to the managed Metabase AI service are routed through this proxy and authenticated with the instance token instead of a provider API key.")+ (deferred-tru "Base URL for the LLM proxy. When set, requests to the managed Metabase AI service are routed through this proxy and authenticated with the instance token instead of a provider API key. Harbormaster adds /llm component into the url.")+ ;; For details on llm component see the https://github.com/metabase/metabase/pull/74526#discussion_r3282553435.:enabled? #(or (premium-features/has-feature? :metabase-ai-managed)(premium-features/has-feature? :metabot-v3)):encryption :no