Skip to content

fix(rag): keep scanned pages readable and read them with a model the PC has - #6261

Merged
kovtcharov-amd merged 7 commits into
amd:mainfrom
kovtcharov:kalin/keep-scans-readable
Nov 1, 2026
Merged

kovtcharov-amd merged 7 commits into
amd:mainfrom
kovtcharov:kalin/keep-scans-readable

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Nov 1, 2026 •

Copy link
Copy Markdown
Contributor

Scanned pages were shrunk until the text couldn't be read, so dense Arabic contracts lost up to all of their words, and indexing asked for a vision model gaia init never downloads. Pages now keep their resolution, reading 92–96% of words on five dense real pages, up from 0–93% depending on the model.

Indexing now uses a tested vision model that's already loaded, then the chat model if it can read images, then Gemma. A PC running a text-only chat model switches to Gemma, the smaller choice. Gemma alone would have made indexing about 4 times slower, so images are now read only on pages with under 200 characters of their own text. Of 310 images read across seven documents, 252 gave no text, and pages short of text held 90% of what was gained. A 229-page report drops from 30 minutes to seconds of extraction, and scans still read in full. The cost: charts and text inside pictures on text-heavy pages can't be searched.

Refs #6166

Test plan

  • python -m pytest tests/unit/rag
  • Index a scanned Arabic PDF on a PC without Qwen3-VL and ask about a number on a dense page

…PC has

Scanned Arabic pages were shrunk until the text was unreadable, so the vision
model returned little or nothing and those pages couldn't be searched. Images
now keep their resolution within the model's limits.

Indexing also uses the PC's chat model when it can read images, so a 64 GB PC
running Qwen3.6 doesn't need Gemma downloaded just to read a scan.
A PC running Qwen3.6 with Gemma configured for vision swapped models to read
each scan, evicting chat. A tested vision model already in memory is now used
as it is; a text-only chat model is passed over for Gemma, which is smaller.
@github-actions github-actions Bot added documentation Documentation changes devops DevOps/infrastructure changes rag RAG system changes llm LLM backend changes tests Test changes performance Performance-critical changes labels Nov 1, 2026
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Verdict: Request changes. One lint failure and a docs claim that's wrong for some users; the code change itself is sound.

Scanned pages no longer get halved until small print is unreadable. They now switch to JPEG at full resolution. Indexing also stops asking for a vision model gaia init never downloads: it uses whichever tested vision model is already loaded. Both changes are good. Two things need fixing before merge:

  • CI lint will fail. The PowerPoint helper still imports a module it no longer uses, and flake8's unused-import check is on. Delete the import.
  • The chat guide now says "nothing else is needed", and that's not true for everyone. When a user sets a text-only default_model, gaia init skips Gemma. Indexing still falls back to Gemma, so their scans fail. The PR also deletes the "download Gemma yourself" instructions, so the next bullet's "fails with these instructions" now points at nothing. Put the download step back for that case.

Real-world evidence

N/A: no evidence bundle was produced for this run, and the PR description shows no real indexing run. This verdict comes from reading the code only. The PR's own test plan item, indexing a scanned Arabic PDF on a PC without Qwen3-VL, is still worth doing before merge, because it's the cold-start path this fix targets.

🔍 Technical details

🟡 Unused io import fails flake8 F401 (src/gaia/rag/pptx_utils.py:14)
The only use of io.BytesIO was in the removed PIL block. util/lint.py runs flake8 without ignoring F401.

import logging

(i.e. delete the import io line.)

🟡 Docs say nothing else is needed, but a text-only default_model leaves Gemma undownloaded (docs/guides/chat.mdx:166)
resolve_default_vision_model() returns DEFAULT_MODEL_NAME for a text-only or cloud default_model, such as the LFM2-8B-A1B-GGUF and fireworks.* cases in the new test. gaia init doesn't download Gemma once default_model is set (see CLAUDE.md, Default Models). Those users hit a VLM-unavailable error, and the doc now has no remedy. The image-files bullet's "fails with these instructions" also lost the instructions it pointed to. Restore a short "if your default_model can't read images, download Gemma (lemonade pull Gemma-4-E4B-it-GGUF or gaia download --agent vlm)" line.

