Skip to content

fix: honor dataset language across VisionFigureParser paths - #17227

Merged
xugangqiang merged 7 commits into
infiniflow:mainfrom
taek105:fix/17136-docx-image-language
Aug 5, 2026
Merged

xugangqiang merged 7 commits into
infiniflow:mainfrom
taek105:fix/17136-docx-image-language

Conversation

@taek105

@taek105 taek105 commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Pass the dataset language through all four figure-parser wrappers and
    their application callers.
  • Cover the direct VisionFigureParser paths used by Markdown and agent-
    flow PDF, DOCX, and Markdown parsing.
  • Normalize missing or empty language values to English.
  • Make both default and contextual figure prompts honor the requested
    language.
  • Preserve visible text verbatim in its original language.
  • Add focused tests for wrapper, caller, Markdown, agent-flow, and prompt
    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 VisionFigureParser audit also found missing language
propagation in the Markdown
and agent-flow media-description paths. These paths are now covered by
this PR.

Testing

  • Focused figure-parser, caller-forwarding, Markdown, agent-flow, and
    prompt tests: 27 passed
  • ruff format --check and ruff check on modified Python files
  • git diff --check
  • Live VLM parsing was not run

Fixes #17136

- 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.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 22, 2026
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Figure 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.

Changes

Localized figure descriptions

Layer / File(s) Summary
Prompt language contract
rag/prompts/generator.py, rag/prompts/vision_llm_figure_describe_prompt*.md
Prompt helpers accept language, and templates require localized descriptions while preserving visible text and fixed field names.
Figure parser language flow
deepdoc/parser/figure_parser.py, rag/app/{book,manual,naive,paper,table,one}.py
DOCX, XLSX, and PDF pipelines normalize and forward dataset language into vision models, parsers, and prompt generation.
Language propagation validation
test/unit_test/deepdoc/parser/test_figure_parser.py, test/unit_test/rag/prompts/test_vision_figure_prompt.py, test/unit_test/rag/app/test_one.py
Tests verify language propagation, English fallback, context-aware prompt selection, and rendered language instructions.

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
Loading

Possibly related issues

  • infiniflow/ragflow#17280: The issue covers language propagation through PDF, DOCX, and XLSX vision wrappers.
  • infiniflow/ragflow#17281: The issue covers equivalent language handling in vision dispatch code.

Possibly related PRs

Suggested reviewers: xugangqiang

Poem

A rabbit carries language through the flow,
Prompts now tell each figure what to show.
Visible words remain just as they were,
Chinese descriptions answer clear.
English waits when no language is supplied.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue #17136 by propagating dataset language and preserving visible text for embedded image descriptions.
Out of Scope Changes check ✅ Passed The XLSX, PDF, logging, and test changes support the stated language-propagation and context-safety objectives.
Title check ✅ Passed The title clearly and concisely describes the main change: propagating dataset language across VisionFigureParser paths.
Description check ✅ Passed The description explains the problem, solution, scope, testing, and linked issue in sufficient detail.

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.

@dosubot dosubot Bot added 🌈 python Pull requests that update Python code 🐞 bug Something isn't working, pull request that fix bug. 🧪 test Pull requests that update test cases. labels Jul 22, 2026

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c6d9f84 and bfbe097.

📒 Files selected for processing (7)
  • deepdoc/parser/figure_parser.py
  • rag/app/naive.py
  • rag/prompts/generator.py
  • rag/prompts/vision_llm_figure_describe_prompt.md
  • rag/prompts/vision_llm_figure_describe_prompt_with_context.md
  • test/unit_test/deepdoc/parser/test_figure_parser.py
  • test/unit_test/rag/prompts/test_vision_figure_prompt.py

Comment thread deepdoc/parser/figure_parser.py Resolved
- Remove raw document context snippets from INFO logs while retaining length metadata
to avoid exposing uploaded content.
@taek105

