Description of the Bug
In backend/app/rag/vision.py, the function caption_image is defined twice:
- First definition (approx line 178):
def caption_image(image_bytes: bytes, page: Optional[int] = None) -> str
- Second definition (approx line 185):
def caption_image(image_bytes: bytes | List[bytes], page: int | List[int] | None = None) -> str | List[str]
In Python, when a function is defined twice in the same module, the second definition completely replaces the first. The second definition has a different signature (accepting single or batch inputs) with its own inline OpenAI implementation.
This means:
- The first simpler signature is entirely dead code
- The second version duplicates logic that should have been in the first version
- The
_openai_caption helper function (defined earlier at line ~149) is defined but never called — the second caption_image has its own inline OpenAI code instead
- The function has two code paths doing essentially the same thing in different ways
This looks like an unresolved merge conflict or a refactoring mistake.
Steps to Reproduce
- Read
backend/app/rag/vision.py
- Observe that
caption_image appears twice (lines ~178 and ~185)
- In Python, the second definition is the only one that exists at runtime
- Note that
_openai_caption (line ~149) is never called anywhere
Expected Behavior
There should be a single consolidated caption_image function. The batch logic and single-image logic should be merged. The _openai_caption helper should either be used or removed.
Affected File
backend/app/rag/vision.py (lines ~178-184 and lines ~185+)
Suggested Fix
Consolidate into a single function. Either:
- Keep the batch-aware signature and remove the first definition entirely, or
- Keep the first simple signature and have
_openai_caption handle both single and batch cases
Also remove _openai_caption if unused, or refactor the duplicate inline code to use it.
GSSoC '26
Description of the Bug
In
backend/app/rag/vision.py, the functioncaption_imageis defined twice:def caption_image(image_bytes: bytes, page: Optional[int] = None) -> strdef caption_image(image_bytes: bytes | List[bytes], page: int | List[int] | None = None) -> str | List[str]In Python, when a function is defined twice in the same module, the second definition completely replaces the first. The second definition has a different signature (accepting single or batch inputs) with its own inline OpenAI implementation.
This means:
_openai_captionhelper function (defined earlier at line ~149) is defined but never called — the secondcaption_imagehas its own inline OpenAI code insteadThis looks like an unresolved merge conflict or a refactoring mistake.
Steps to Reproduce
backend/app/rag/vision.pycaption_imageappears twice (lines ~178 and ~185)_openai_caption(line ~149) is never called anywhereExpected Behavior
There should be a single consolidated
caption_imagefunction. The batch logic and single-image logic should be merged. The_openai_captionhelper should either be used or removed.Affected File
backend/app/rag/vision.py(lines ~178-184 and lines ~185+)Suggested Fix
Consolidate into a single function. Either:
_openai_captionhandle both single and batch casesAlso remove
_openai_captionif unused, or refactor the duplicate inline code to use it.GSSoC '26