Codiqo

Understanding AI · lesson 47 of 60 · about 5 minutes

Context: What It Remembers

A chatbot doesn't remember the way you do. Find out what it can keep in mind, and what falls out.

What you'll learn

  • Explain what a context window is
  • Explain how a chat keeps track of earlier messages
  • Explain what happens when a chat gets too long

Reading the whole chat, every time

The model itself doesn't change while you chat. Instead, each time you send a message, the whole conversation so far is sent to it again, and it predicts what comes next from all of that text.

The amount of text it can look at once is its context window. It's measured in tokens.

When it overflows

If a chat gets longer than the context window, the oldest parts no longer fit. The model simply can't see them, so it may forget something you said at the start. Modern windows are large, but they always have a limit.

A pretend window that only fits the last 5 tokens. `[-5:]` takes the last five items.

chat = "my name is Sam and I like football and pizza".split()
window = chat[-5:]
print(window)

Output

['I', 'like', 'football', 'and', 'pizza']

Tip

The name Sam has fallen out of this window, so the model could no longer answer what's my name.

Now try it yourself

This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.