taek105 commented Jul 22, 2026

Copy link
Copy Markdown
Contributor Author

These raw context snippet logs predated this PR. They have now been removed in commit 6e3f2b7
because they could expose uploaded document content. The context length metadata was retained for diagnostics.

Focused tests: 7 passed. Ruff: all checks passed.

@yingfeng
yingfeng requested a review from xugangqiang July 22, 2026 06:30
@yingfeng yingfeng added the ci Continue Integration label Jul 22, 2026
@codecov

codecov Bot commented Jul 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (6a85d1c) to head (c53e707).
⚠️ Report is 458 commits behind head on main.

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.
📢 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.

@xugangqiang

Copy link
Copy Markdown
Contributor

Thanks for this fix — the approach of controlling output language via the prompt's {{ language }} variable is correct. However, the fix only covers 1 of 4 affected paths. Three other wrappers in the same file have the same bug.

What's fixed

vision_figure_parser_docx_wrapper_naive (the DOCX path in rag/app/naive.py) now correctly propagates lang to VisionFigureParser and the prompt templates.

What's still broken

Wrapper File:Line Callers Callers pass lang?
vision_figure_parser_docx_wrapper deepdoc/parser/figure_parser.py:49 rag/app/book.py:88, rag/app/manual.py:277 No
vision_figure_parser_figure_xlsx_wrapper deepdoc/parser/figure_parser.py:69 rag/app/table.py:83 No
vision_figure_parser_pdf_wrapper deepdoc/parser/figure_parser.py:102 rag/app/naive.py:121 (via by_deepdoc), rag/app/manual.py:258, rag/app/paper.py:174 No

Root cause: Every chunk() function declares lang="Chinese" as a named parameter, so lang is not in **kwargs. The three unmodified wrappers receive **kwargs only, so lang never reaches them. VisionFigureParser.self.language (set via kwargs.get("lang") or "English") always falls back to "English", and the prompt's {{ language }} renders as "English" — even when the dataset language is Chinese.

This means PDF, Excel, book, manual, and paper figure descriptions are still always generated in English.

LLMBundle(lang=lang) is a no-op for figure descriptions

The PR adds lang=lang to LLMBundle(...). This sets self.lang on the CvModel, but self.lang is only read by describe() (rag/llm/cv_model.py:315-326), which uses a hardcoded Chinese/English prompt. The figure parser path calls describe_with_prompt(image, prompt) (rag/llm/cv_model.py:353), which does not read self.lang — it uses the explicit prompt argument.

So the actual language control is entirely through the prompt's {{ language }} variable. The LLMBundle(lang=) call has no effect on figure description output (though it's harmless and useful for consistency / future describe() reuse).

Suggested fix

Add lang as an explicit parameter to the three wrappers (defaulting to "English" for backwards compatibility) and have each caller pass lang=lang:

  • vision_figure_parser_docx_wrapper → book.py:88, manual.py:277
  • vision_figure_parser_figure_xlsx_wrapper → table.py:83 (also need lang forwarded through Excel.__call__ from table.py:408)
  • vision_figure_parser_pdf_wrapper → naive.py:121 (by_deepdoc), manual.py:258, paper.py:174

- 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.
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 23, 2026
@taek105

taek105 commented Jul 23, 2026

Copy link
Copy Markdown
Contributor Author

Addressed in commit 1e1259d.

  • Added an explicit lang parameter, defaulting to English, to the DOCX, XLSX, and PDF
    figure wrappers.
  • Forwarded the dataset language from all Python callers in book.py, manual.py,
    naive.py, paper.py, and table.py.
  • Propagated lang through chunk() → Excel.__call__() → the XLSX figure wrapper.
  • Passed the language to both VisionFigureParser and LLMBundle; the prompt's

Validation: 10 focused tests passed, and Ruff reports no issues.

