How does a sliding-window memory keep a chat under budget, and what does it always lose?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Sliding-window memory keeps only the last N turns verbatim and drops older ones. It is cheap and deterministic, but anything older than the window vanishes with no summary or substitute to replace it.
Imagine a fridge with a strict rule: only the five most recent items stay, anything older gets thrown out. No leftover gets summarized into a note on the door, no fridge inventory gets kept somewhere else. It is simple, the fridge never overflows, but the milk you bought last week is gone the moment the sixth item arrives. A sliding-window chat memory works the same way. The last few turns are kept word for word, anything older drops off the back, and nothing replaces them. The bot behaves as if those old turns never happened.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Define the sliding-window pattern as a FIFO over turns or tokens. Walk through the wins (cost, determinism, debuggability). Walk through the one thing it loses (everything older than the window). Cover the choice of N or K and how to tune it. Close with the production composition where sliding window is paired with summary and fact-store layers.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking the dropped turns get summarized somewhere. In a pure sliding window, no summary is created and the dropped content is genuinely lost.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.