Skip to content

fix: use provider-specific default base_url in BaseLLMReranker (Ollama gets localhost:11434, not OpenAI endpoint)#12405

Closed
amethystani wants to merge 2 commits into
mindsdb:mainfrom
amethystani:fix/reranker-ollama-default-base-url
Closed

fix: use provider-specific default base_url in BaseLLMReranker (Ollama gets localhost:11434, not OpenAI endpoint)#12405
amethystani wants to merge 2 commits into
mindsdb:mainfrom
amethystani:fix/reranker-ollama-default-base-url

Conversation

@amethystani

Copy link
Copy Markdown

Summary

Fixes #11952BaseLLMReranker uses DEFAULT_LLM_ENDPOINT (https://api.openai.com/v1) as the fallback base_url for all OpenAI-compatible providers, including Ollama. This means any user who configures an Ollama reranker without explicitly setting base_url gets their requests silently routed to the OpenAI endpoint, which fails with 404.

Root Cause

In BaseLLMReranker._init_client() the branch that handles openai and ollama providers always fell back to the same default:

# Before — same OpenAI URL used as fallback for both providers
base_url = self.base_url or DEFAULT_LLM_ENDPOINT   # https://api.openai.com/v1

Fix

Use a provider-specific default so Ollama falls back to http://localhost:11434/v1 (the standard local Ollama endpoint), while the openai provider retains its existing DEFAULT_LLM_ENDPOINT default:

if self.provider == 'ollama':
    default_base_url = 'http://localhost:11434/v1'
else:
    default_base_url = DEFAULT_LLM_ENDPOINT
base_url = self.base_url or default_base_url

An explicit base_url is still respected in all cases.

Tests Added

tests/unit/interfaces/knowledge_base/test_reranker_base_url.py — 5 parametrized cases covering:

  • Ollama with no base_url → gets Ollama default ✓
  • Ollama with explicit base_url → respected ✓
  • OpenAI with no base_url → gets DEFAULT_LLM_ENDPOINT
  • OpenAI with explicit base_url → respected ✓
  • Regression: Ollama default ≠ OpenAI endpoint ✓

cc @MinuraPunchihewa @paxmaxei @kumpelblase2 — this is the remaining bug after the settings.py default was corrected. Happy to address any feedback.

…lama (mindsdb#11952)

When the Ollama reranker provider is used without an explicit base_url,
the fallback was DEFAULT_LLM_ENDPOINT (https://api.openai.com/v1) — the
OpenAI URL — which causes all Ollama reranker calls to fail with 404.

Fix: use http://localhost:11434/v1 as the Ollama default, while keeping
DEFAULT_LLM_ENDPOINT as the fallback for the standard OpenAI provider.
@github-actions

github-actions Bot commented Apr 23, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@amethystani

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Apr 23, 2026
@entelligence-ai-pr-reviews

Copy link
Copy Markdown
Contributor

EntelligenceAI PR Summary

Fixes gh-11952 by ensuring BaseLLMReranker uses the correct default base URL based on the configured provider.

  • Modified _init_client in base_reranker.py to check if provider is 'ollama' and apply http://localhost:11434/v1 as the fallback base URL
  • All other providers continue to use DEFAULT_LLM_ENDPOINT when no base_url is specified
  • Added test_reranker_base_url.py with unit tests using unittest.mock to bypass _init_client during construction and inspect AsyncOpenAI call kwargs for URL correctness

Confidence Score: 4/5 - Mostly Safe

Safe to merge — this PR correctly addresses the provider-specific default base URL bug in BaseLLMReranker._init_client, ensuring Ollama uses http://localhost:11434/v1 instead of the OpenAI endpoint. The fix is surgical and well-scoped, touching only the relevant conditional logic in base_reranker.py and backing the change with unit tests in test_reranker_base_url.py. No review comments were generated and no critical or significant issues were identified by static analysis.

Key Findings:

  • The conditional check in _init_client correctly isolates Ollama's default base URL (http://localhost:11434/v1) without affecting any other provider's fallback to DEFAULT_LLM_ENDPOINT, making the logic change minimal and low-risk.
  • Unit tests in test_reranker_base_url.py use unittest.mock to bypass _init_client during construction and inspect AsyncOpenAI call arguments, which is an appropriate testing pattern for this kind of initialization-time behavior.
  • Only 1 of 2 changed files was reviewed by the automated analysis (coverage gap on either the test file or the implementation), but given the simplicity of the change and zero flagged issues, this is a minor concern rather than a blocking one.
Files requiring special attention
  • base_reranker.py
  • test_reranker_base_url.py

@torrmal

torrmal commented May 2, 2026

Copy link
Copy Markdown
Contributor

thank you!! can you please create a pull request in github.com/mindsdb/engine

@amethystani

Copy link
Copy Markdown
Author

Sounds good! I'll port this over to the engine repo right now and link the new PR here once it's up.

@amethystani

Copy link
Copy Markdown
Author

The PR is up on the engine repo here: mindsdb/engine#2

Closing this one out. Thanks again!

@amethystani amethystani closed this May 2, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators May 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Reranker defaults to OpenAI endpoint for non-OpenAI providers (e.g., Google Gemini)

2 participants