How to Split a Long PDF into Chunks That Fit a Context Window
Split a long PDF into chunks that fit a context window by cutting on section breaks, not mid-sentence.
THE FIELD GUIDE
Understand model formats, context windows, quantization, embeddings, and sampling before choosing settings for a real task.
Split a long PDF into chunks that fit a context window by cutting on section breaks, not mid-sentence.
Verify a prompt cache hit from the response usage fields instead of assuming the cache worked.
Place a cache breakpoint on the last block that stays the same from one request to the next.
Choose the 5-minute cache lifetime for chatty sessions and the 1-hour lifetime when requests are spaced further apart.
Cache a repeated system prompt with Claude prompt caching so later requests reuse it instead of reprocessing it.
Trim chat history to recent turns when the conversation grows past the context window, keeping the turns that matter.
Set num_ctx in Ollama for a long document so the runtime reserves a window big enough to hold it.
Check a model's advertised context window against the runtime default, because the runtime may give you far less.
Fit a long document into a context window by summarizing it first and sending the summary with your question.
Estimate the tokens in a long prompt before sending it so you know whether it fits the context window.