Thanks for this fix — the approach of controlling output language via the prompt's {{ language }} variable is correct. However, the fix only covers 1 of 4 affected paths. Three other wrappers in the same file have the same bug.

What's fixed

vision_figure_parser_docx_wrapper_naive (the DOCX path in rag/app/naive.py) now correctly propagates lang to VisionFigureParser and the prompt templates.

What's still broken

Wrapper File:Line Callers Callers pass lang?
vision_figure_parser_docx_wrapper deepdoc/parser/figure_parser.py:49 rag/app/book.py:88, rag/app/manual.py:277 No
vision_figure_parser_figure_xlsx_wrapper deepdoc/parser/figure_parser.py:69 rag/app/table.py:83 No
vision_figure_parser_pdf_wrapper deepdoc/parser/figure_parser.py:102 rag/app/naive.py:121 (via by_deepdoc), rag/app/manual.py:258, rag/app/paper.py:174 No
Root cause: Every chunk() function declares lang="Chinese" as a named parameter, so lang is not in **kwargs. The three unmodified wrappers receive **kwargs only, so lang never reaches them. VisionFigureParser.self.language (set via kwargs.get("lang") or "English") always falls back to "English", and the prompt's {{ language }} renders as "English" — even when the dataset language is Chinese.

This means PDF, Excel, book, manual, and paper figure descriptions are still always generated in English.

LLMBundle(lang=lang) is a no-op for figure descriptions

The PR adds lang=lang to LLMBundle(...). This sets self.lang on the CvModel, but self.lang is only read by describe() (rag/llm/cv_model.py:315-326), which uses a hardcoded Chinese/English prompt. The figure parser path calls describe_with_prompt(image, prompt) (rag/llm/cv_model.py:353), which does not read self.lang — it uses the explicit prompt argument.

So the actual language control is entirely through the prompt's {{ language }} variable. The LLMBundle(lang=) call has no effect on figure description output (though it's harmless and useful for consistency / future describe() reuse).

Suggested fix

Add lang as an explicit parameter to the three wrappers (defaulting to "English" for backwards compatibility) and have each caller pass lang=lang:

  • vision_figure_parser_docx_wrapper → book.py:88, manual.py:277
  • vision_figure_parser_figure_xlsx_wrapper → table.py:83 (also need lang forwarded through Excel.__call__ from table.py:408)
  • vision_figure_parser_pdf_wrapper → naive.py:121 (by_deepdoc), manual.py:258, paper.py:174

@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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 1e1259d and c3dc5b1.

📒 Files selected for processing (4)
  • deepdoc/parser/figure_parser.py
  • rag/app/one.py
  • test/unit_test/deepdoc/parser/test_figure_parser.py
  • test/unit_test/rag/app/test_one.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • deepdoc/parser/figure_parser.py

Comment thread rag/app/one.py Resolved
@taek105

taek105 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Hi @xugangqiang, just following up on this PR when you have a chance.

I’ve incorporated the review feedback and completed the language
propagation across all four figure-vision wrappers and their Python call
sites, including the remaining rag/app/one.py DOCX path.

Empty lang values are now normalized to English before reaching
LLMBundle, VisionFigureParser, or the prompt builders, including the
_naive direct-prompt path. I also added focused regression coverage for
the empty-string fallback and the one.py caller.

Following the latest CodeRabbit feedback, the one.py flow now logs the
effective language and image count without exposing document content, with
test coverage for the log record as well.

All 17 focused tests pass, and the PR is ready for another review. Thanks!

@xugangqiang

Copy link
Copy Markdown
Contributor

Thanks for the fix — driving output language through the prompt's {{ language }} variable is the right approach, and the 4 wrappers in deepdoc/parser/figure_parser.py now propagate lang correctly. I did a repo-wide audit and have a few points before this can be considered complete.

Scope gap — two more VisionFigureParser sites are still broken

