Skip to main content

LayoutIR Reader

Overview

LayoutIR Reader uses LayoutIR - a production-grade document ingestion and canonicalization engine with compiler-like architecture. Unlike simple PDF-to-Markdown converters, LayoutIR processes documents through an Intermediate Representation (IR) layer, enabling precise preservation of complex layouts, tables, and multi-column structures.

Why LayoutIR?

LayoutIR stands out for its:

  • Deterministic Processing: Hash-based stable IDs ensure reproducible results
  • Layout Preservation: Maintains complex multi-column layouts and table structures
  • Canonical IR Schema: Typed intermediate representation for reliable downstream processing
  • Flexible Chunking: Semantic section-based or fixed-size chunking strategies
  • GPU Acceleration: Optional GPU support for faster document processing
  • Production-Ready: Designed for enterprise-grade document pipelines

Installation

Basic Installation

pip install llama-index-readers-layoutir

With GPU Support

For GPU acceleration, first install PyTorch with CUDA support:

pip3 install torch torchvision --index-url https://download.pytorch.org/whl/cu130
pip install llama-index-readers-layoutir

Usage

Basic Usage

Load a PDF document with default settings:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader()
documents = reader.load_data(file_path="document.pdf")

# Each document preserves block structure and metadata
for doc in documents:
    print(f"Block Type: {doc.metadata['block_type']}")
    print(f"Page: {doc.metadata['page_number']}")
    print(f"Content: {doc.text[:100]}...")

With GPU Acceleration

Enable GPU processing for faster performance:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(use_gpu=True)
documents = reader.load_data(file_path="large_document.pdf")

Custom Chunking Strategy

Use semantic section-based chunking:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(
    chunk_strategy="semantic",
    max_heading_level=2,  # Split at h1 and h2 headings
)
documents = reader.load_data(file_path="structured_document.pdf")

Processing Multiple Files

Process a batch of documents:

from llama_index.readers.layoutir import LayoutIRReader
from pathlib import Path

reader = LayoutIRReader(use_gpu=True)

file_paths = ["report_2024.pdf", "technical_spec.pdf", "user_manual.pdf"]

documents = reader.load_data(file_path=file_paths)
print(f"Loaded {len(documents)} document blocks from {len(file_paths)} files")

Integration with VectorStoreIndex

Build a searchable index from LayoutIR-processed documents:

from llama_index.readers.layoutir import LayoutIRReader
from llama_index.core import VectorStoreIndex

# Load documents with preserved layout structure
reader = LayoutIRReader(
    use_gpu=True, chunk_strategy="semantic", max_heading_level=2
)
documents = reader.load_data(file_path="company_knowledge_base.pdf")

# Create index
index = VectorStoreIndex.from_documents(documents)

# Query with layout-aware context
query_engine = index.as_query_engine()
response = query_engine.query("What are the key financial metrics in Q4?")
print(response)

With SimpleDirectoryReader

Integrate LayoutIR for PDF processing in directory operations:

from llama_index.core import SimpleDirectoryReader
from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(use_gpu=True)

dir_reader = SimpleDirectoryReader(
    input_dir="/path/to/documents",
    file_extractor={".pdf": reader},
)

documents = dir_reader.load_data()
print(f"Processed {len(documents)} blocks")

Advanced Configuration

Full configuration example:

from llama_index.readers.layoutir import LayoutIRReader

reader = LayoutIRReader(
    use_gpu=True,  # Enable GPU acceleration
    chunk_strategy="semantic",  # Use semantic chunking
    max_heading_level=3,  # Split up to h3 level
    model_name="custom_model",  # Optional: specify model
    api_key="your_api_key",  # Optional: for remote processing
)

documents = reader.load_data(
    file_path="complex_layout.pdf",
    extra_info={"department": "research", "year": 2026},
)

# Access rich metadata
for doc in documents:
    print(f"ID: {doc.doc_id}")
    print(f"Type: {doc.metadata['block_type']}")
    print(f"Page: {doc.metadata['page_number']}")
    print(f"Department: {doc.metadata['department']}")

Metadata Structure

Each Document includes the following metadata:

  • file_path: Source file path
  • file_name: Source file name
  • block_type: Type of content block (table, paragraph, heading, etc.)
  • block_index: Index of the block in the document
  • page_number: Page number where the block appears
  • source: Always "layoutir"
  • Plus any extra_info passed to load_data()

Requirements

  • Python >= 3.12
  • llama-index-core >= 0.13.0
  • layoutir >= 1.0.3
  • Optional: PyTorch with CUDA for GPU acceleration

License

MIT

Forcing CPU Mode

If you encounter CUDA/GPU issues (e.g. cuBLAS version mismatches or missing CUDA drivers), set CUDA_VISIBLE_DEVICES="" before running to force CPU-only processing:

CUDA_VISIBLE_DEVICES="" python your_script.py

Metadata

Release files for llama-index-readers-layoutir 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-readers-layoutir 0.2.0
File Size Uploaded Provenance
llama_index_readers_layoutir-0.2.0.tar.gz 6.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-readers-layoutir 0.2.0
File Interpreter ABI Platform
llama_index_readers_layoutir-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.2 kB

Release files / llama_index_readers_layoutir-0.2.0.tar.gz

Download URL llama_index_readers_layoutir-0.2.0.tar.gz
Size 6.7 kB
Tags Source
SHA-256 checksum
How to use checksums
c4398290a0744d5e7eaae83903aa4b50970b5e4395a2e09ce96e162c8eb3519f
BLAKE2b-256 checksum
How to use checksums
14fe45774aa81efe1c06cfa2c65d459ae21ce7f477ac055d6bb1721e1f8dac14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_readers_layoutir-0.2.0-py3-none-any.whl

Download URL llama_index_readers_layoutir-0.2.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f46082c55c78af028cc020d693797473398a0cf1063dfa67a9129dd764f2f48d
BLAKE2b-256 checksum
How to use checksums
6d37dcc92ca75613d6f3ca309c6e2f714fc03816c1c29b249a918a6dc798ef13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-readers-layoutir 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page