From 1c06ec39ca1ae1846ebfb493058d9491766c1b6b Mon Sep 17 00:00:00 2001 From: Philipp Heyken Soares <30441296+HeyPhiS@users.noreply.github.com> Date: Thu, 20 Nov 2025 02:46:39 +0100 Subject: [PATCH] fix cohere rerank base_url default (#11353) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### What problem does this PR solve? **Cohere rerank base_url default handling** - Background: When no rerank base URL is configured, the settings pipeline was passing an empty string through RERANK_CFG → TenantLLMService → CoHereRerank, so the Cohere client received base_url="" and produced “missing protocol” errors during rerank calls. - What changed: The CoHereRerank constructor now only forwards base_url to the Cohere client when it isn’t empty/whitespace, causing the client to fall back to its default API endpoint otherwise. - Why it matters: This prevents invalid URL construction in the rerank workflow and keeps tests/sanity checks that rely on the default Cohere endpoint from failing when no custom base URL is specified. ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) Co-authored-by: Philipp Heyken Soares --- rag/llm/rerank_model.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rag/llm/rerank_model.py b/rag/llm/rerank_model.py index cf9834901..c876c0515 100644 --- a/rag/llm/rerank_model.py +++ b/rag/llm/rerank_model.py @@ -234,7 +234,11 @@ class CoHereRerank(Base): def __init__(self, key, model_name, base_url=None): from cohere import Client - self.client = Client(api_key=key, base_url=base_url) + # Only pass base_url if it's a non-empty string, otherwise use default Cohere API endpoint + client_kwargs = {"api_key": key} + if base_url and base_url.strip(): + client_kwargs["base_url"] = base_url + self.client = Client(**client_kwargs) self.model_name = model_name.split("___")[0] def similarity(self, query: str, texts: list):