Skip to content

heripo engine

TypeScript library for extracting structured data from archaeological excavation report PDFs

CI Node.js Python pnpm coverage License

English | ν•œκ΅­μ–΄

⚠️ macOS Only: The PDF parser and the demo that uses it require macOS (Apple Silicon or Intel). The other library packages have no OS installation restriction. See @heripo/pdf-parser README for detailed system requirements.

ℹ️ Notes (v0.1.x):

  • Mandatory Correction: Fixed ocrmac OCR is followed by VLM text correction regardless of language. Structural review is enabled by default in the library and disabled by default in the demo.
  • TOC Dependency: Failed automatic TOC extraction stops processing. Supply reviewed tocEntries and pageRangeMap to bypass automatic extraction.
  • Vertical Text: Old vertical-text documents with Chinese numeral page numbers are a long-term goal, not currently scheduled

🌐 Online Demo: Try it without local installation β†’ engine-demo.heripo.org

Table of Contents

Introduction

heripo engine is a collection of tools for analyzing archaeological excavation report PDFs and extracting structured data. It is designed to effectively process documents that span hundreds of pages and contain complex layouts, tables, diagrams, and photographs.

About heripo lab

heripo lab is an open-source R&D group that combines archaeological domain knowledge with software engineering expertise to drive practical research efficiency.

Kim, Hongyeon (Lead Engineer)

  • Role: Design of LLM-based unstructured data extraction pipeline and system implementation
  • Background: Software Engineer (B.S. in Computer Science and B.A. in Archaeology)
  • Research:

Cho, Hayoung (Domain Researcher)

Kim, Gaeun (Software Engineer)

  • Role: Development of archaeology research platforms
  • Background:
    • Software Engineer
    • M.A. in Archaeology (Coursework Completed)
    • B.A. in Archaeology
    • B.A. in Library and Information Science

Why heripo engine?

Archaeological excavation reports contain valuable cultural heritage information, but are often available only in PDF format, making systematic analysis and utilization difficult. heripo engine solves the following problems:

  • OCR Quality: High accuracy recognition of scanned documents using Docling SDK
  • Structure Extraction: Automatic identification of document structure including table of contents, chapters/sections, images, and tables
  • Cost Model: Docling OCR runs locally; subsequent VLM correction and document analysis costs and data transfers depend on the selected local or cloud models.

Beyond Archaeology: While heripo engine is optimized for archaeological reports, its PDF structuring capabilities (text, tables, images, TOC extraction) work well with heavily damaged scanned PDFs and documents from other domains (architecture, history, etc.). Feel free to fork and adapt it to your needs.

Data Pipeline

Raw Data Extraction β†’ Archaeological Data Ledger β†’ Archaeological Data Standard β†’ Domain Ontology β†’ DB Storage
Stage Description
Raw Data Extraction Document data structurally extracted in the original format of PDF reports (no archaeological interpretation)
Data Ledger Immutable ledger structured using a universal model covering global archaeology
Data Standard Extensible standard model (base standard β†’ country-specific β†’ domain-specific extensions)
Ontology Domain-specific semantic models and knowledge graphs
DB Storage Independent storage and utilization for each pipeline stage

Current Implementation (v0.1.x):

  • βœ… PDF parsing and OCR (Docling SDK)
  • βœ… Document structure extraction (TOC, chapters/sections, page mapping)
  • βœ… Image/table extraction and caption parsing

Planned Stages:

  • πŸ”œ Immutable Ledger (universal archaeological model, concept extraction)
  • πŸ”œ Extensible Standardization (hierarchical standard model, normalization)
  • πŸ”œ Ontology (semantic model, knowledge graph)
  • πŸ”œ Production Ready (performance optimization, API stability)

For a detailed roadmap, see docs/roadmap.md.

Built with heripo engine: heripo basecamp

heripo basecamp is a research tool currently in a private alpha. It is a separate service that uses heripo engine to build its own structured report dataset for research discovery.

Starting in Korea, growing across borders. basecamp begins with archaeological excavation reports from Korea, with a scope that extends beyond any one country. Its goal is to help researchers discover and explore reports across countries and regions.

  • Find reports on a map and narrow the search with criteria and AI filters.
  • Explore report content through a reader that brings together source PDFs, text, images, and tables.
  • Build on structured data: the engine handles PDF extraction and document structure; basecamp adds the research interface and discovery features.

The engine demo lets you try PDF processing. heripo basecamp is a separate application of the same engine, with its own dataset. Reports uploaded to the demo and their processing results are not added to basecamp.

Key Features

PDF Parsing (@heripo/pdf-parser)

  • High-Quality OCR: Document recognition using Docling SDK (ocrmac / Apple Vision Framework)
  • Mandatory VLM Correction: Page text and table-cell correction after OCR, with configurable structural review and table correction.
  • Apple Silicon Optimized: Uses the Apple Vision OCR backend on macOS
  • Automatic Environment Setup: Automatic Python virtual environment and docling-serve installation
  • Image Extraction: Automatic extraction and saving of images from PDFs
  • Review Assistance: Optional page-level VLM review with audit proposals and high-confidence auto-fixes

