Prompt Engineering: The Context Window
The context window is the model's working memory. The prompt, the conversation and the answer all share one window.
A short prompt leaves room
A short prompt leaves plenty of room in the window. The model sees the whole job at once.
You are a support agent for ShopStack. Maya asks where order 1042 is. Order 1042 is shipped and out for delivery. Write a short reply.A long prompt fills the window
A long prompt fills the window with facts the question does not need. The model still answers, but little room is left.
ShopStack sells the Aurora Ceramic Mug for $18, the Hearthstone Desk Lamp for $42, the Trailhead Canvas Tote for $26, the Ember Pour-Over Set for $35 and the Willow Linen Cushion for $29. Returns run 30 days for unused items. Shipping is free over $35, otherwise $4.95. Delivery takes 2 to 4 business days. Order 1042 is Maya's Aurora Ceramic Mug, shipped and out for delivery. Order 1043 is Tom's Hearthstone Desk Lamp, still processing. Order 1044 is Priya's tote and pour-over set, delivered. Write a short reply to Maya about order 1042.Example
You are a support agent for ShopStack. Write a short reply to Tom about order 1043. His lamp is still processing and has not shipped yet.Key points
- The context window holds everything the model can see at once.
- The prompt, the earlier messages and the new answer all share the same window.
- A long conversation fills the window. Old messages drop out when it fills up.
- Short prompts leave more room for the answer.
This example runs a short prompt against the local model and shows the reply it gave.
Note
The model cannot see past the window. What drops out is gone.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Rust Playground
Exercise
What happens when the context window fills up?