Repository navigation
fix: keep OCR text when no image2text model is configured - #18012
yuzhichang merged 5 commits into
Conversation
The picture parser discarded OCR output when the text was under the CV LLM threshold and the vision model lookup failed, so an image with readable text produced no chunk at all. Closes infiniflow#17941
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughPicture parsing strips OCR text before length checks. When vision-model processing fails, available OCR text is indexed and the document keeps media context. Tests cover configurable OCR output, model lookup failures, successful fallback, and empty OCR output. ChangesPicture OCR fallback
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: 🔵 Low · up to The change preserves non-empty OCR text when no vision model is available and reports degraded parsing. A broad exception handler can also misclassify unrelated processing failures as vision-model outages and fall back to OCR-only, so the PR is mergeable with explicit owner follow-up to narrow the handler. Suggested labels: Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 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.
Inline comments:
In `@rag/app/picture.py`:
- Around line 113-116: Add a warning-level application log in the OCR fallback
branch of the surrounding image-processing function, alongside the existing
callback, recording the CV LLM failure and that OCR text indexing is being used.
Preserve the current tokenize and attach_media_context flow while ensuring the
warning is emitted even when callback events are not retained.
- Around line 113-116: Normalize OCR text immediately after extraction and
before the length threshold and fallback branch, so whitespace-only values such
as " \n" are treated as empty and do not produce a successful empty image chunk.
Update the logic around the OCR handling flow and add a regression case covering
ocr_text=" \n".
In `@test/unit_test/rag/app/test_picture_video.py`:
- Around line 165-167: Update the docstring of
test_failure_is_reported_when_ocr_finds_no_text() to describe parser behavior:
chunk() produces no chunks and invokes the parser failure callback. Remove
references to task failure, indexing, or task-status handling.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: fbb692b6-a5c0-4207-b888-235757e4e21d
📒 Files selected for processing (2)
rag/app/picture.pytest/unit_test/rag/app/test_picture_video.py
Whitespace-only OCR output is truthy, so it reached the fallback and produced a chunk with no searchable content. Strip the text at extraction so it is treated as empty.
|
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. |
|
Thanks for the fix — the core problem (usable OCR text being discarded when no image2text model is set) is solved and the new tests are solid. A few remaining issues I'd like to flag before merge: 1. "Closes #17941" overclaims the scope. 2. Vision failure is silently swallowed as a successful parse. 3. 4. Missing test for the behavior change. These are not blockers for the happy path, but #1 and #2 affect how the failure is reported to users. Question for @Dhruv-kys: would you prefer to address #1–#4 (at least #1 and the |
|
Thanks — #1, #2 and #4 are fixed. On #3 I think the specific suggestion would reintroduce the bug; details below. #1 — scope. Description now says "Partially addresses #17941" and maps the three parts: P0-1 here, P0-2 in #18013, P1 split out as #18509. #2 — degraded status. The fallback no longer reports a clean success. It now sends a message-only I went with the message rather than a flag on the chunk because chunk fields are schema-bound — #3 — if not model_name:
raise Exception(f"No default {model_type} model is set.")
Related: the test was faking the failure as If you want the catch narrowed properly, the clean way is a dedicated exception (e.g. #4 — test added.
|
The fallback that indexes OCR text when the vision model is unavailable sent callback(0.8, ...), so a misconfigured or erroring image2text model produced a task that looked like a clean success. Send a message-only [WARN] instead: the OCR text is still indexed, but the vision failure stays visible and the progress field is left untouched. Fix the test fake to raise a bare Exception rather than LookupError. get_tenant_default_model_by_type raises Exception for an unset default model (tenant_model_service.py:196); LookupError is only raised for the misconfigured cases, so the fake did not match this code path.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #18012 +/- ##
==========================================
- Coverage 94.56% 90.65% -3.91%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 650 -28
- Misses 25 39 +14
- Partials 14 28 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
@yuzhichang LGTM |
…#18012) An image whose OCR text is shorter than the CV LLM threshold produces zero chunks when the tenant has no image2text model configured. The extracted text is discarded.
Summary
An image whose OCR text is shorter than the CV LLM threshold produces zero chunks when the tenant has no image2text model configured. The extracted text is discarded.
rag/app/picture.pysends short OCR output to the vision model:With no vision model set,
get_tenant_default_model_by_typeraises andreturn []throws awaytxt, which already held usable OCR output. The success path keeps it (txt += "\n" + ans); only the failure path loses it.This indexes the OCR text when the vision model is unavailable, and leaves the existing failure signal untouched when OCR found nothing.
Because the OCR-only result is a degraded parse rather than a clean one, the fallback reports
[WARN] CV LLM unavailable (...), indexing OCR text only.via a message-only callback instead ofcallback(0.8, ...). A misconfigured or erroring vision model therefore stays visible to the operator rather than reading as a normal success, and the progress field is left for the parser/orchestrator to own.Partially addresses #17941
#17941 bundled three problems. This PR covers the first:
task_executormarkschunks == []asprogress=1.0DONE instead of preserving the parser's-1. Affects every chunker, tracked in [Bug]: parser failure (progress -1) is overwritten by "No chunk built" and the document is marked DONE #18013.Testing
test_short_ocr_text_is_kept_when_vision_model_is_missing— 0 chunks on main, 1 chunk here.test_parser_reports_failure_when_ocr_finds_no_text— parametrized over empty and whitespace-only OCR output; a blank image with no vision model still reportsprog=-1.test_ocr_only_fallback_is_reported_as_degraded— the fallback keeps the chunk, emits exactly one[WARN]carrying the reason, and emits neitherprog=-1nor a clean0.8. Fails on the pre-fix parser withthe vision failure was not reported as a degraded parse.ruff checkon the two touched files reports the same 14 pre-existing errors asmain(verified against a stashed tree);ruff format --checkis clean.