Metadata-Version: 2.4
Name: lightrag-section-anything
Version: 0.1.1
Summary: Section Anything PDF parser engines for LightRAG: accurate headings for heading-aware chunking, with a cost/accuracy dial.
Author: The Section Anything Authors
License-Expression: Apache-2.0
Project-URL: Homepage, https://github.com/Omniwot/section-anything/tree/main/packages/lightrag-section-anything
Project-URL: Repository, https://github.com/Omniwot/section-anything
Project-URL: Issues, https://github.com/Omniwot/section-anything/issues
Keywords: lightrag,parser,plugin,pdf,sections,headings,rag,chunking
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Text Processing :: General
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Requires-Dist: section-anything<0.2,>=0.1.4
Requires-Dist: lightrag-hku<1.7,>=1.5.7
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# lightrag-section-anything

LightRAG parser engines that turn a PDF into heading-aware blocks (`.blocks.jsonl`) using the
[`section-anything`](https://github.com/Omniwot/section-anything) library, so LightRAG's
heading-based chunker ("P") and its heading context work on PDFs without a MinerU or Docling
service.

## Install

```sh
pip install lightrag-section-anything
# latest from GitHub:
pip install "git+https://github.com/Omniwot/section-anything#subdirectory=packages/lightrag-section-anything"
```

Python 3.11+. Depends on `section-anything` and `lightrag-hku` (1.5.7 or later, below 1.7); the
LightRAG server needs `lightrag-hku[api]`. The engines register through LightRAG's
`lightrag.parsers` entry point, which the LightRAG server (`lightrag-server`) and the parser debug
CLI (`python -m lightrag.parser.cli`) load at startup. When you embed LightRAG as a library, call
`load_third_party_parsers()` from `lightrag.parser.plugins` first.

## Engines

| Engine | Runs | Cost per 1,000 pages |
|---|---|---|
| `sectionany_free` | rules (bookmarks, contents, typography) | $0 |
| `sectionany_quick` | rules + a small model reviewing candidate lines | about $0.07 |
| `sectionany_standard` | a model reading all lines | about $0.16 (gpt-6-luna, the default); $2.90 with gpt-6.1-sol |
| `sectionany_local` | quick-style review on a local Ollama model (`SECTIONANY_LOCAL_MODEL`) | $0 |
| `sectionany` | the mode in `SECTIONANY_MODE` (default `free`) | |

## Use

Route PDFs to an engine with LightRAG's `LIGHTRAG_PARSER` rules, for example:

    LIGHTRAG_PARSER=pdf:sectionany_quick-P,pdf:sectionany-P,*:native-teP,*:legacy-R

Settings are the library's `SECTIONANY_*` environment variables (see its README): API key
(`SECTIONANY_API_KEY`, else `OPENAI_API_KEY` for OpenAI's endpoint or `ANTHROPIC_API_KEY` for
Claude models), models, prices,
`SECTIONANY_MAX_USD_PER_DOC` (default 0.50), `SECTIONANY_OVER_BUDGET=downgrade|fail`,
`SECTIONANY_MAX_PAGES` (500), `SECTIONANY_MAX_MB` (100), `SECTIONANY_EXTRACT_TIMEOUT_SECONDS`
(120). The plugin adds `SECTIONANY_MODE`, `SECTIONANY_SYNTHETIC_TITLES` and
`MAX_PARALLEL_PARSE_SECTIONANY` (default 2). Nothing is written to the process environment, so
LightRAG's own model settings are untouched. Cost, model and mode per document are reported in
LightRAG's document status (`parse_warnings`) and in `<name>.sectionany.json`.

Tests: `SECTIONANY_TEST_PDF=<some.pdf> pytest packages/lightrag-section-anything/tests`.

Not yet: tables as tables, images, OCR, re-levelling MinerU/Docling output, a section-path
prefix inside embeddings (needs LightRAG's chunker plugins, 1.5.8+).
