Skip to main content

Privacy-first document intelligence engine — converts PDFs, DOCX, PPTX, XLSX, and CSV into AI-ready Markdown + structured JSON for RAG pipelines.

Project description

LongParser

Privacy-first document intelligence engine for production RAG pipelines.

Parse PDFs, DOCX, PPTX, XLSX & CSV → validated, AI-ready chunks with HITL review.

CI PyPI Downloads Python MIT License Docs


Features

Feature Detail
Multi-format extraction PDF, DOCX, PPTX, XLSX, CSV via Docling
Hybrid chunking Token-aware, heading-hierarchy-aware, table-aware
HITL review Human-in-the-Loop block & chunk editing before embedding
LangGraph HITL approve / edit / reject workflow with LangGraph interrupt()
3-layer memory Short-term turns + rolling summary + long-term facts
Multi-provider LLM OpenAI, Gemini, Groq, OpenRouter
Multi-backend vectors Chroma, FAISS, Qdrant
Async-first API FastAPI + Motor (MongoDB) + ARQ (Redis)
LangChain adapters Drop-in BaseRetriever and LlamaIndex QueryEngine
Privacy-first All processing runs locally; no data leaves your infra

Installation

Core (SDK only — no API server)

pip install longparser

With REST API server (FastAPI + MongoDB + LLM)

pip install "longparser[server]"

All extras

pip install "longparser[all]"

Quick Start

Python SDK

from longparser import PipelineOrchestrator, ProcessingConfig

pipeline = PipelineOrchestrator()
result = pipeline.process_file("document.pdf")

print(f"Pages: {result.document.metadata.total_pages}")
print(f"Chunks: {len(result.chunks)}")
print(result.chunks[0].text)

REST API

# 1. Copy and edit configuration
cp .env.example .env

# 2. Start services (MongoDB + Redis)
docker-compose up -d mongo redis

# 3. Start the API
uv run uvicorn longparser.server.app:app --reload --port 8000

# 4. Upload a document
curl -X POST http://localhost:8000/jobs \
  -H "X-API-Key: your-key" \
  -F "file=@document.pdf"

# 5. Check job status
curl http://localhost:8000/jobs/{job_id} -H "X-API-Key: your-key"

# 6. Finalize and embed
curl -X POST http://localhost:8000/jobs/{job_id}/finalize \
  -H "X-API-Key: your-key" \
  -H "Content-Type: application/json" \
  -d '{"finalize_policy": "approve_all_pending"}'

curl -X POST http://localhost:8000/jobs/{job_id}/embed \
  -H "X-API-Key: your-key" \
  -H "Content-Type: application/json" \
  -d '{"provider": "huggingface", "model": "BAAI/bge-base-en-v1.5", "vector_db": "chroma"}'

# 7. Chat with the document
curl -X POST http://localhost:8000/chat/sessions \
  -H "X-API-Key: your-key" \
  -H "Content-Type: application/json" \
  -d '{"job_id": "your-job-id"}'

curl -X POST http://localhost:8000/chat \
  -H "X-API-Key: your-key" \
  -H "Content-Type: application/json" \
  -d '{"session_id": "...", "job_id": "...", "question": "What is the refund policy?"}'

Architecture

Document → Extract → Validate → HITL Review → Chunk → Embed → Index
                                                              ↓
                                             Chat → RAG → LLM → Answer

Pipeline Stages

  1. Extract — Docling converts PDF/DOCX/etc. into structured Block objects
  2. Validate — Per-page confidence scoring and RTL detection
  3. HITL Review — Human approves/edits/rejects blocks and chunks via the API
  4. ChunkHybridChunker builds token-aware RAG chunks with section hierarchy
  5. Embed — Embedding engine (HuggingFace / OpenAI) vectors stored in Chroma/FAISS/Qdrant
  6. Chat — LCEL chain with 3-layer memory and citation validation

Project Structure

src/longparser/
├── schemas.py           ← core Pydantic models (Document, Block, Chunk, …)
├── extractors/          ← Docling, LaTeX OCR backends
├── chunkers/            ← HybridChunker
├── pipeline/            ← PipelineOrchestrator
├── integrations/        ← LangChain loader & LlamaIndex reader
├── utils/               ← shared helpers (RTL detection, …)
└── server/              ← REST API layer
    ├── app.py           ← FastAPI application (all routes)
    ├── db.py            ← Motor async MongoDB
    ├── queue.py         ← ARQ/Redis job queue
    ├── worker.py        ← ARQ background worker
    ├── embeddings.py    ← HuggingFace / OpenAI embedding engine
    ├── vectorstores.py  ← Chroma / FAISS / Qdrant adapters
    └── chat/            ← RAG chat engine
        ├── engine.py    ← ChatEngine (LCEL + 3-layer memory)
        ├── graph.py     ← LangGraph HITL workflow
        ├── schemas.py   ← chat Pydantic models
        ├── retriever.py ← LangChain BaseRetriever adapter
        ├── llm_chain.py ← multi-provider LLM factory
        └── callbacks.py ← observability callbacks

LangChain Integration

from longparser.integrations.langchain import LongParserLoader

loader = LongParserLoader("report.pdf")
docs = loader.load()  # list[langchain_core.documents.Document]

LlamaIndex Integration

from longparser.integrations.llamaindex import LongParserReader

reader = LongParserReader()
docs = reader.load_data("report.pdf")

Configuration

Copy .env.example to .env and set:

Variable Default Description
LONGPARSER_MONGO_URL mongodb://localhost:27017 MongoDB connection
LONGPARSER_REDIS_URL redis://localhost:6379 Redis for job queue
LONGPARSER_LLM_PROVIDER openai LLM provider
LONGPARSER_LLM_MODEL gpt-4o Model name
LONGPARSER_EMBED_PROVIDER huggingface Embedding provider
LONGPARSER_VECTOR_DB chroma Vector store backend

Running with Docker

docker-compose up

API available at http://localhost:8000 · Docs at http://localhost:8000/docs


Testing

# Install dev dependencies
uv sync --extra dev

# Run unit tests
uv run pytest tests/unit/ -v

# Run with coverage
uv run pytest tests/ --cov=src/longparser --cov-report=term-missing

Contributing

See CONTRIBUTING.md for development setup and PR guidelines.

Security

See SECURITY.md for vulnerability reporting.

License

MIT — Copyright © 2026 ENDEVSOLS

Project details


Download files

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

Source Distribution

longparser-0.1.0.tar.gz (87.0 kB view details)

Uploaded Source

Built Distribution

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

longparser-0.1.0-py3-none-any.whl (94.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for longparser-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1287b542a0e348c54e5e8b7594c82ec8d5f672cee3c6f8f9b04924db26d7b0e0
MD5 54f6293bf0abb7d4a9bee5a3ac008ce2
BLAKE2b-256 dac5a640cc6cfb4540ad60b98956436467230071801f04dc96d01f423cc05053

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for longparser-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a45a4e3f70f30b4af7c0905ea84d88d1526ee2d6ea3b6248675b214ec8dc5881
MD5 1f8d002f5d33885c12ee5379c7c8486c
BLAKE2b-256 53efff4983bf1180d645fc2f06a95359d4175d3e76140ea160d590cc342b7b14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page