Skip to content

feat: add visual-document multimodal RAG - #1049

Merged
AmitoVrito merged 13 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-894-visual-rag
Sep 21, 2026
Merged

AmitoVrito merged 13 commits into
SynapseKit:mainfrom
DhruvGarg111:feat/issue-894-visual-rag

Conversation

@DhruvGarg111

Copy link
Copy Markdown
Collaborator

Summary

  • Adds provider-agnostic visual-page contracts, lazy ColPali/ColQwen adapters, and page-level MaxSim retrieval.
  • Integrates visual indexing and multimodal answer generation into RAG with additive MultimodalRAG, deterministic page/bbox/source citations, and text fallback.
  • Adds optional PDF/PPTX/media support, provider-aware image handling, a rendered offline benchmark, and a CI gate.

Motivation

Scanned PDFs and slide decks often contain meaning in layout, charts, colors, and images that text-only retrieval cannot recover.

Closes #894

Changes

  • Introduces dependency-free variable-length multimodal embedding contracts.
  • Adds lazy Transformers-backed ColPaliEmbeddings and ColQwenEmbeddings adapters.
  • Adds VisualPage, image/PDF/PPTX renderers, SVG dispatch, table fallback extraction, and consistent page/slide provenance.
  • Adds visual retrieval with late-interaction MaxSim scoring and preserved image/page/bbox/source metadata.
  • Adds visual document ingestion, query routing, context packing, provider capability gating, Gemini image-part conversion, streaming, and citations.
  • Preserves existing text-only RAG APIs and uses text fallback when visual rendering is unavailable.
  • Adds the visual optional dependency group and updates the lockfile.
  • Adds a deterministic eight-sample benchmark that renders PNG fixtures through ImagePageRenderer before retrieval.

Test Plan

  • Affected tests: 1221 passed, 43 skipped
  • Visual benchmark acceptance test: 2 passed
  • Standalone benchmark: 8 samples, seed 42, visual accuracy 1.0, text accuracy 0.25, uplift 0.75
  • Ruff check and format check
  • Mypy: no issues in 650 source files
  • Deptry: no dependency issues
  • uv lock --check
  • uv build
  • Async-blocking check: clean across 646 files
  • Real temporary PPTX renderer smoke test
  • Real temporary PDF renderer smoke test with PyMuPDF
  • Core import isolation: no eager optional visual/provider imports

Notes for Reviewers

  • ColPali/ColQwen model inference is intentionally lazy and was covered with fake backends; no model download or live provider call is required by the tests.
  • The full repository suite was also attempted but stops at the unrelated existing Windows failure tests/agents/test_tools.py::TestPythonREPLTool::test_timeout_on_slow_operation (423 passed, 27 skipped, 1 failed with --maxfail=1).
  • The offline benchmark is a deterministic contract/regression gate, not a claim about production DocVQA accuracy.

DhruvGarg111 and others added 13 commits September 18, 2026 01:00
supports_multimodal defaults to False on BaseLLM, so most providers now
silently skip captioning for ImageLoader instead of erroring or captioning.
Surface it via a log so the degradation isn't invisible.

Co-authored-by: Dhruv Garg <[email protected]>
retrieve_with_scores ran the MaxSim numpy matmuls directly on the event
loop, blocking it for the full scan duration on large page corpora and
violating the framework's async-first invariant.

Co-authored-by: Dhruv Garg <[email protected]>
… silently matching nothing

_filter_candidates caught TypeError from an unhashable filter value (e.g. a
bbox list) and returned [] for the whole query, indistinguishable from a
real empty result. Unhashable metadata is never indexed by _update_index,
so querying on it can never match anything -- fail fast instead.

Co-authored-by: Dhruv Garg <[email protected]>
…l RAG tests

Project testing standard forbids MagicMock/Mock/mocker.patch anywhere; this
new test file used them for pipeline stubs and PDFLoader.aload interception.
Replace with hand-written recorder/fake classes and pytest's monkeypatch
(real attribute substitution, not a Mock object).

Co-authored-by: Dhruv Garg <[email protected]>
…nothing

_ask_visual/_stream_visual always built the vision-flavored prompt once
page_count > 0, even for queries where the visual retriever returns no
results. Fall back to the plain text pipeline in that case instead of
framing the answer around nonexistent visual evidence.

Co-authored-by: Dhruv Garg <[email protected]>
add_async swallowed all render_file exceptions (corrupted/password-protected
PDF, missing renderer) with a bare except and no logging, so callers saw
"success" with silently zero visual indexing. Log a warning so the
degradation is visible.

Co-authored-by: Dhruv Garg <[email protected]>
…it through

_prepare_image silently returned the original wrapper object (not
bytes/str) when base64 image data was empty, which then hit the
processor/model call and crashed opaquely deep inside transformers/PIL.
Raise a clear ValueError at the boundary instead.

Co-authored-by: Dhruv Garg <[email protected]>
…lently passing them through

_validate_batch guarded divide-by-zero for zero-norm token rows but left
them unnormalized with no signal. A genuine all-zero (e.g. padding-heavy)
token vector now silently participates in MaxSim scoring. Warn when this
happens so it's visible instead of silently biasing retrieval scores.

Co-authored-by: Dhruv Garg <[email protected]>
Resolve conflicts in ci.yml (keep both visual-rag-gate and
orchestration-eval-gate jobs), README.md (fold visual-page retrieval
into main's refreshed table format), and uv.lock (regenerated).
Add the missing Unreleased CHANGELOG entry for SynapseKit#894 at merge time,
including the post-review fixes.
@AmitoVrito
AmitoVrito merged commit 1bc8603 into SynapseKit:main Sep 21, 2026
18 checks passed
@AmitoVrito

AmitoVrito commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Thanks for this one @DhruvGarg111 , visual RAG is a big feature and the ColPali/ColQwen integration is really solid work. Merged into main, closes #894. Made a handful of small fixes on top before merging (mostly around silent failure modes and the async gate) but the core design held up well. Appreciate the effort here.

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.

Visual-document & multimodal RAG (ColPali-style page retrieval)

2 participants