PageDoc-RAG: CPU-First Multimodal Document Ingestion & Retrieval Engine
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?
- 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.
- CPU-First Architecture: High-speed, cost-effective inference on standard CPU hardware without requiring heavy multi-gigabyte GPU models for standard enterprise document corpora.
- 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.
- 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)$$
- Source-of-Truth Principle: Returns original PDF page references, visual crops, and bounding boxes alongside similarity scores.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5ee12b603b98b5bae063bf3b447589db9c89a020e0c59b73d80f94f873d5abc4
|
|
| MD5 |
495960d15c70b019ba02ba780278afd6
|
|
| BLAKE2b-256 |
73bcec377abe3d8aefcb4d4f0efdb3e3a23b88fdf58a6cb78e0abe3a2e910a6a
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
11715689383f059ef9b57b71c17b696633b2a9e0476bf0815050641fbd373f2b
|
|
| MD5 |
33feafdb5902ee6fc8be1545ab885ea5
|
|
| BLAKE2b-256 |
20e2cae3d46a6795d0eec16399aafd5c2a2bd47dc58288b86f65dca1202f04aa
|