Native vs Docling¶
Pagelore reads files with its own loaders by default, and can use
Docling instead. Docling understands page layout
(reading order, table structure), but it is much slower. Whether that is
worth it depends on your files, so scripts/compare_extractors.py
measures it on your own documents.
What the script does¶
flowchart TB
F["your files"] --> N["project A<br/>native extractor"]
F --> D["project B<br/>Docling"]
N --> Q["questions<br/>(yours, or half from each project)"]
D --> Q
Q --> E["POST /evaluate on both"]
E --> R["side-by-side report"]
Against a running server with Docling installed (uv sync --extra
docling), it:
- creates two throwaway projects with the same chunking, one per extractor;
- uploads the same files to both, timing each file;
- gets test questions: yours (
--questions), or written by the server's LLM (--generate N). Generated questions come half from each project's chunks, so neither extractor has a home advantage; - pins each answer to a quote, so one question set works for both projects;
- evaluates both projects and prints the metrics side by side;
- deletes the projects (
--keepto look at them afterwards).
The report also lists:
- the questions only one extractor answered;
- the ingestion time per file, for each extractor;
- the files where Docling failed and the native loader read them instead;
- how many generated answers the other extractor did not extract word for word.
Run it¶
# Let the LLM write 40 questions, and save them
uv run python scripts/compare_extractors.py ~/contracts --generate 40 --save-questions q.json
# Rerun with the same questions and other chunking, and keep the full report
uv run python scripts/compare_extractors.py ~/contracts --questions q.json \
--chunking '{"chunk_size": 800}' --output report.json
| Argument | Default | |
|---|---|---|
paths |
Files or folders to upload. Unpack archives first: questions refer to files by name | |
--url |
http://localhost:8000 |
The Pagelore server |
--questions FILE |
Your questions (see below). One of --questions or --generate is required |
|
--generate N |
Have the server's LLM write N questions (1 to 400) | |
--seed |
1 |
Sample the same chunks again |
--instructions |
Extra guidance for the question writer | |
--min-chars |
server default (200) | Only ask about chunks this long |
--top-k |
5 |
Results per question |
--chunking |
project defaults | Chunking options for both projects, as JSON or a JSON file |
--configs |
vector, keyword, hybrid |
Retrieval configs, as JSON or a JSON file, as in POST /evaluate |
--keep |
off | Keep the two projects |
--save-questions FILE |
Write the questions, with their quotes, to rerun with --questions |
|
--output FILE |
Write the full report as JSON | |
--timeout |
1800 |
Seconds per request. Docling on a long PDF takes a while |
The questions file¶
Document ids differ between the two projects, so a questions file names files instead:
{"questions": [
{"id": "q1", "query": "How much did revenue grow in Q3?",
"relevant": [{"file": "report.pdf", "text": "revenue grew 12 percent"}]},
{"id": "q2", "query": "Who signs off on travel expenses?",
"relevant": [{"file": "travel.docx"}]}
]}
- A relevant item names a file, and optionally a quote the answer contains. Without a quote, any result from that file counts.
--save-questionswrites this format, so a generated set can be reviewed, edited and reused.
Why answers are pinned to quotes¶
A generated question uses its source.answer (the passage's words that
answer it) as the quote. A result counts only when its chunk contains the
quote, comparing words only (case, spacing, punctuation and Markdown are
ignored).
So the comparison measures whether the answer reached the chunk intact, not only whether retrieval found the right page. That is where extractors differ: two columns read across instead of down, for example, put the same words in the wrong order, and the check fails even though all the words are there.
Generating questions with a local model¶
--generate makes one LLM call per question.
- A local reasoning model can think for minutes and use thousands of tokens before it answers.
- A chunk whose reply fails is replaced by another one, with a warning.
- If they all fail, raise
LLM_TIMEOUTandLLM_MAX_TOKENS(the server log says which one ran out), or write the questions with a model that does not think. - With Ollama, its context window caps the reply too. Set
OLLAMA_CONTEXT_LENGTHon the Ollama server when the log still says the reply was cut.
Reading the results¶
- Keep the native extractor unless Docling wins clearly. It is the default because it is fast, needs no models, and reads most files well.
- Docling helps most on complex layouts: multi-column PDFs, and tables
whose structure matters. Use
DOCLING_EXTENSIONSto send only those file types to Docling. - Tables need room. With table-heavy files, small chunks split tables
apart for either extractor. Try a larger
chunk_size(around 2000 characters) in--chunkingbefore you decide. - Look at the per-file times as well as the metrics. Docling can take minutes on a long PDF that the native loader reads in seconds.