Skip to content

fix(rag): keep VLM blocks atomic in section-based chunking - #5817

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
TejasS1233:fix-786-vlm-atomic-chunks
Oct 26, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
TejasS1233:fix-786-vlm-atomic-chunks

Conversation

@TejasS1233

Copy link
Copy Markdown
Contributor

VLM image blocks in extracted PDFs were silently merged into neighboring body chunks whenever _split_text_into_chunks took the section-based path. The image markers are replaced with <<<VLM_BLOCK_N>>> placeholders before sectioning, but the atomic guard only checked for ### 🖼️ IMAGE and **Content Extracted from Images:**. The placeholders were never marked VLM, so restoring them produced oversized chunks and could split image-derived text at the embedder cap, degrading retrieval without an error.

The guard now also recognizes the generated placeholders, so VLM-bearing sections stay atomic on both chunking paths.

Fixes #786.

Test plan

  • pytest tests/unit/rag/test_embed_input_cap.py::test_section_chunking_keeps_vlm_blocks_out_of_body_chunks -q
  • pytest tests/unit/rag -q
  • pytest tests/test_rag.py -q
  • python util/lint.py --black --isort --pylint --flake8
  • python util/lint.py --all (the import smoke test timed out locally; the remaining checks were not run)

Copilot AI balanced review requested due to automatic review settings October 26, 2026 06:50

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota.

@github-actions github-actions Bot added rag RAG system changes tests Test changes performance Performance-critical changes labels Oct 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions

This one-line fix is correct. When a PDF had enough headings to take the section-based chunking path, text that a vision model pulled out of images got merged into the surrounding body chunks, and the embedder cap could then cut it in half. Image sections now stay as their own chunks on both chunking paths, and the new test pins this down.

One thing to know before merging. A section that holds an image block also holds everything else up to the next heading. That includes any body text from the next page. The whole section is now treated as one unbreakable chunk, so a long run of body text after an image ends up in the image chunk and gets cut only by the embedder cap. This is still better than before and doesn't block the merge, but it's worth a follow-up (details below).

Real-world evidence

N/A: this is an internal RAG chunking change covered by unit tests, and the CI evidence stage produced no bundle. This verdict rests on static review alone. I couldn't run the new test here because pytest isn't installed in the review runner. The PR's own test plan reports tests/unit/rag and tests/test_rag.py passing.

🔍 Technical details

Issues

🟢 A section with an image keeps the trailing body text in the atomic chunk (src/gaia/rag/sdk.py:2446). vlm_pattern ends a block at [Page N]\n. The page text after that has no # heading, so it stays in the same section as <<<VLM_BLOCK_i>>>. Before this change that body text was packed with neighbouring paragraphs. Now the whole section skips the sentence split and goes to _fit_chunks_to_embedder as a single item. That function cuts by size and ignores sentence boundaries. A simple follow-up would be to also treat a placeholder line as a section boundary (start a new section when the line after a placeholder begins), so each VLM block becomes a section of its own. Not blocking.

🟢 The test docstring could name the regression. The new test covers the section-based path, with more than 3 sections and an image block in the middle. A one-line docstring saying the placeholder guard is what's under test would stop someone from later "simplifying" the fixture down to ≤3 sections. With ≤3 sections the code takes the paragraph path, which already worked.

Strengths

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 26, 2026
Merged via the queue into amd:main with commit cbb2b38 Oct 26, 2026
31 checks passed
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 26, 2026
5 of 9 tasks
grtninja pushed a commit to grtninja/gaia that referenced this pull request Oct 26, 2026
## Why this matters

v0.25.2 is a bug-fix release on top of v0.25.1: setup and install no
longer stop at the first failed step, shell and file access handle
Windows paths and text encodings, the Agent UI and desktop app stop
showing misleading states, and document search, email and skills each
lose a handful of rough edges. 55 commits since v0.25.1; notes are in
`docs/releases/v0.25.2.mdx` and credit 15 outside contributors.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.25.2.mdx
--tag v0.25.2` passes
- [x] `mintlify validate` (from `docs/`) passes
- [x] `python util/check_doc_links.py --internal-only`, `python
util/check_doc_versions.py` and `node
installer/version/bump-ui-version.mjs --check` pass
- [x] `python util/check_component_core_api.py --release-version 0.25.2`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py
tests/unit/test_hub_core_version_gate.py`: 156 passed
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.25.2-rc1`:

- `gaia_shell` and shell/safety (amd#5794, amd#5751, amd#5768)
- `gaia_honesty` (amd#5753)
- `gaia_skills_tasks` and `gaia_skills_lifecycle` (amd#5422, amd#5755)
- `rag_retrieval` and `rag_quality` (amd#5742, amd#5754, amd#5761, amd#5817, amd#5812)
- email scenarios (amd#5767, amd#5811)
- `tool_selection` and `error_recovery` (amd#5732)
- Claude provider thinking replay (amd#5072)
- memory categories (amd#5818 merged; amd#5756 has not)

## Release checklist

- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.25.2-rc1`
- [ ] Extend the changelog if main gains commits before the tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance-critical changes rag RAG system changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RAG: VLM image blocks can be split across chunks when section-based splitting path is used

3 participants