Skip to main content

PageDoc-RAG: CPU-First Multimodal Document Ingestion & Retrieval Engine

PyPI Version License: Apache-2.0 Python 3.9+

PageDoc-RAG is a production-grade, CPU-first multimodal document engine that bridges the gap between raw documents (PDFs, scans, images) and modern RAG pipelines. It performs native layout extraction, semantic multimodal chunking (preserving tables, charts, and text reading order), multi-vector indexing, and fine-grained MaxSim late-interaction retrieval with authoritative page evidence.


🌟 Why PageDoc-RAG?

  1. End-to-End Document Lifecycle: Not just a retriever. It handles the entire pipeline: high-resolution PDF rendering, native layout & table extraction, OCR fallback, semantic multimodal chunking, multi-vector generation, and database indexing.
  2. CPU-First Architecture: High-speed, cost-effective inference on standard CPU hardware without requiring heavy multi-gigabyte GPU models for standard enterprise document corpora.
  3. Atomic Multimodal Chunking:
    • Tables: Extracted as structured atomic units with header context preserved across rows.
    • Charts: Decomposed into 3 vector streams: Chart Title, Data Series pairs, and Synthesized Semantic Relational Insights (e.g., "Q4 has highest revenue").
    • Text: Extracted with bounding boxes $[x_0, y_0, x_1, y_1]$ and reading-order continuity.
    • Seals & Stamps: Detected and isolated for compliance and verification workflows.
  4. ColPali/ColBERT-Style Late Interaction (MaxSim): Generates fine-grained multi-vector representations per page and scores queries using token-level late interaction: $$\text{Score}(Q, P) = \sum_{i=1}^{M} \max_{j=1}^{N} \text{sim}(q_i, p_j)$$
  5. Source-of-Truth Principle: Returns original PDF page references, visual crops, and bounding boxes alongside similarity scores.
  6. Two-Stage Scalable Retrieval: ANN candidate filtering before MaxSim reranking to scale effortlessly to tens of thousands of documents.

📦 Installation

# Core installation (Zero heavy dependencies, pure CPU)
pip install pagedoc-rag

# Optional extras:
pip install "pagedoc-rag[vector]"   # Adds FAISS-CPU vector index backend
pip install "pagedoc-rag[all]"      # Full suite (PyMuPDF, FAISS-CPU, Pillow, FastAPI)

🚀 Quickstart (Python API)

from pagedoc_rag import PageDocRAG

# 1. Initialize engine
rag = PageDocRAG(
    embedding_model="small-cpu",
    index_backend="memory",   # or "faiss"
    enable_charts=True,
    enable_tables=True,
    enable_seals=True
)

# 2. Ingest document (PDF, PNG, JPG)
doc = rag.ingest("annual_report.pdf")
print(f"Ingested {doc.num_pages} pages ({doc.document_id})")

# 3. Perform natural language search
results = rag.search("What was the Net Operating Profit in FY2025?", top_k=5)

for res in results:
    print(f"Rank Page #{res.page_number} | Score: {res.score:.4f}")
    print(f"Snippet: {res.text[:140]}...")
    print(f"Source PDF: {res.source_pdf}")
    print(f"Evidence items found: {len(res.evidence)}")

💻 CLI Usage

# Index a directory of documents
pagedoc index ./documents --backend memory

# Search across indexed pages
pagedoc search "What was revenue in 2025?" --top-k 5

# Inspect structured elements & bounding boxes on a page
pagedoc inspect ./documents/report.pdf --page 2

🏛️ Architecture & Processing Pipeline

                       PDF / Scanned Document
                                 │
                                 ▼
                     PyMuPDF High-Res Rendering
                                 │
          ┌──────────────────────┴──────────────────────┐
          ▼                                             ▼
  Native Digital Stream                         Scanned Document Stream
  • Text Blocks & Coordinates                   • PaddleOCR DBNet / SVTR
  • Native Table Matrices (find_tables)         • PP-Structure Layout Router
  • Vector Drawings & Images                    • Chart2Table & Seal Detector
          │                                             │
          └──────────────────────┬──────────────────────┘
                                 ▼
                    Semantic Multimodal Chunking
               ├── Text Paragraphs with Bounding Boxes
               ├── Structured Table Matrices (CSV / Headers)
               └── Decomposed Chart Relations & Trends
                                 │
                                 ▼
                    Multi-Vector Embedding Model
                     [p1, p2, p3, ... pN per page]
                                 │
                                 ▼
                Two-Stage Candidate Search & Filtering
                                 │
                                 ▼
                 Vectorized MaxSim Late Interaction
                                 │
                                 ▼
             Authoritative Page Retrieval & RAG Context

📊 Evaluation & Benchmarking

PageDoc-RAG includes a built-in evaluation suite for standard information retrieval metrics:

  • Recall@1, Recall@5, Recall@10
  • Mean Reciprocal Rank (MRR)
  • nDCG@5, nDCG@10
  • Latency Percentiles (p50, p95) & QPS
from pagedoc_rag.eval.benchmark import Evaluator, BenchmarkQuery

queries = [
    BenchmarkQuery(query="Revenue breakdown", target_page_ids=["doc_p2"], query_type="table"),
    BenchmarkQuery(query="Executive summary", target_page_ids=["doc_p1"], query_type="text"),
]

report = Evaluator.evaluate(rag, queries)
print(f"Recall@1: {report.recall_at_1:.2%}, MRR: {report.mrr:.4f}")

📄 License

Licensed under the Apache License, Version 2.0.

Download files

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

Source Distribution

pagedoc_rag-0.1.0.tar.gz (31.5 kB view details)

Uploaded Source

Built Distribution

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

pagedoc_rag-0.1.0-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file pagedoc_rag-0.1.0.tar.gz.

File metadata

  • Download URL: pagedoc_rag-0.1.0.tar.gz
  • Upload date:
  • Size: 31.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pagedoc_rag-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5ee12b603b98b5bae063bf3b447589db9c89a020e0c59b73d80f94f873d5abc4
MD5 495960d15c70b019ba02ba780278afd6
BLAKE2b-256 73bcec377abe3d8aefcb4d4f0efdb3e3a23b88fdf58a6cb78e0abe3a2e910a6a

See more details on using hashes here.

File details

Details for the file pagedoc_rag-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pagedoc_rag-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for pagedoc_rag-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 11715689383f059ef9b57b71c17b696633b2a9e0476bf0815050641fbd373f2b
MD5 33feafdb5902ee6fc8be1545ab885ea5
BLAKE2b-256 20e2cae3d46a6795d0eec16399aafd5c2a2bd47dc58288b86f65dca1202f04aa

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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