LiteParse Document Parsing Library

repository·main·Indexed 11 days ago

https://github.com/run-llama/liteparse

A high-performance, local-first document parsing library for fast spatial text extraction and OCR, designed for RAG pipelines and LLM agents. It supports PDF, Microsoft Office, OpenDocument, and image formats. LiteParse provides a Rust implementation, a Node.js SDK, and the `lit` CLI tool. It features built-in Tesseract OCR and supports external OCR backends including OAR ONNX, EasyOCR, PaddleOCR, and Surya.

Tokens
80.1K
Snippets
255
Records
349
Agent score
95%

What's inside LiteParse

  1. Overview of LiteParse

    main

    LiteParse is a standalone, open-source PDF parsing tool designed for fast and lightweight local parsing. It focuses on high-quality spatial text parsing with bounding boxes and does not require proprietary LLMs or cloud dependencies.

    Key Features:

    • Fast Text Parsing: Uses PDFium for spatial text extraction.
    • Flexible OCR: Supports built-in Tesseract (zero setup) or external HTTP OCR servers (e.g., EasyOCR, PaddleOCR).
    • Complexity Detection: Ability to check if a document requires OCR before full processing.
    • Multiple Output Formats: Supports Markdown (with headings, tables, lists, images, and links), JSON (with bounding boxes), and plain text.
    • Screenshot Generation: Creates high-quality page screenshots for LLM agents.
    • Multi-language/Platform Support: Available for Rust, Node.js/TypeScript, Python, and WASM (Browser) across Linux, macOS, and Windows.
  2. What is LiteParse?

    main
    LiteParse is an open-source document parsing library designed for fast, local parsing of PDFs, Office documents, and images. It is written in Rust and runs entirely on your machine without cloud dependencies, LLMs, or API keys. It is optimized for real-time applications, coding agents, and local workflows that require spatial layout information and bounding boxes.
  3. Capabilities and limitations of LiteParse WASM

    main

    What works in the browser

    • PDF parsing using Uint8Array input.
    • Custom OCR via the ocrEngine callback interface.
    • Output formats: Text, JSON, and Markdown.
    • Complexity detection: Using parser.isComplex(bytes).
    • Full extraction options: Annotations, form fields, structure trees, vector graphics, etc.

    What doesn't work

    • File path input: You must pass Uint8Array instead of a string path.
    • Office conversion: DOCX/XLSX/PPTX conversion is unavailable (requires LibreOffice).
    • Built-in OCR: Tesseract and HTTP OCR backends are not available; you must provide a custom ocrEngine.
    • Screenshots: Not supported in the WASM build.
    • Multi-threading: numWorkers is not available; parsing is single-threaded.
    • Filesystem access: imageOutputDir is unavailable; use extractImages and read the bytes from the result instead.
  4. Configure OCR settings and servers

    main

    LiteParse supports multiple OCR strategies:

    1. Built-in Tesseract

    Tesseract is included out-of-the-box. You can specify languages or provide a custom path to trained data.

    • Specify language: --ocr-language <lang> (e.g., fra)
    • Custom data path: --tessdata-path <path> or via environment variable TESSDATA_PREFIX.

    2. HTTP OCR Service

    You can connect to an external OCR service (like EasyOCR or PaddleOCR) by providing a URL.

    • Server URL: --ocr-server-url <url>

    Custom OCR API Requirements: To use a custom service, implement an endpoint that:

    • Responds to POST /ocr with file and language parameters.
    • Returns JSON: { "results": [{ "text": "...", "bbox": [x1,y1,x2,y2], "confidence": 0.0 }] }
    lit parse document.pdf --ocr-language fra
    export TESSDATA_PREFIX=/path/to/tessdata
    lit parse document.pdf
  5. Supported input formats and LibreOffice conversion

    main

    LiteParse supports automatic conversion of various document formats to PDF before parsing.

    Office Documents

    Conversion requires LibreOffice to be installed on your system. Supported formats include:

    • Word: .doc, .docx, .docm, .odt, .rtf, .pages
    • PowerPoint: .ppt, .pptx, .pptm, .odp, .key
    • Spreadsheets: .xls, .xlsx, .xlsm, .ods, .csv, .tsv, .numbers

    Installation Commands:

    • macOS: brew install --cask libreoffice
    • Ubuntu/Debian: apt-get install libreoffice
    • Windows: choco install libreoffice-fresh (Note: You may need to add the LibreOffice program directory to your PATH).

    Images

    LiteParse provides native support for image formats without requiring imagemagick (as of v2.8.0). Supported formats:

    • .jpg, .jpeg, .png, .gif, .bmp, .tiff, .webp, .svg
  6. Integrate custom HTTP OCR servers

    main

    For higher accuracy, you can replace the default Tesseract engine with an external HTTP OCR service (like EasyOCR or PaddleOCR).

    To integrate your own service, implement the LiteParse OCR API specification. Your service must provide:

    • A POST /ocr endpoint.
    • Support for file and language parameters.
    • A JSON response in the following format:
    {
      "results": [
        {
          "text": "string",
          "bbox": [x1, y1, x2, y2],
          "confidence": number
        }
      ]
    }
  7. Understand OCR complexity reasons

    main

    Complexity is computed per page. A page is flagged with a needs_ocr verdict if it contains any of the following reasons:

    ReasonMeaning
    scannedA single raster covers ~the whole page with little or no text behind it.
    no-textAlmost no extractable text and no full-page image (e.g., blank page, cover).
    sparse-textReal text exists but covers very little of the page (e.g., a figure caption).
    embedded-imagesSubstantial embedded raster figures sit alongside native text.
    garbledNative text decodes to unreadable garbage.
    vector-textText is painted as filled vector outlines rather than native text items.
    annotation-textMeaningful text lives in PDF annotations rather than the content stream.
  8. Implement a custom LiteParse OCR server

    main

    You can integrate any OCR engine by implementing a server that exposes a POST /ocr endpoint accepting multipart/form-data.

    Note on Language Codes: LiteParse forwards the --ocr-language value (defaulting to Tesseract-style ISO 639-3 like eng). Your server should be able to handle both ISO 639-3 and ISO 639-1 (e.g., en) codes.

    Request Format:

    • file (binary, required): The image file.
    • language (string, optional): ISO 639-1 code.

    Response Format: Return a JSON object containing a results array. Each result must include text, bbox (axis-aligned [x1, y1, x2, y2]), and confidence (0.0 to 1.0).

    Implementation Requirements:

    • Return {"results": []} if no text is detected.
    • Bounding boxes must be axis-aligned (top-left to bottom-right). If your engine returns rotated boxes, convert them to axis-aligned.
    • Results should be in reading order (top-to-bottom, left-to-right).
    • If your engine lacks confidence scores, return 1.0.
    {
      "results": [
        {
          "text": "recognized text",
          "bbox": [12, 40, 220, 62],
          "confidence": 0.95
        }
      ]
    }
  9. Core capabilities of LiteParse

    main

    LiteParse provides several key features for document processing:

    • Spatial PDF Parsing: Extracts text with precise positioning and bounding boxes for every text line.
    • Markdown Rendering: Converts documents into structured Markdown including headings, tables, lists, images, and links, ideal for RAG pipelines.
    • OCR Support: Handles scanned documents using built-in Tesseract or external OCR servers.
    • Multi-format Support: Parses Office files (DOCX, XLSX, PPTX) and images (PNG, JPG) via automatic conversion.
    • Advanced Extraction: Pulls embedded images, vector graphics, annotations, AcroForm fields, and tagged-structure trees.
    • Document Complexity Scoring: Analyzes documents beforehand to identify scanned, multi-column, or table-heavy pages for optimized routing.
    • Cross-platform usage: Available via Node.js/TypeScript, Python, Rust, and WebAssembly (WASM) for browser environments.
  10. Understand the JsParseResult structure

    main

    The JsParseResult is the top-level object returned after a parsing session.

    Fields:

    • total_pages: Total pages in the source document.
    • pages: Array of JsParsedPage objects.
    • page_errors: Array of JsPageError objects (if continue_on_page_error is enabled).
    • text: The concatenated text of the entire document.
    • images: Extracted image data.
    • screenshots: Rendered page images (if extract_screenshots is enabled).
    • doc_meta: Document-level metadata (if extract_document_metadata is enabled).
    • xfa_packets: Raw XFA packets (if extract_xfa_packets is enabled).
  11. How the LiteParse agent skill optimizes document processing

    main

    The LiteParse skill is designed to keep an agent's context window small and reduce costs by following these patterns:

    • Parse once, search many: Instead of re-parsing a document for every query, the skill parses the document to a temporary file once, and all subsequent searches are performed against that file.
    • Minimize round-trips: The skill fetches matches and their surrounding context in single commands and batches independent lookups to avoid spending multiple turns on search terms.
    • Bound outputs: Results are capped to prevent a single lookup from flooding the agent's context window.
    • Escalate to ranked search: When keyword matching is insufficient, the skill uses ranked search instead of attempting multiple keyword variants one by one.