Document Processing (@heripo/document-processor)

  • TOC Extraction: Automatic TOC recognition with rule-based + LLM fallback
  • Hierarchical Structure: Automatic generation of chapter/section/subsection hierarchy
  • Page Mapping: Actual page number mapping using Vision LLM
  • Caption Parsing: Automatic parsing of image and table captions
  • Source Provenance: Optional Docling source metadata and node-level source references
  • Table Grid Normalization: Preserves row/column spans and removes merged-cell shadow entries
  • LLM Flexibility: Support for various LLMs including OpenAI, Anthropic, Google

Data Models (@heripo/model)

  • ProcessedDocument: Intermediate data model optimized for LLM analysis
  • DoclingDocument: Raw output format from Docling SDK
  • ReviewAssistanceReport: Optional page-level review assistance report model
  • Type Safety: Complete TypeScript type definitions

Architecture

heripo engine is organized as a pnpm workspace-based monorepo.

heripo-engine/
β”œβ”€β”€ packages/              # Core libraries
β”‚   β”œβ”€β”€ pdf-parser/        # PDF β†’ DoclingDocument
β”‚   β”œβ”€β”€ document-processor/ # DoclingDocument β†’ ProcessedDocument
β”‚   β”œβ”€β”€ model/             # Data models and type definitions
β”‚   β”œβ”€β”€ logger/            # Logging adapter package
β”‚   └── shared/            # Internal utilities (not published)
β”œβ”€β”€ apps/                  # Applications
β”‚   └── demo-web/          # Next.js web demo
└── tools/                 # Build tool configurations
    β”œβ”€β”€ tsconfig/          # Shared TypeScript config
    β”œβ”€β”€ tsup-config/       # Build config
    └── vitest-config/     # Test config

For detailed architecture explanation, see docs/architecture.md.

Installation

System Requirements

  • macOS (Apple Silicon or Intel)
  • Node.js >= 24.0.0
  • pnpm 11.25.0 (packageManager)
  • Python 3.9 - 3.12 (⚠️ Python 3.13+ is not supported)
  • jq (JSON processing tool)
  • poppler (PDF text extraction tools)
  • ImageMagick + Ghostscript (page rendering and image-PDF conversion)
# Install Python 3.11 (recommended)
brew install python@3.11
export PATH="$(brew --prefix python@3.11)/libexec/bin:$PATH"
python3 --version

# Install jq
brew install jq

# Install poppler
brew install poppler imagemagick ghostscript

# Install Node.js and pnpm
brew install node
npm install -g pnpm@11.25.0

For detailed installation guide, see @heripo/pdf-parser README.

Package Installation

# Install individual packages
pnpm add @heripo/pdf-parser
pnpm add @heripo/document-processor
pnpm add @heripo/model
pnpm add @heripo/logger

# Or install all at once
pnpm add @heripo/pdf-parser @heripo/document-processor @heripo/model @heripo/logger

Packages

Package Version Description
@heripo/pdf-parser 0.1.x PDF parsing and OCR
@heripo/document-processor 0.1.x Document structure analysis and LLM processing
@heripo/model 0.1.x Data models and type definitions
@heripo/logger 0.1.x Logger interface and adapter

The parser and document processor ship as ESM; model and logger provide both ESM and CommonJS. The workspace uses Node.js 24+ and pnpm 11.25.0. Align AI SDK and provider versions with the catalog in pnpm-workspace.yaml.

pnpm add @ai-sdk/openai

Internal package documentation:

Usage Examples

Run in an ESM project. This example also requires @ai-sdk/openai; configure a model that supports image input and structured output, with its model ID and credentials in your environment.

import type { DoclingDocument } from '@heripo/model';

import { openai } from '@ai-sdk/openai';
import { DocumentProcessor } from '@heripo/document-processor';
import { Logger } from '@heripo/logger';
import { PDFParser } from '@heripo/pdf-parser';
import { readFile, writeFile } from 'node:fs/promises';
import { join } from 'node:path';

const logger = new Logger(console);
// Set OPENAI_API_KEY and HERIPO_MODEL to a vision-capable model ID.
const model = openai(process.env.HERIPO_MODEL!);
const parser = new PDFParser({ logger, port: 5001, timeout: 1_800_000 });
const processor = new DocumentProcessor({
  logger,
  fallbackModel: model,
  textCleanerBatchSize: 20,
  captionParserBatchSize: 5,
  captionValidatorBatchSize: 5,
});

