Skip to content

fix(multimodal): collect all surrounding text as context instead of o… - #136

Merged
XiaoBoAI merged 3 commits into
mainfrom
fix/image-grader-context-extraction
Mar 5, 2026
Merged

fix(multimodal): collect all surrounding text as context instead of o…#136
XiaoBoAI merged 3 commits into
mainfrom
fix/image-grader-context-extraction

Conversation

@XiaoBoAI

@XiaoBoAI XiaoBoAI commented Mar 5, 2026

Copy link
Copy Markdown
Collaborator

…nly the nearest segment

Previously, get_image_context only picked the single text item immediately adjacent to the image (via break). When users placed the image at the end of the response list (e.g. after a task description + source + target), context_above would contain only the last string (often a single word like "Off" or "Custom") while the task description was silently dropped. This caused ImageCoherenceGrader and ImageHelpfulnessGrader to receive near-empty context, resulting in unstable and severely low scores (1–2) for the same content that scored 5 when the image was placed first.

The fix concatenates all text segments before/after the image, ensuring task instructions and surrounding content are always fully passed to the model regardless of image position.

Made-with: Cursor

OpenJudge Version

[The version of OpenJudge you are working on, e.g. import openjudge; print(openjudge.__version__)]

Description

[Please describe the background, purpose, changes made, and how to test this PR]

Checklist

Please check the following items before code is ready to be reviewed.

  • Code has been formatted with pre-commit run --all-files command
  • All tests are passing
  • Docstrings are in Google style
  • Related documentation has been updated (e.g. links, examples, etc.)
  • Code is ready for review

…nly the nearest segment

Previously, `get_image_context` only picked the single text item
immediately adjacent to the image (via `break`). When users placed
the image at the end of the `response` list (e.g. after a task
description + source + target), `context_above` would contain only
the last string (often a single word like "Off" or "Custom") while the
task description was silently dropped. This caused `ImageCoherenceGrader`
and `ImageHelpfulnessGrader` to receive near-empty context, resulting in
unstable and severely low scores (1–2) for the same content that scored 5
when the image was placed first.

The fix concatenates all text segments before/after the image,
ensuring task instructions and surrounding content are always fully
passed to the model regardless of image position.

Made-with: Cursor
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the context extraction mechanism for multimodal graders. The change ensures that when processing content containing images, all relevant textual information preceding and following an image is captured and provided as context. This enhancement addresses an issue where previously only immediate text segments were considered, leading to incomplete context and negatively impacting the accuracy and stability of image-related grading.

Highlights

  • Context Collection Logic: Modified the get_image_context function to collect and concatenate all text segments surrounding an image, rather than stopping at the first adjacent segment.
  • Grader Accuracy Improvement: Ensures that multimodal graders like ImageCoherenceGrader and ImageHelpfulnessGrader receive complete task instructions and surrounding content, preventing unstable and low scores caused by truncated context.
Changelog
  • openjudge/graders/multimodal/_internal/context_utils.py
    • Updated the get_image_context function to aggregate all text segments before and after an image, joining them with newlines.
Activity
  • No specific activity (comments, reviews, progress) has been recorded for this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist 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.

Code Review

The pull request refactors the get_image_context function to collect all surrounding text segments for improved context for multimodal graders, leading to more stable and accurate evaluations. However, this change increases the surface area for prompt injection attacks as the extracted context is directly formatted into LLM prompts without sanitization, potentially allowing malicious user input to manipulate the grading process. Additionally, an edge case regarding max_context_size needs attention to ensure correct behavior.

Comment thread openjudge/graders/multimodal/_internal/context_utils.py Outdated
Comment thread openjudge/graders/multimodal/_internal/context_utils.py
XiaoBoAI added 2 commits March 5, 2026 19:48
…le zero value correctly

`max_context_size=0` should truncate context to empty, but the previous
`and max_context_size` truthiness check treats 0 as False, silently
skipping truncation. Switching to `is not None` ensures the limit is
always respected, including when explicitly set to 0.

Also applies black formatting.

Made-with: Cursor
…context_size=0

`context[-0:]` returns the full string rather than an empty string,
so `max_context_size=0` must be handled as a special case explicitly.

Made-with: Cursor
@XiaoBoAI
XiaoBoAI merged commit 6f1324b into main Mar 5, 2026
2 checks passed
@XiaoBoAI
XiaoBoAI deleted the fix/image-grader-context-extraction branch March 9, 2026 12:42
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.

3 participants