Skip to content

fix(deepdoc): propagate dataset language through all 4 figure-vision wrappers - #17677

Closed
Harsh23Kashyap wants to merge 0 commit into
infiniflow:mainfrom
Harsh23Kashyap:fix/figure-parser-lang-all-wrappers
Closed

Harsh23Kashyap wants to merge 0 commit into
infiniflow:mainfrom
Harsh23Kashyap:fix/figure-parser-lang-all-wrappers

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

fix(deepdoc): propagate dataset language through all 4 figure-vision wrappers

Fixes #17280. Supersedes the partial PR #17227 (still OPEN, never landed).

Problem

PR #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

Wrapper File:Line Callers (pass lang=lang)
vision_figure_parser_docx_wrapper deepdoc/parser/figure_parser.py:49 rag/app/book.py:89, rag/app/manual.py:286
vision_figure_parser_figure_xlsx_wrapper deepdoc/parser/figure_parser.py:69 rag/app/table.py:83 (also forward lang through Excel.__call__)
vision_figure_parser_pdf_wrapper deepdoc/parser/figure_parser.py:102 rag/app/naive.py:122 (by_deepdoc), rag/app/manual.py:267, rag/app/paper.py:183
vision_figure_parser_docx_wrapper_naive deepdoc/parser/figure_parser.py:144 rag/app/naive.py:1031, rag/app/one.py:86

Root cause

Every chunk() function in rag/app/{book,manual,naive,one,paper,table}.py 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".

Fix

This PR also picks up the supporting changes that PR #17227 introduced for the _naive wrapper (since PR #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 a ## OUTPUT LANGUAGE section that uses {{ language }}.

Files changed

File Change
deepdoc/parser/figure_parser.py Add lang="English" to 4 wrappers; VisionFigureParser.__init__ stores self.language; __call__ worker passes language=self.language to both prompt functions
rag/app/book.py Pass lang=lang to vision_figure_parser_docx_wrapper
rag/app/manual.py Pass lang=lang to both wrapper calls
rag/app/naive.py Pass lang=lang to vision_figure_parser_pdf_wrapper (in by_deepdoc) and vision_figure_parser_docx_wrapper_naive
rag/app/one.py Pass lang=lang to vision_figure_parser_docx_wrapper_naive
rag/app/paper.py Pass lang=lang to vision_figure_parser_pdf_wrapper
rag/app/table.py Pass lang=lang to vision_figure_parser_figure_xlsx_wrapper; Excel.__call__ accepts and forwards lang
rag/prompts/generator.py vision_llm_figure_describe_prompt(language=...) and vision_llm_figure_describe_prompt_with_context(..., language=...) accept the argument
rag/prompts/vision_llm_figure_describe_prompt.md Add ## OUTPUT LANGUAGE section with {{ language }}
rag/prompts/vision_llm_figure_describe_prompt_with_context.md Add ## OUTPUT LANGUAGE section with {{ language }}
test/unit_test/deepdoc/parser/test_figure_parser.py New test file, 15 tests

Diff: 11 files changed, 67 insertions(+), 23 deletions(-).

Tests

15 p0 tests, three layers:

  • TestPromptLanguageVariable (4) -- the figure-description prompt functions accept a language argument and render {{ language }} in the prompt (default "English", Chinese / Japanese when passed).
  • TestVisionFigureParserLanguage (3) -- VisionFigureParser stores self.language from the lang kwarg, defaults to "English" when omitted, falls back on empty string.
  • TestDocxWrapperForwardsLang (2), TestXlsxWrapperForwardsLang (1), TestPdfWrapperForwardsLang (1), TestNaiveDocxWrapperForwardsLang (2) -- each of the 4 wrappers forwards lang to both LLMBundle and VisionFigureParser. The _naive wrapper additionally forwards language=lang to both prompt functions in its per-chunk worker (with and without context).
  • TestPromptReceivesParserLanguage (2) -- end-to-end: VisionFigureParser.__call__ passes self.language to the prompt functions in its process worker.

All 15 tests pass locally:

$ .venv/bin/python -m pytest test/unit_test/deepdoc/parser/test_figure_parser.py -v
============================== 15 passed in 3.42s ==============================

Lint / format

$ ruff check <all 11 files>
All checks passed!

$ ruff format --check <all 11 files>
1 file already formatted

Out of scope

LLMBundle(lang=) does not currently affect figure descriptions (the prompt {{ language }} is what controls the output language -- describe_with_prompt() in rag/llm/cv_model.py:353 does not read self.lang). LLMBundle(lang=lang) is still passed here for consistency with the non-figure LLM call sites.

Notes

PR #17227 (a prior partial fix for the same problem) is still OPEN. This PR is a strict superset: it covers all 4 wrappers (vs PR #17227's 1 wrapper) and includes the supporting prompt + VisionFigureParser.__init__ changes that PR #17227 needs. When this PR lands, #17227 should be closed as superseded.

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

coderabbitai Bot commented Aug 1, 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: 12877ccd-74ae-4c8e-b5d5-623f7d80d0c8

📥 Commits

Reviewing files that changed from the base of the PR and between 5aa22ee and 12a3ab2.

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

📝 Walkthrough

Walkthrough

Figure parsing now accepts document language through DOCX, PDF, and Excel paths. Vision wrappers, model bundles, parser instances, and prompts propagate the language. Prompt templates define translated generated fields while preserving visible text. Regression tests cover defaults, forwarding, and prompt rendering.

Changes

Figure language propagation

