← chapter

Long context and document Q&A

Chapter 15 · when the whole document just fits

The hour

The anti-RAG

RAG existed because documents didn't fit. Now many do.

Barely any new API

def ask(document, question):
    r = client.responses.create(
        model="gpt-5.4-nano",
        instructions=f"Answer using this document.\n\n{document}",
        input=[{"role": "user", "content": question}])
    return r.output_text

What's new is the scale of what goes in instructions.

Long context vs RAG

Long contextRAG
Fits, can't missScales past any window
Re-reads all each callFetches only what's needed
Single, stable docLarge, changing corpus

Not "better" — situational.

Two hidden costs

Put it to work — three apps

Takeaway

Fits the window? Paste it and skip retrieval. Big or changing corpus? RAG. Mind the token bill and the lost middle. Next: prompt caching, cost, and latency — the money made explicit.