Metadata-Version: 2.5
Name: langchain-readanydoc
Version: 0.1.0
Summary: LangChain document loader for ReadAnyDoc: PDFs, scans, photos and Office files to Markdown, one Document per page, with page numbers and block positions
Project-URL: Homepage, https://readanydoc.com/
Project-URL: Documentation, https://readanydoc.com/docs/guides/integrations/
Project-URL: Repository, https://github.com/arpitpatel25/ReadAnyDoc
Project-URL: Issues, https://github.com/arpitpatel25/ReadAnyDoc/issues
Author-email: Arpit Patel <arpit@readanydoc.com>
License-Expression: Apache-2.0
License-File: LICENSE
Keywords: document-loader,document-parsing,langchain,ocr,pdf,rag,readanydoc
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Text Processing
Requires-Python: >=3.12
Requires-Dist: langchain-core>=0.3
Requires-Dist: readanydoc[engine]>=0.4.11
Description-Content-Type: text/markdown

# langchain-readanydoc

A LangChain document loader for [ReadAnyDoc](https://readanydoc.com/), the open-source (Apache-2.0) document
parser. It turns PDFs, scans, photos and Office files into Markdown `Document`s, one per page, each with its page
number so an answer can point back to where it came from.

ReadAnyDoc runs on your own machine. Pages are read by a vision model on your own model account (Claude Haiku 5.5
by default), so there is no parsing service to sign up for and your files are not uploaded to one.

## Install

```bash
pip install langchain-readanydoc
export ANTHROPIC_API_KEY=...        # the default model is Claude Haiku 5.5
```

It also needs Tesseract for scans: `brew install tesseract` or `apt install tesseract-ocr`. The layout and OCR
weights (about 200 MB) download on first use, so the first parse takes a few minutes longer. Python 3.12 or 3.13.

## Use

```python
from langchain_readanydoc import ReadAnyDocLoader

docs = ReadAnyDocLoader("report.pdf").load()     # one Document per page

docs[0].page_content    # Markdown, tables as HTML
docs[0].metadata        # {"source": "report.pdf", "page": 1}
```

Into a vector store, the usual way:

```python
from langchain_core.vectorstores import InMemoryVectorStore
from langchain_openai import OpenAIEmbeddings

docs = ReadAnyDocLoader(["q3-report.pdf", "contract.docx", "scan.jpg"]).load()
store = InMemoryVectorStore.from_documents(docs, OpenAIEmbeddings())
store.similarity_search("termination notice period", k=3)[0].metadata   # source and page
```

## Options

| Argument | What it does |
|---|---|
| `split="page"` | one Document per page (default) |
| `split="block"` | one Document per title, paragraph, table and so on; metadata adds `block_type`, `bbox` and `confidence` |
| `split="document"` | the whole file as one Document |
| `mode="model-only"` | faster and cheaper, without block positions |
| `pages=[1, 2]` | only these pages |
| `model=...` | another vision model: any Claude model, OpenAI models, or an OpenAI-compatible endpoint (`openai_compatible:<model>@<base_url>`). The numbers below are for Claude Haiku 5.5 |

Any other keyword goes to [`readanydoc.parse`](https://readanydoc.com/docs/guides/parse/). `lazy_load()` works too,
and yields pages as each file finishes.

The first Document of a file carries `warnings` in its metadata when ReadAnyDoc reported any, for example a page
the model provider declined to read.

## What to expect

Measured on public benchmarks with Claude Haiku 5.5, against Reducto's hosted API on the same pages:

- olmOCR-bench (1,403 pages): 85.4 against 80.9
- OmniDocBench text error (1,651 pages, lower is better): 0.050 against 0.095
- tables (RD-TableBench): 88.84 against 88.85

It is slower: 20-50 seconds a page against about 4, although the pages of one document are read in parallel. Cost
is about $0.003-0.005 a page on your own model account. Every score, including the ones it loses, is in
[BENCHMARKS.md](https://github.com/arpitpatel25/ReadAnyDoc/blob/main/BENCHMARKS.md).

Typed extraction with a citation box for every value is not part of the loader. For that, call
[`readanydoc.extract`](https://readanydoc.com/docs/guides/extract/).

## Links

- ReadAnyDoc: https://github.com/arpitpatel25/ReadAnyDoc
- Docs: https://readanydoc.com/docs/guides/integrations/
- Issues: https://github.com/arpitpatel25/ReadAnyDoc/issues

Apache-2.0.
