Skip to main content

PyMuPDF Utilities for LLM/RAG with Visual Analyzer

Project description

Image Analyzer (New!)

PyMuPDF4LLM now includes a powerful Image Analyzer feature designed to bridge the gap between visual content and structured text. This feature uses Vision Language Models (VLMs) to extract detailed information from images—such as logos, complex tables, and charts—and convert them into clean, LLM-ready Markdown.

How it Works

The Image Analyzer is designed to handle the nuance of visual data that standard OCR often misses:

  • Hierarchical Table Parsing: Specifically optimized to detect and reconstruct complex, multi-level X-axis structures (e.g., grouping data by "Model" then "Configuration").
  • Brand & Logo Recognition: Identifies and transcribes visible text from logos and brand marks.
  • Chart & Graph Interpretation: Converts bar charts, line graphs, and pie charts into structured Markdown tables, capturing data points and trend notes.
  • Smart OCR: Uses a hybrid approach to only apply OCR where necessary (e.g., on scanned regions or illegible text), preserving the quality of native digital text.

Key Features

  • Model Agnostic: Compatible with multiple inference backends, including Hugging Face, Groq, and OpenAI.
  • Layout-Aware: Maintains the natural reading order and structural context of the document.
  • Markdown Optimized: Outputs are formatted specifically for RAG pipelines, ensuring that visual data is indexed as meaningfully as the surrounding text.

Usage

You can use the Image Analyzer by calling the analyze_image method from the ImageAnalyzer classes.

import pymupdf4llm
from pymupdf4llm.helpers.image_analyzer import OpenAIImageAnalyzer

# Initialize the analyzer
analyzer = OpenAIImageAnalyzer(
    api_key=os.getenv("OPENAI_API_KEY"), 
    base_url=os.getenv("OPENAI_BASE_URL"), 
    model_name=os.getenv("OPENAI_MODEL_NAME")
)

# Initialize to_markdown to get parsed pdf document
pymupdf4llm.to_markdown(
                document,
                analyze_image=analyzer,
            )

Technical Details

  • Prompt Engineering: Uses a sophisticated system prompt (visual_descriptor.md) that enforces strict structural rules to prevent "hallucinated" layout collapses.
  • Performance: Optimized to be significantly faster and cheaper than standard vision-based LLM extraction by using efficient inference.
  • Customizable: Easily configure model, max_output_tokens, and temperature to suit your specific data requirements.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymupdf4llm_tsr-0.3.0.tar.gz (3.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymupdf4llm_tsr-0.3.0-py3-none-any.whl (77.3 kB view details)

Uploaded Python 3

File details

Details for the file pymupdf4llm_tsr-0.3.0.tar.gz.

File metadata

  • Download URL: pymupdf4llm_tsr-0.3.0.tar.gz
  • Upload date:
  • Size: 3.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for pymupdf4llm_tsr-0.3.0.tar.gz
Algorithm Hash digest
SHA256 704e8c288341b8213762ae3e9a0c3a6e98ca975c301bf836dcf0c827c24ba341
MD5 b318c6e835865e30c40767e0008304ad
BLAKE2b-256 9ade54d118c23cfa0c31e44b3720b9d2a7582991d3cb94de9977988aea3fc693

See more details on using hashes here.

File details

Details for the file pymupdf4llm_tsr-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pymupdf4llm_tsr-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8da5bc45bb7f07f201d04f4743e7708779e06fc3421af9cdd972d1e1e89cbe81
MD5 b78b45166517a7d0e8f34242e105b789
BLAKE2b-256 9bbbd809f3ce599b8fe946ee24e4dfd8f731ab3ab57c76ccf2440d0d0775d6be

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page