🟢 Exact-string match misses user.-prefixed residents (src/gaia/llm/lemonade_client.py:438-439)
FLASH_OPTION_MODEL_NAME is user.Qwen3.8-Flash-Next-GGUF, but /health may list it without the prefix. _model_ids_match exists for exactly this. Using it here, and in the configured not in VISION_CHAT_MODELS check, keeps the resident Flash model from being missed, which would otherwise trigger an eviction and a Gemma load.

🟢 An explicit RAGConfig(vlm_model="Gemma-4-E4B-it-GGUF") is silently swapped for a resident Qwen3.6 (lemonade_client.py:429)
The function's docstring says a model chosen on purpose "stays", but that only holds for models outside the set. If that's intended, consider saying so in the RAGConfig.vlm_model comment.

🟢 One /health round-trip per image (src/gaia/rag/sdk.py:2466)
_extract_text_from_image resolves the resident model on every call. That's cheap, but it could be resolved once per indexing pass, as the PDF/PPTX paths already do.

Strengths

  • The PPTX path now reuses prepare_image_for_vlm instead of a copy-pasted compressor, so PDF and slide images can't drift apart again.
  • The tests decode the actual output bytes and check format, size and RGBA-to-white handling, not just the returned dict.
  • The unreachable-server path logs and keeps the configured model, and VLMClient.check_availability still raises the actionable error, so nothing is silently swallowed.

Indexing sent every image to the vision model, about 22 seconds each, so a 229-page report took 30 minutes. Of 310 images read across seven documents, 252 gave no text, and pages with under 100 characters held 90% of what was gained.

Images are now read on pages with under 200 characters of their own text, which still covers scans. Charts on text-heavy pages are left unread, and the document's metadata counts those pages.
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

🟡 The new "skip images on text pages" rule drops content users can search today, and the chat guide doesn't say so. Any PDF page with 200 or more characters of its own text no longer has its images read. That covers the usual report page with a chart or diagram, so chart labels, figure text and screenshots on those pages stop being indexed. The rule is in the SDK spec, but the user guide still reads as if every image in a PDF is read whenever a vision model is available. The only trace is a count in the metadata and a log line.

Add a line to the chat guide that says which images are skipped. Consider also adding a RAGConfig setting that turns the skip off, for people who need figures indexed.

🔍 Technical details
  • src/gaia/rag/sdk.py:1464: read_images = len(pypdf_text.strip()) < IMAGE_PAGE_TEXT_LIMIT gates every page with images, and nothing in config can override it.
  • docs/guides/chat.mdx (the PDF/PPTX bullet under "Document Indexing Requirements") is the user-facing place for the new behaviour. docs/spec/rag-sdk.mdx already describes it.
  • PPTX slides aren't gated, so after this change PDF and slide images behave differently.

The chat guide read as if every image were read whenever a vision model is available.
…Gemma download step

The new image-page tests built their PDFs with PyMuPDF, which GAIA bans (AGPL) and no lane installs, so they skipped everywhere and failed the unit lane's skip check. They now build PDFs with reportlab, like the other PDFium tests.

The chat guide said nothing else is needed for the VLM, but gaia init skips Gemma when the user sets a default_model, so a text-only one leaves scans unreadable. The download step is back for that case.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Nov 1, 2026
Merged via the queue into amd:main with commit 1c0ceb3 Nov 1, 2026
45 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the kalin/keep-scans-readable branch November 1, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

devops DevOps/infrastructure changes documentation Documentation changes llm LLM backend changes performance Performance-critical changes rag RAG system changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants