Skip to content

fix(image): keep longest-edge resize dimensions nonzero - #761

Open
JesusMan0529 wants to merge 2 commits into
qdrant:mainfrom
JesusMan0529:fix/nonzero-image-resize
Open

JesusMan0529 wants to merge 2 commits into
qdrant:mainfrom
JesusMan0529:fix/nonzero-image-resize

Conversation

@JesusMan0529

Copy link
Copy Markdown

A 4096 x 1 or 1 x 4096 image resized to a longest edge of 2048 currently truncates its shorter edge to zero. Pillow raises ValueError: height and width must be > 0, including when the image goes through ColModernVBERT's Idefics3 preprocessing.

Clamp the final resize dimensions to at least one pixel, matching Idefics3's reference behavior. Tests cover both orientations, existing even rounding and ordinary images, plus the real Compose pipeline with image splitting, rescaling and normalization.

Validation:

  • The added image tests on an immutable copy of the original package: 4 failed, 15 passed; the four failures reproduce the zero-dimension exception.
  • pytest tests/test_image_transform.py tests/test_common.py tests/test_postprocess.py::test_empty_multivectors_raise_value_error -q: 27 passed.
  • Pinned pre-commit hooks on both changed files, repository-wide Ruff lint, the CI mypy command, pyright tests/type_stub.py, and git diff --check: passed.
  • Repository-wide ruff format --check . reports three unchanged files (experiments/attention_export.py, experiments/try_attention_export.py, tests/test_postprocess.py); both modified files pass formatting. The full model-download/inference suite was not completed locally.

All submissions:

Copilot AI balanced review requested due to automatic review settings October 3, 2026 10:15
@JesusMan0529
JesusMan0529 requested a review from joein as a code owner October 3, 2026 10:15

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 413bda9b-1926-4d2a-a87d-f33f53957046
📥 Commits

Reviewing files that changed from the base of the PR and between b002a50 and 06e4cce.

📒 Files selected for processing (2)
  • fastembed/image/transform/functional.py
  • tests/test_image_transform.py
🚧 Files skipped from review as they are similar to previous changes (2)
  • fastembed/image/transform/functional.py
  • tests/test_image_transform.py

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.


📝 Walkthrough

Walkthrough

resize_longest_edge clamps each resized dimension to at least one pixel. Tests check the 2048-pixel longest-edge cap, nonzero output dimensions, even-rounded dimensions, and Idefics3 preprocessing for very thin images.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~8 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 06e4c

The thin-image resize fix has no identified merge-blocking issue. Normal checks remain appropriate before merging.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing longest-edge resizing from producing zero-sized dimensions.
Description check ✅ Passed The description explains the zero-dimension issue, the fix, the tests, and the reported validation results. It is directly related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 80.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 2 files.
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
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@JesusMan0529

Copy link
Copy Markdown
Author

Reproduced the crash in both orientations (4096 x 1 and 1 x 4096) using the real ColModernVBERT preprocessing config. The original package fails four regression cases; after the fix, the shorter edge stays at one pixel and preprocessing produces five normalized 3 x 512 x 512 patches per image. The dimensions also match the Idefics3 reference.

Local validation: 27 related tests passed, both pinned pre-commit hooks passed, repository-wide Ruff lint and the CI mypy/pyright commands passed. The root formatting check reports three unchanged files; full model-download/inference tests were not completed locally.

@JesusMan0529

Copy link
Copy Markdown
Author

Added concise docstrings to resize_longest_edge and both new regression-test functions to address the docstring-coverage warning. This follow-up adds only three docstring lines; comparing the executable AST before and after confirms that behavior is unchanged. The 27 related tests and both pinned Ruff pre-commit hooks pass again.

@JesusMan0529

Copy link
Copy Markdown
Author

Hope it could be merged 😊

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants