Drop a 300-page legal brief or a bound annual report into most OCR pipelines, and the software will quietly break it into chunks. Page one, process, flush memory. Page two, process, flush memory. By the time the system reaches the exhibits at the back, any context it might have gleaned from the introduction is long gone. Footnotes become orphans. Tables split across pages lose their structure. Headers that continue across pages get mislabeled. The result is a stitched-together text file that a human has to reassemble.

Baidu thinks this workflow is fundamentally broken. Their answer is Unlimited OCR, an architecture designed to ingest massive, multi-page documents in a single forward pass without the GPU memory explosion that usually follows. The trick is a new attention mechanism that treats memory less like a hard drive and more like human working memory: keep the source material in front of you, remember what you just wrote, and let the distant past fade.

Why Long Documents Kill Standard OCR

To understand the fix, it helps to see where conventional end-to-end OCR systems fall apart.

Most modern OCR pipelines use a large language model as their decoder. As the model reads a page and generates text, it stores internal representations called a KV cache—essentially a running diary of keys and values that help the model keep track of what it has already said. The problem is that this diary grows linearly with every new line of output. Process ten pages, and the cache is ten pages deep. Process a hundred, and it balloons to hundreds of thousands of tokens, chewing through VRAM and throttling generation speed to a crawl.

Engineers have dealt with this by simply not dealing with it. They cut documents into single pages, run each page through the model independently, and reset the KV cache between every step. It keeps the lights on, but it also strips the model of any continuous thread. A paragraph that starts on page three and finishes on page four gets bisected. Cross-page table formatting disintegrates. References to earlier sections turn into broken links because the decoder has no persistent memory of what came before. The model is not really reading the document; it is doing a series of isolated flashcards.

The Human Trick: Reference Sliding Window Attention

Baidu’s researchers attacked this by borrowing a page from human cognition. Think about manually copying a passage out of a book. You do not keep every previously copied sentence loaded in your mind. You glance at the source, look at the last few words you wrote, and continue. Your working memory is tiny, but because the source text stays open in front of you, the task is effortless.

Reference Sliding Window Attention, or R-SWA, formalizes exactly this intuition.

Under the hood, the KV cache becomes a fixed-length queue. When the model generates a new token, it retains full visibility of the "reference tokens"—the original visual image embeddings and the initial prompt—but it only looks back at the last 128 tokens it has personally generated. That is it. Whether the model is on page one or page fifty, the memory footprint of its own output history stays locked in place. The cache does not grow. It recycles.

This is a