Layer / File(s) Summary
Language-aware figure prompts
rag/prompts/generator.py, rag/prompts/vision_llm_figure_describe_prompt*.md
Prompt helpers accept language. Templates use it for generated descriptions and field values while preserving visible text and field names.
Vision parser language flow
deepdoc/parser/figure_parser.py
Vision wrappers and VisionFigureParser accept language values, pass them to LLMBundle, and include them in prompt rendering.
Application language forwarding
rag/app/book.py, rag/app/manual.py, rag/app/naive.py, rag/app/one.py, rag/app/paper.py, rag/app/table.py
DOCX, PDF, and Excel parsing paths forward the selected language to figure processing.
Language propagation regression tests
test/unit_test/deepdoc/parser/test_figure_parser.py
Tests cover prompt rendering, defaults, wrapper forwarding, naive DOCX processing, and end-to-end parser behavior.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Mergeability Score: ⚪ Minimal · up to 12a3a

This change propagates dataset language through all figure-description paths and reports passing targeted tests and checks; no actionable merge-blocking risk remains beyond normal review.

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant FigureWrapper
  participant LLMBundle
  participant VisionFigureParser
  participant PromptGenerator
  Application->>FigureWrapper: pass document language
  FigureWrapper->>LLMBundle: initialize with language
  FigureWrapper->>VisionFigureParser: construct with language
  VisionFigureParser->>PromptGenerator: render figure prompt with language
Loading

Possibly related PRs

  • infiniflow/ragflow#18188 — Propagates dataset language into related figure-description prompts through a different parser path.

Poem

I’m a rabbit with prompts in my den,
Passing language from caller to pen.
Figures now speak as settings decree,
While visible words stay as we see.
Tests hop beside every flow—
Language travels where figures go.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.43% 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
Title check ✅ Passed The title clearly identifies the main change: language propagation through all four DeepDoc figure-vision wrappers.
Description check ✅ Passed The description provides clear background, affected paths, root cause, implementation details, tests, and scope information.
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.
✨ Finishing Touches 💡 1
⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch fix/figure-parser-lang-all-wrappers

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.

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 49-80: Normalize the lang parameter at the start of both vision
figure wrapper functions, vision_figure_parser_docx_wrapper and
vision_figure_parser_figure_xlsx_wrapper, so empty values fall back to
"English". Use the normalized lang for every LLMBundle, VisionFigureParser, and
figure-prompt call in these wrappers.
🪄 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 Plus

Run ID: 60ec27c7-30a7-4ce3-a239-e036ccbcb5ce

📥 Commits

Reviewing files that changed from the base of the PR and between 26a5af8 and 5aa22ee.

📒 Files selected for processing (11)
  • deepdoc/parser/figure_parser.py
  • rag/app/book.py
  • rag/app/manual.py
  • rag/app/naive.py
  • rag/app/one.py
  • rag/app/paper.py
  • rag/app/table.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

Comment thread deepdoc/parser/figure_parser.py Resolved
@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (776b937) to head (5aa22ee).
⚠️ Report is 112 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #17677      +/-   ##
==========================================
- 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

Before merging, please: 1) apply CodeRabbit's lang normalization across all 4 wrappers (especially _naive, where language=lang is passed directly), and 2) add a test covering the empty-string lang fallback.

Harsh23Kashyap added a commit to Harsh23Kashyap/ragflow that referenced this pull request Aug 13, 2026
…on wrappers

Per @xugangqiang's review on infiniflow#17677: the wrappers' lang="English"
default is bypassed when an empty string is forwarded (the default only
fires when the kwarg is missing). Apply the same 'lang = lang or default'
normalization at the wrapper boundary in all 4 figure-vision wrappers
(docx, xlsx, pdf, naive), so the figure-description prompt always gets a
real language and the dataset's empty-language fallback is never
silently dropped.

Adds 4 new test cases (one per wrapper) covering the empty-string
fallback.
@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Both done in 12a3ab2 (force-pushed over the previous tip).

  1. lang normalization across all 4 wrappers — added lang = lang or "English" at the entry of vision_figure_parser_docx_wrapper, vision_figure_parser_figure_xlsx_wrapper, vision_figure_parser_pdf_wrapper, and vision_figure_parser_docx_wrapper_naive. The empty string now falls back to the default at the wrapper boundary instead of bypassing it. This mirrors the same lang = lang or "Chinese" pattern that already exists in rag/app/naive.py:957 at the parent chunk() level — the wrappers just weren't doing the equivalent.

  2. Empty-string test — added one test_empty_string_lang_falls_back_to_english per wrapper (4 total), mirroring the existing test_lang_defaults_to_english_when_omitted shape. All 19 tests in test/unit_test/deepdoc/parser/test_figure_parser.py pass locally.

One scope note for review: the language=lang calls in rag/app/naive.py (lines 1036, 1092, 1114, 1184, 1283, 1285, 1293) that go to doc_tokenize_chunks_with_images / tokenize_table / tokenize_chunks* are downstream of the parent lang = lang or "Chinese" normalization on line 957, so they receive "Chinese" (or whatever the dataset language is) and don't have the same empty-string-bypass bug. I left them out of scope; happy to extend the normalization to those if you want it, but they look like they're already correct via the parent chunk() guard.

@JinHai-CN

Copy link
Copy Markdown
Member

@Harsh23Kashyap Would you please resolve the conflicts?

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator Author

Cherry-picked the commits onto current upstream/main and force-pushed. Lang normalization applied across all 4 wrappers; test for empty-string lang stays. Ready for your review pass.

@Harsh23Kashyap
Harsh23Kashyap force-pushed the fix/figure-parser-lang-all-wrappers branch from 12a3ab2 to c87aa3b Compare August 20, 2026 12:43
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Aug 20, 2026
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:XS This PR changes 0-9 lines, ignoring generated files. 🧪 test Pull requests that update test cases.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Figure description language not propagated to PDF/DOCX(book,manual)/XLSX vision wrappers

3 participants