This PR fixes the 4 wrappers, but a full grep shows two additional direct VisionFigureParser(...) construction sites that still ignore dataset language and fall back to English:

  1. rag/app/naive.py:1171 (Markdown path inside chunk()): VisionFigureParser(vision_model=vision_model, figures_data=[...], **kwargs). Since chunk() declares lang="Chinese" as a named parameter, lang is not in **kwargs, so VisionFigureParser.__init__'s kwargs.get("lang") or "English" always yields "English". The LLMBundle(...) a few lines above also doesn't pass lang. → Markdown-embedded image descriptions are still always English.
  2. rag/flow/parser/utils.py:188 (enhance_media_sections_with_vision): builds VisionFigureParser(..., context_size=0) with no lang at all, and the function has no lang parameter. Its callers (rag/flow/parser/parser.py:772/975/1111) don't forward it either. → Agent-flow image/table section descriptions are still always English.

Because the fix was scoped to the 4 wrappers enumerated earlier rather than a full audit of every VisionFigureParser construction, the original bug persists for Markdown and Agent-flow documents.

Suggested fix (on top of current changes)

  • rag/app/naive.py: pass lang=lang to both LLMBundle(...) and the VisionFigureParser(...) call at line 1171.
  • rag/flow/parser/utils.py: add lang="English" param to enhance_media_sections_with_vision, forward it to LLMBundle/VisionFigureParser, and pass lang from the 3 call sites in parser.py.

