How it works
The indexing and querying pipelines, step by step.
Two pipelines do the work. Indexing turns a document into a tree of sections. Querying walks that tree to answer a question. Indexing runs once per document. Querying runs once per question.
Indexing
Indexing starts when you hand it a file. Everything down to the tree runs locally, so the document itself never has to leave the machine.
A node stores its title, the line it starts on, and the text running up to the next heading. Step two calls no LLM, so it is free and returns the same tree every time. Most documents stop there.
Some come out flat, and buildIndexAuto repairs those. Which repair it reaches for depends on why the tree is flat, and the two cost very differently.
A document can have headings that all landed at one level. PDFs do this when nothing in the layout tells the parser which heading outranks which, and all three General Mills 10-Ks in our test set behave this way. The titles and line numbers are already right, so assignHeadingLevels sends the model the titles alone and asks only how deep each one sits.
A contract usually has no headings at all. There is nothing to nest, so reconstructTree sends the line-numbered text and asks the model where sections start. This is the expensive path, and it is bounded by the model’s context window: a 448 KB filing works out to roughly 133k tokens, which will not fit in 128k.
Both answers feed the same deterministic tree builder.
Querying
The agent never receives the document. It receives the table of contents and decides what to open.
If the section covers the question, the agent writes the answer and stops. If it does not, the agent goes back to the table of contents and tries somewhere else. Three to six passes is typical.
Why the tree stays small
A 28-page filing holds 66 KB of text, but the agent’s view of it is 1.6 KB:
whole document ████████████████████████████████████████ 66 KB
what the LLM sees █ 1.6 KB
The agent reads that 1.6 KB of titles and line numbers, picks one section, and pulls maybe 2 KB of real text. The other 64 KB never reaches the model. A longer document mostly means a longer list of titles, not a bigger prompt.
What it costs
Indexing is free unless the tree needs repairing or you enrich it, which are the steps that call an LLM. Repairing a flat tree costs one call per 60 headings when the headings exist, or one call over the whole document when they do not. Querying costs three to six LLM calls for a typical question. That number tracks how many times the agent has to look, not how long the document is, so a 300-page filing costs about what a 30-page one does.