Repository navigation
fix: honor dataset language across VisionFigureParser paths - #17227
Conversation
- Pass the dataset language through DOCX figure parsing and vision model setup. - Render both default and contextual figure prompts in the requested language while preserving visible text in its original language. - Add focused tests for language propagation and English and Chinese prompt rendering.
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughFigure parsing now propagates dataset language through DOCX, XLSX, and PDF vision wrappers into model construction and prompts. Templates require localized descriptions while preserving visible text. Tests cover propagation, fallback, and prompt rendering. ChangesLocalized figure descriptions
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant ParsingPipeline
participant FigureWrapper
participant LLMBundle
participant VisionFigureParser
participant PromptGenerator
ParsingPipeline->>FigureWrapper: pass dataset language
FigureWrapper->>LLMBundle: construct vision model with lang
FigureWrapper->>VisionFigureParser: construct parser with lang
VisionFigureParser->>PromptGenerator: build localized figure prompt
VisionFigureParser->>LLMBundle: request figure description
Possibly related issues
Possibly related PRs
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 1
🤖 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 `@deepdoc/parser/figure_parser.py`:
- Around line 169-170: Remove the raw context snippet INFO logs around
FigureParser’s figure-processing flows at deepdoc/parser/figure_parser.py lines
169-170 and 270-271, while retaining the existing context length metadata logs
at both sites.
🪄 Autofix (Beta)
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
Run ID: d6befea3-9166-4d7a-af5d-081430f43480
📒 Files selected for processing (7)
deepdoc/parser/figure_parser.pyrag/app/naive.pyrag/prompts/generator.pyrag/prompts/vision_llm_figure_describe_prompt.mdrag/prompts/vision_llm_figure_describe_prompt_with_context.mdtest/unit_test/deepdoc/parser/test_figure_parser.pytest/unit_test/rag/prompts/test_vision_figure_prompt.py
- Remove raw document context snippets from INFO logs while retaining length metadata to avoid exposing uploaded content.
|
These raw context snippet logs predated this PR. They have now been removed in commit 6e3f2b7 Focused tests: 7 passed. Ruff: all checks passed. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17227 +/- ##
==========================================
- 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:
|
|
Thanks for this fix — the approach of controlling output language via the prompt's What's fixed
What's still broken
Root cause: Every This means PDF, Excel, book, manual, and paper figure descriptions are still always generated in English.
|
- Pass the dataset language through the DOCX, XLSX, and PDF figure wrappers and all Python callers. - Extend focused tests to cover language propagation across every Python figure wrapper path.
|
Addressed in commit 1e1259d.
Validation: 10 focused tests passed, and Ruff reports no issues.
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/one.py`:
- Line 85: Before calling vision_figure_parser_docx_wrapper_naive, add a log
entry recording the requested lang and len(image_idxs), using the module’s
existing logging mechanism and preserving the current wrapper arguments and
behavior.
🪄 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: f64cc6e7-5124-48ed-a6dc-0ccc51402b3b
📒 Files selected for processing (4)
deepdoc/parser/figure_parser.pyrag/app/one.pytest/unit_test/deepdoc/parser/test_figure_parser.pytest/unit_test/rag/app/test_one.py
🚧 Files skipped from review as they are similar to previous changes (1)
- deepdoc/parser/figure_parser.py
|
Hi @xugangqiang, just following up on this PR when you have a chance. I’ve incorporated the review feedback and completed the language Empty Following the latest CodeRabbit feedback, the All 17 focused tests pass, and the PR is ready for another review. Thanks! |
|
Thanks for the fix — driving output language through the prompt's Scope gap — two more
|
|
Thanks for the thorough repo-wide audit. I’ll go with option (b) and fold the remaining Markdown and agent-flow language propagation into this PR, together with focused caller-forwarding tests. I’ll not mark #17136 fully resolved until all of those paths are covered.
|
|
@xugangqiang During the final repo-wide audit, I also found that MinerU’s separate PDF image-enrichment path calls Could you take another look when convenient? Thanks! |
|
LGTM — thanks for the thorough repo-wide audit and the iterative fixes across all four wrappers plus the Markdown and agent-flow paths. Before I merge (I'll do it shortly), could you please open a follow-up English issue to track the two remaining / sites that still ignore dataset language and fall back to English:
Please mention this PR (#17227) in that issue so the linkage is clear. Once the issue is created I'll go ahead and merge. |
|
Sure! I’ve opened #17885 to track the remaining MinerU and Mistral language-propagation paths.
|
The EmbeddingModel BatchSize port (knowledge compiler) accidentally reverted PR infiniflow#17227, which threaded the document language through the vision figure parser (LLMBundle lang, VisionFigureParser lang, and the vision figure describe prompts) so figure captions are described in the dataset language. Restore the lang plumbing across the docx/pdf/xlsx wrappers, Excel.__call__, enhance_media_sections_with_vision, the prompt generators, and the two prompt templates.
This PR (EmbeddingModel BatchSize port, infiniflow#17881) deleted five unit tests that PR infiniflow#17227 added to cover the dataset-language plumbing threaded through VisionFigureParser / LLMBundle / the vision figure describe prompts. Those source changes were already restored; restore the matching test coverage so the language behavior stays verified: - test/unit_test/deepdoc/parser/test_figure_parser.py - test/unit_test/rag/app/test_one.py - test/unit_test/rag/app/test_vision_language_callers.py - test/unit_test/rag/flow/parser/test_vision_language.py - test/unit_test/rag/prompts/test_vision_figure_prompt.py
…wrappers PR infiniflow#17227 fixed the dataset language propagation for the `vision_figure_parser_docx_wrapper_naive` path, but three other wrappers in `deepdoc/parser/figure_parser.py` had the same bug: they never received `lang`, so `VisionFigureParser.self.language` always defaulted to "English" and the figure-description prompt's `{{ language }}` variable always rendered as English. Affected paths (this PR covers all of them): - `vision_figure_parser_docx_wrapper` (line 49) -- callers: `rag/app/book.py:89`, `rag/app/manual.py:286` - `vision_figure_parser_figure_xlsx_wrapper` (line 69) -- callers: `rag/app/table.py:83` (also forward `lang` through `Excel.__call__`) - `vision_figure_parser_pdf_wrapper` (line 102) -- callers: `rag/app/naive.py:122` (`by_deepdoc`), `rag/app/manual.py:267`, `rag/app/paper.py:183` - `vision_figure_parser_docx_wrapper_naive` (line 144) -- callers: `rag/app/naive.py:1031`, `rag/app/one.py:86` (already in PR infiniflow#17227 for the wrapper itself, repeated here for self-containment) Root cause: every `chunk()` function declares `lang="Chinese"` as a named parameter, so `lang` is captured and is **not** in `**kwargs`. The wrappers received `**kwargs` only, so `lang` never reached `VisionFigureParser.__init__`, and `self.language = kwargs.get("lang") or "English"` always fell back to "English". This PR also picks up the supporting changes that PR infiniflow#17227 introduced for the `_naive` wrapper (since PR infiniflow#17227 is still open and depends on the same `VisionFigureParser.__init__` and prompt changes): - `VisionFigureParser.__init__` stores `self.language` from the `lang` kwarg (default "English"). - `vision_llm_figure_describe_prompt(language=...)` and `vision_llm_figure_describe_prompt_with_context(..., language=...)` accept and render the `language` argument. - Both prompt .md templates now include an `## OUTPUT LANGUAGE` section that uses `{{ language }}`. Impact: figure descriptions for PDF (naive/manual/paper), DOCX (book/manual), and Excel (table) now honor the dataset's language setting. Pre-fix, all figure descriptions were always generated in English regardless of the dataset language. Out of scope: `LLMBundle(lang=)` does not currently affect figure descriptions (the prompt `{{ language }}` is what controls the output language). `LLMBundle(lang=lang)` is still passed here for consistency with the non-figure LLM call sites. Fixes infiniflow#17280. Supersedes the partial PR infiniflow#17227 (still OPEN, never landed).
Summary
their application callers.
VisionFigureParserpaths used by Markdown and agent-flow PDF, DOCX, and Markdown parsing.
language.
language propagation.
Why
Embedded-image descriptions did not consistently receive the dataset
language, and the
figure-description prompts contained no output-language instruction. As a
result, descriptions
could be generated in English even when the dataset language was set to
Chinese.
A repo-wide
VisionFigureParseraudit also found missing languagepropagation in the Markdown
and agent-flow media-description paths. These paths are now covered by
this PR.
Testing
prompt tests: 27 passed
ruff format --checkandruff checkon modified Python filesgit diff --checkFixes #17136