Test coverage gaps

  • The wrapper-level and prompt-rendering tests are good (Chinese + empty→English, with/without context).
  • But the rag/app/* callers that forward lang (book/manual/paper/naive-by_deepdoc/table) are only covered for one.py. The most error-prone part — callers forgetting to forward lang — is largely untested.
  • The Markdown and flow paths have no tests at all, which is exactly where the remaining bug lives. Please add lightweight tests asserting each chunk()/flow caller forwards lang to its parser.

No regression risk observed

LLMBundle(lang=...) is signature-compatible and is a no-op for the describe_with_prompt figure path; all callers pass lang explicitly so there's no duplicate-keyword TypeError; the behavior change (descriptions now follow dataset language) is the intended fix.

Question for the author

Would you prefer to:

  • (a) merge this PR as-is and address the Markdown/flow paths plus the caller-forwarding tests in a follow-up PR, or
  • (b) fold those fixes and tests into this PR before merge?

Either is fine, but please don't mark issue #17136 as fully resolved until the Markdown and flow paths are covered.

@taek105

taek105 commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor Author

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.

Thanks for the fix — driving output language through the prompt's {{ language }} variable is the right approach, and the 4 wrappers in deepdoc/parser/figure_parser.py now propagate lang correctly. I did a repo-wide audit and have a few points before this can be considered complete.

Scope gap — two more VisionFigureParser sites are still broken

This PR fixes the 4 wrappers, but a full grep shows two additional direct VisionFigureParser(...) construction sites that still ignore dataset language and fall back to English:

  1. rag/app/naive.py:1171 (Markdown path inside chunk()): VisionFigureParser(vision_model=vision_model, figures_data=[...], **kwargs). Since chunk() declares lang="Chinese" as a named parameter, lang is not in **kwargs, so VisionFigureParser.__init__'s kwargs.get("lang") or "English" always yields "English". The LLMBundle(...) a few lines above also doesn't pass lang. → Markdown-embedded image descriptions are still always English.
  2. rag/flow/parser/utils.py:188 (enhance_media_sections_with_vision): builds VisionFigureParser(..., context_size=0) with no lang at all, and the function has no lang parameter. Its callers (rag/flow/parser/parser.py:772/975/1111) don't forward it either. → Agent-flow image/table section descriptions are still always English.

Because the fix was scoped to the 4 wrappers enumerated earlier rather than a full audit of every VisionFigureParser construction, the original bug persists for Markdown and Agent-flow documents.

Suggested fix (on top of current changes)

  • rag/app/naive.py: pass lang=lang to both LLMBundle(...) and the VisionFigureParser(...) call at line 1171.
  • rag/flow/parser/utils.py: add lang="English" param to enhance_media_sections_with_vision, forward it to LLMBundle/VisionFigureParser, and pass lang from the 3 call sites in parser.py.

Test coverage gaps

  • The wrapper-level and prompt-rendering tests are good (Chinese + empty→English, with/without context).
  • But the rag/app/* callers that forward lang (book/manual/paper/naive-by_deepdoc/table) are only covered for one.py. The most error-prone part — callers forgetting to forward lang — is largely untested.
  • The Markdown and flow paths have no tests at all, which is exactly where the remaining bug lives. Please add lightweight tests asserting each chunk()/flow caller forwards lang to its parser.

No regression risk observed

LLMBundle(lang=...) is signature-compatible and is a no-op for the describe_with_prompt figure path; all callers pass lang explicitly so there's no duplicate-keyword TypeError; the behavior change (descriptions now follow dataset language) is the intended fix.

Question for the author

Would you prefer to:

  • (a) merge this PR as-is and address the Markdown/flow paths plus the caller-forwarding tests in a follow-up PR, or
  • (b) fold those fixes and tests into this PR before merge?

Either is fine, but please don't mark issue #17136 as fully resolved until the Markdown and flow paths are covered.

@taek105 taek105 changed the title fix: honor dataset language for DOCX image descriptions fix: honor dataset language across VisionFigureParser paths Aug 5, 2026
@taek105

taek105 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

@xugangqiang
Thanks again for the thorough audit. I’ve completed the remaining changes for #17136, including the Markdown and agent-flow language propagation, caller-forwarding coverage, and the empty-string fallback to English. The focused suite passes with 27 tests, and all CI checks are passing.

During the final repo-wide audit, I also found that MinerU’s separate PDF image-enrichment path calls vision_llm_figure_describe_prompt() directly without forwarding lang. This path bypasses VisionFigureParser and is separate from the General-parser DOCX issue addressed by this PR. so I think it would be better to track this separately as a follow-up issue rather than expand the scope of this PR.

Could you take another look when convenient? Thanks!

@xugangqiang

Copy link
Copy Markdown
Contributor

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:

  • deepdoc/parser/mineru_parser.py:897 — MinerU image enrichment calls vision_llm_figure_describe_prompt() directly without forwarding lang (this bypasses VisionFigureParser).
  • deepdoc/parser/mistral_parser.py:329 — Mistral parser calls vision_llm_figure_describe_prompt() directly without lang.

Please mention this PR (#17227) in that issue so the linkage is clear. Once the issue is created I'll go ahead and merge.

@taek105

taek105 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Sure! I’ve opened #17885 to track the remaining MinerU and Mistral language-propagation paths.

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:

  • deepdoc/parser/mineru_parser.py:897 — MinerU image enrichment calls vision_llm_figure_describe_prompt() directly without forwarding lang (this bypasses VisionFigureParser).
  • deepdoc/parser/mistral_parser.py:329 — Mistral parser calls vision_llm_figure_describe_prompt() directly without lang.

Please mention this PR (#17227) in that issue so the linkage is clear. Once the issue is created I'll go ahead and merge.

@xugangqiang
xugangqiang merged commit b7966c9 into infiniflow:main Aug 5, 2026
3 checks passed
@taek105
taek105 deleted the fix/17136-docx-image-language branch August 5, 2026 13:53
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Aug 6, 2026
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.
yuzhichang added a commit to yuzhichang/ragflow that referenced this pull request Aug 6, 2026
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
Harsh23Kashyap added a commit to Harsh23Kashyap/ragflow that referenced this pull request Aug 20, 2026
…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).
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 🌈 python Pull requests that update Python code size:L This PR changes 100-499 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] DOCX embedded image descriptions ignore dataset language and are generated in English

3 participants