Skip to content

feat: Add VisionPDFLoader for VLM-based Markdown extraction - #1066

Merged
AmitoVrito merged 2 commits into
SynapseKit:mainfrom
ramashishmaurya:feature/vision-pdf-loader
Oct 13, 2026
Merged

AmitoVrito merged 2 commits into
SynapseKit:mainfrom
ramashishmaurya:feature/vision-pdf-loader

Conversation

@ramashishmaurya

Copy link
Copy Markdown
Contributor

Overview

This PR introduces VisionPDFLoader, a new async RAG data loader that bypasses traditional text-extraction libraries (like PyPDF/PyMuPDF text extraction) which often fail on complex enterprise documents (two-column academic papers, financial tables, charts, embedded images).

Instead, it converts PDF pages into high-res images and passes them directly to a Vision-Language Model (VLM) (e.g., GPT-4o, Claude 3.5 Sonnet) to output perfectly structured Markdown.

Why?

Vision-based parsing is the absolute state-of-the-art for Enterprise RAG. By leveraging VLMs directly in the ingestion pipeline, SynapseKit leaps ahead of standard LangChain loaders by perfectly capturing document structure, reading charts natively, and eliminating messy text overlap from complex layouts.

Features

  • Natively Async: Fully leverages asyncio to process pages concurrently via a configurable Semaphore, blasting through large documents.
  • Provider Agnostic: The loader works with any VLM subclass of BaseLLM (OpenAI, Anthropic, Gemini) by automatically formatting the multimodal payload depending on the BaseLLM's provider configuration.
  • PyMuPDF Engine: Uses fitz for ultra-fast, high-fidelity PDF rasterization without requiring poppler OS dependencies.

Changes

  • Created src/synapsekit/loaders/vision_pdf.py featuring the VisionPDFLoader.
  • Exported VisionPDFLoader in src/synapsekit/loaders/__init__.py.
  • Wrote full unit test coverage using a mocked VLM in tests/loaders/test_vision_pdf.py.

ramashishmaurya and others added 2 commits October 1, 2026 08:53
…cess, mock-based tests

doc.close() was skipped if any page's VLM call raised, leaking the
fitz.Document/file handle. Page rasterization also called
page.get_pixmap() concurrently across threads (via asyncio.to_thread
under a bounded semaphore) on the shared fitz.Document, which is not
safe for concurrent cross-thread access in PyMuPDF; rasterization is
now serialized behind a lock while the LLM call still runs
concurrently.

Replaced the unittest.mock/MagicMock-based test doubles with a
hand-written fake fitz module and a real temp PDF file per house
testing standards, and fixed a mypy no-any-return on the pixmap bytes.

Co-authored-by: Ashish Maurya <[email protected]>
@AmitoVrito
AmitoVrito force-pushed the feature/vision-pdf-loader branch from 6441220 to 06f9e80 Compare October 13, 2026 17:00

@AmitoVrito AmitoVrito left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and hardened before merge: fixed a resource leak (doc.close() skipped on a failed page), serialized PyMuPDF page rasterization (not safe for concurrent cross-thread access) behind a lock while still letting the LLM call run concurrently, replaced MagicMock-based tests with a hand-written fake fitz module + a real temp PDF, and updated the loader-count preflight test.

@AmitoVrito
AmitoVrito merged commit bc2c23b into SynapseKit:main Oct 13, 2026
19 checks passed
AmitoVrito added a commit that referenced this pull request Oct 13, 2026
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.

2 participants