try {
  await parser.init();
  const parserUsage = await parser.parse(
    'file:///absolute/path/to/report.pdf',
    'report-001',
    async (artifactDir) => {
      const doclingDocument = JSON.parse(
        await readFile(join(artifactDir, 'result.json'), 'utf8'),
      ) as DoclingDocument;
      const { document, usage } = await processor.process(
        doclingDocument,
        'report-001',
        artifactDir,
      );
      await writeFile(
        join(artifactDir, 'result-processed.json'),
        JSON.stringify(document, null, 2),
      );
      console.log('Chapters:', document.chapters.length);
      console.log('Processor token usage:', usage.total);
    },
    false, // Keep artifacts after the callback.
    {
      correction: {
        models: {
          textCorrection: model,
          pageGate: model,
          reviewAssistance: model,
        },
      },
      chunkedConversion: true,
      chunkSize: 10,
    },
  );
  console.log('Parser token usage:', parserUsage?.total);
} finally {
  await parser.dispose();
}

parse() returns TokenUsageReport | null, not a document. Read the corrected Docling document from artifactDir/result.json in the callback. With cleanupAfterCallback: true, copy required JSON, images and pages elsewhere inside the callback before the directory is removed. The processor returns { document, usage } and does not save files automatically.

See document-processor for manual TOC/page mapping and provenance, and pdf-parser for per-stage models, fallbacks and correction options.

Demo Application

Online Demo

Try it without local installation:

πŸ”— https://engine-demo.heripo.org

Public-mode limits depend on deployment settings, including daily limits and a seven-day session lock after successful processing. See the demo README for details.

Web Demo (Next.js)

A web application providing real-time PDF processing monitoring:

# Run from the repository root.
pnpm install
pnpm build:packages
cp apps/demo-web/.env.example apps/demo-web/.env
# Configure providers and model settings before processing.
pnpm demo-web:dev

Access http://localhost:3000 in your browser

Key Features:

  • PDF upload and processing option configuration
  • Real-time processing status monitoring (SSE)
  • Processing result visualization (TOC, images, tables)
  • Job queue management

For detailed usage, see apps/demo-web/README.md.

Documentation

Package Documentation

Roadmap

Current version: v0.1.x (Initial Release)

v0.1.x - Raw Data Extraction (Current)

  • βœ… PDF parsing with OCR
  • βœ… Document structure extraction (TOC, chapters/sections)
  • βœ… Image/table extraction
  • βœ… Page mapping
  • βœ… Caption parsing

v0.2.x - Immutable Ledger

  • Universal data model design covering global archaeology
  • Archaeological concept extraction (features, artifacts, strata, excavation units)
  • LLM-based information extraction pipeline

v0.3.x - Extensible Standardization

  • Hierarchical standard model design (base β†’ country-specific β†’ domain-specific)
  • Normalization pipeline
  • Data validation

v0.4.x - Ontology

  • Domain-specific semantic models
  • Knowledge graph construction

v1.0.x - Production Ready

  • Performance optimization
  • API stability guarantee
  • Comprehensive testing

For details, see docs/roadmap.md.

Development

Monorepo Commands

# Install dependencies
pnpm install

# Build all
pnpm build

# Type check
pnpm typecheck

# Lint
pnpm lint
pnpm lint:fix

# Format
pnpm format
pnpm format:check

# Run all tests
pnpm test
pnpm test:coverage
pnpm test:ci

# Test specific package
pnpm --filter @heripo/pdf-parser test
pnpm --filter @heripo/document-processor test

Package-Specific Commands

# Build specific package
pnpm --filter @heripo/pdf-parser build

# Test specific package (with coverage)
pnpm --filter @heripo/pdf-parser test:coverage

# Watch mode for specific package
pnpm --filter @heripo/pdf-parser dev

Contributing

Thank you for contributing to the heripo engine project! For contribution guidelines, see CONTRIBUTING.md.

How to Contribute

  1. Fork this repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Create a Pull Request

Development Guidelines

  • All tests must pass (pnpm test)
  • 100% code coverage must be maintained
  • ESLint and Prettier rules must be followed
  • Commit messages must follow Conventional Commits

Community

Citation and Attribution

If you use this project in research, services, or derivative works, please include the following attribution:

Powered by heripo engine

Such attribution helps support the open-source project and gives credit to contributors.

BibTeX Citation

For academic papers or research documents, you may use the following BibTeX entry:

@software{heripo_engine,
  author = {Kim, Hongyeon and Cho, Hayoung and Kim, Gaeun},
  title = {heripo engine: TypeScript Library for Extracting Structured Data from Archaeological Excavation Report PDFs},
  year = {2026},
  url = {https://github.com/heripo-lab/heripo-engine},
  note = {Apache License 2.0}
}

Sponsor

If you'd like to support heripo lab's open-source research, you can sponsor us through:

License

This project is distributed under the Apache License 2.0.

Acknowledgments

This project uses the following open-source projects:


heripo lab | GitHub | heripo engine

About

TypeScript library for extracting structured data from archaeological excavation report PDFs using Docling SDK and LLM-powered analysis

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

11 stars

Watchers

0 watching

Forks

Releases

Sponsor this project

Contributors

Languages