How we built a Python pipeline to chunk books, preserve context, and maintain consistent terminology across hundreds of chapters.

The Problem: Translating a Whole Book, Not Just a Page

At LectuLibre, we let users upload an EPUB or PDF and get back a professionally translated book. The tricky part isn't calling an LLM—it's doing it across 100,000+ words without losing the plot, literally.

Naively, you might split the book into chunks that fit the LLM's context window and translate each independently. We tried that first. The result: names changed spelling halfway through, terminology was inconsistent, and dialogue references to earlier events sometimes made no sense. The story fell apart.

Context windows are huge now (Claude's 200k tokens, GPT-4 Turbo's 128k), but even those aren't enough for a full novel—and even if they were, cost and quality degrade with massive inputs. So we needed a chunking strategy that respects the document's structure and carries context across chunks.