Skip to content

fix(rag): identify DOCX images by relationship type - #44905

Merged
crazywoola merged 3 commits into
langgenius:mainfrom
Winoren:fix/docx-image-relationship-types
Oct 30, 2026
Merged

crazywoola merged 3 commits into
langgenius:mainfrom
Winoren:fix/docx-image-relationship-types

Conversation

@Winoren

@Winoren Winoren commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #44904.

DOCX knowledge ingestion silently loses an embedded picture when its valid image relationship points to media/logo.png, because the extractor requires the target name to contain image. The same name check also stores non-image XML parts whose target happens to contain that substring.

Select image relationships by python-docx's RT.IMAGE constant. Existing storage, persistence, and Markdown rendering paths remain responsible for handling the selected images.

Regression tests save and reload actual DOCX files, exercise WordExtractor.extract() with real filesystem storage and SQLite sessions, and verify:

  • image1.png, logo.png, and Logo.PNG produce an image link in paragraph order and store the original PNG bytes.
  • A custom-XML relationship targeting image-metadata.xml creates neither an image asset nor an UploadFile row.

One additional lockfile metadata line is refreshed to match the existing dify-agent Pillow constraint. No locked package version changes. This is the same upstream stale metadata that the repository's autofix bot corrected on #44903; it prevents CI's lock check from failing before tests run.

Validation

  • Before the production fix: 3 failed, 20 passed in the Word extractor suite. The ordinary image1.png control passes; the two alternative names and non-image relationship fail.
  • After the fix: 71 passed across the Word extractor and extraction-dispatch suites.
  • make lint: passed, including all 75 import contracts.
  • make type-check PATH_TO_CHECK=api/core/rag/extractor/word_extractor.py: passed.
  • Explicit strict Pyrefly checking of the test module reports the same 71 existing diagnostics as the unchanged baseline, with zero new diagnostics. The repository already excludes this module from its strict unit-test project; this PR does not change that exclusion.
  • uv 0.13.6 lock --project api --check and git diff --check: passed.

These results are local verification of the actual extractor and its dependencies, not a deployed knowledge-base ingestion or a remote CI result.

Checklist

  • This change requires a documentation update, included: Dify Document (not required)
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've verified the change and added or updated tests where meaningful regression risk justifies coverage.
  • I've updated the documentation accordingly. (no public API change)
  • I ran make lint && make type-check (backend) and vp staged (frontend) to appease the lint gods. (backend lint and scoped production type check; no frontend changes)

AI assistance was used for investigation, implementation, and verification; the actual results and the pre-existing typing limitation are recorded above.

From Codex

@Winoren
Winoren requested a review from a team October 27, 2026 16:28
@github-actions github-actions Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 27, 2026
@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Diff

base → PR
--- /tmp/pyrefly_base.txt	2026-10-30 04:38:56.044442066 +0000
+++ /tmp/pyrefly_pr.txt	2026-10-30 04:38:37.296468900 +0000
@@ -4303,7 +4303,7 @@
 ERROR Object of class `NoneType` has no attribute `strip` [missing-attribute]
   --> tests/unit_tests/core/rag/extractor/test_markdown_extractor.py:30:16
 ERROR `_CloseRecorder` is not assignable to attribute `temp_file` with type `_TemporaryFileWrapper[bytes]` [bad-assignment]
-   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:397:27
+   --> tests/unit_tests/core/rag/extractor/test_word_extractor.py:399:27
 ERROR Object of class `NoneType` has no attribute `indexing_status` [missing-attribute]
    --> tests/unit_tests/core/rag/index_processor/test_index_processor.py:240:16
 ERROR Object of class `FunctionType` has no attribute `return_value` [missing-attribute]

@github-actions

github-actions Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 81.40% 81.40% +0.00%
Strict coverage 81.10% 81.10% +0.00%
Typed symbols 83,169 83,181 +12
Untyped symbols 19,079 19,079 0
Modules 4240 4240 0

@codecov

codecov Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.67%. Comparing base (9e20db9) to head (76f2e7d).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main   #44905       +/-   ##
===========================================
+ Coverage   68.68%   89.67%   +20.98%     
===========================================
  Files        6083     6149       +66     
  Lines      367753   390569    +22816     
  Branches    77976    77656      -320     
===========================================
+ Hits       252597   350238    +97641     
+ Misses     112353    34029    -78324     
- Partials     2803     6302     +3499     
Flag Coverage Δ
api 89.63% <100.00%> (+37.77%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Reviewed the complete diff, relationship selection, internal/external image handling, storage/session ownership, and Markdown rendering. No issues found.

Validated on this head: 71 Word extractor and extraction-dispatch tests passed, including saved/reloaded DOCX files with image1.png, logo.png, and Logo.PNG, original stored image bytes, paragraph ordering, and rejection of non-image XML relationships. Ruff check and format check passed. Current backend unit, controller, integration, and Python-style CI checks are green.

@JohnJyong
JohnJyong enabled auto-merge October 28, 2026 17:00
@crazywoola
crazywoola added this pull request to the merge queue Oct 30, 2026
Merged via the queue into langgenius:main with commit 04aee9d Oct 30, 2026
47 checks passed
@laipz8200 laipz8200 mentioned this pull request Nov 3, 2026
1 task done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DOCX extraction silently drops embedded images without image in their part name

3 participants