Skip to content

fix(ollama): preserve native API base URL in OllamaCV - #17013

Merged
JinHai-CN merged 3 commits into
infiniflow:mainfrom
iwasaki1112:fix/ollama-cv-v1-url-bug
Aug 28, 2026
Merged

JinHai-CN merged 3 commits into
infiniflow:mainfrom
iwasaki1112:fix/ollama-cv-v1-url-bug

Conversation

@iwasaki1112

Copy link
Copy Markdown
Contributor

What

OllamaCV.__init__ normalizes base_url with ensure_v1(), which forces a trailing /v1 onto the URL. That's correct for the OpenAI-compatible SDK clients used by most other providers in cv_model.py, but OllamaCV doesn't use one — it hands the URL straight to the official ollama.Client, which targets Ollama's native REST API ({host}/api/generate, {host}/api/chat, ...), not an OpenAI-compatible /v1 surface.

With /v1 already baked into host, every request lands on {base_url}/v1/api/generate and Ollama returns 404, since that path doesn't exist.

Impact

Any dataflow Parser step that sends an image to an Ollama vision model (PDF/DOCX/Image/etc. with "Disable vision model" off) gets back **ERROR**: 404 page not found (status code: 404) from describe() / describe_with_prompt() / async_chat() / async_chat_streamly(). Because those methods return the error text as the "description" instead of raising, the literal error string gets ingested as chunk content alongside real document text.

Fix

Use base_url as configured, only stripping a trailing slash — matching how the ollama-python README documents Client(host=...).

Testing

Verified against a live RAGFlow + Ollama deployment (Ollama configured with a valid, /v1-free base URL and a vision-capable model):

  • Before: Ollama's access log showed repeated 404s on POST /v1/api/generate for every vision call made by a dataflow Parser step; the OCR/description output for each figure contained the literal **ERROR**: 404 page not found (status code: 404) string.
  • After: the same dataflow run produced POST /api/generate requests returning 200 OK, and the error string no longer appeared in the parsed output.

No automated test is included; this is a one-line behavioral fix to a URL a real backend is sensitive to, not something a mock would catch. Happy to add a unit test around OllamaCV.__init__ (asserting the Client is constructed with the un-suffixed host) if useful.

OllamaCV.__init__ passed the configured base_url through ensure_v1(),
which forces a trailing /v1 segment. That URL is then handed to the
official ollama-python Client, which targets Ollama's native REST API
(e.g. POST {host}/api/generate, POST {host}/api/chat) rather than an
OpenAI-compatible /v1 surface. With /v1 already baked into the host,
every request lands on {base_url}/v1/api/generate and Ollama returns
404, since that native API is not published there.

ensure_v1() exists for the OpenAI-compatible SDK clients used by the
other providers in this file (OpenAI, Azure, xAI, etc.), not for the
ollama-python client. Applying it to OllamaCV mixes the two protocols.

Symptom observed on a real deployment: every dataflow Parser step that
sends an image to an Ollama VLM (PDF/DOCX/etc. with 'Disable vision
model' off) got '**ERROR**: 404 page not found (status code: 404)'
back from describe()/describe_with_prompt(), and that literal error
string was ingested as chunk text alongside the real content.

Fix: use the base_url as configured (only strip a trailing slash),
matching how the ollama-python README documents Client(host=...).

Verified against a live RAGFlow + Ollama deployment: before the fix,
Ollama's access log showed repeated 404s on POST /v1/api/generate;
after patching this file into the running container and restarting,
the same dataflow run produced POST /api/generate requests returning
200 OK.
Drop the redundant `or ""` fallback: base_url is a required kwarg for
this provider, so coercing a missing/None value to an empty string
only masks a configuration error instead of surfacing it. Plain
.rstrip("/") matches how the other providers in this file normalize
their base_url.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 16, 2026
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 75baf8b8-6580-4523-9703-bde48002b019

📥 Commits

Reviewing files that changed from the base of the PR and between 3f0cf5a and f535030.

📒 Files selected for processing (1)
  • rag/llm/cv_model.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • rag/llm/cv_model.py

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

OllamaCV now removes trailing slashes from base_url instead of applying ensure_v1. The normalized URL is used as the Ollama client host.

Changes

Ollama URL normalization

Layer / File(s) Summary
Normalize Ollama client host URL
rag/llm/cv_model.py
OllamaCV.__init__ uses rstrip("/") to normalize the configured Ollama base URL instead of ensure_v1.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Merge Risk: ⚪ Minimal · up to f5350

This is a localized URL-handling fix for Ollama vision requests, and no actionable merge-blocking risk remains beyond normal checks and review.

Poem

I’m a rabbit trimming slashes with care,
The Ollama host is clean and bare.
No /v1 is added in flight,
The URL now ends just right,
And the client follows it there.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the problem, impact, fix, and testing results. It does not use the template's exact "### Summary" heading, but it provides the required summary information and is othe…
Title check ✅ Passed The title clearly and concisely describes the main change: preserving the native Ollama API base URL in OllamaCV.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the problem, impact, fix, and testing results. It does not use the template's exact "### Summary" heading, but it provides the required summary information and is otherwise complete.

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
rag/llm/cv_model.py (1)

735-735: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Add a focused regression test for the normalized Ollama host.

Assert that a base URL such as http://localhost:11434/ is passed to ollama.Client as http://localhost:11434, and that no /v1 segment is introduced. The official client builds native requests such as /api/generate and /api/chat relative to this host. (raw.githubusercontent.com)

As per coding guidelines, “Preserve valid behavior with focused tests.”

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@rag/llm/cv_model.py` at line 735, Add a focused regression test for the
initialization path that assigns self.base_url, passing a trailing-slash Ollama
URL and asserting ollama.Client receives the slash-trimmed host without any /v1
suffix. Verify the existing native endpoint behavior remains based on this
normalized host.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@rag/llm/cv_model.py`:
- Line 735: Add a focused regression test for the initialization path that
assigns self.base_url, passing a trailing-slash Ollama URL and asserting
ollama.Client receives the slash-trimmed host without any /v1 suffix. Verify the
existing native endpoint behavior remains based on this normalized host.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a043bd7e-15bd-4640-9dc1-dc32bee73100

📥 Commits

Reviewing files that changed from the base of the PR and between bd485db and 37eee89.

📒 Files selected for processing (1)
  • rag/llm/cv_model.py

@Lynn-Inf Lynn-Inf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@JinHai-CN JinHai-CN added the ci Continue Integration label Aug 28, 2026
@coderabbitai

coderabbitai Bot commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@codecov

codecov Bot commented Aug 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.07%. Comparing base (88e80fc) to head (f535030).
⚠️ Report is 20 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17013      +/-   ##
==========================================
- Coverage   39.25%   39.07%   -0.19%     
==========================================
  Files          54       54              
  Lines       14911    14911              
  Branches      117      117              
==========================================
- Hits         5854     5827      -27     
- Misses       9045     9058      +13     
- Partials       12       26      +14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@JinHai-CN
JinHai-CN merged commit c84713f into infiniflow:main Aug 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants