Context window là số token tối đa model có thể "nhìn thấy" cùng lúc — bao gồm cả prompt (system + user + history) và output đang sinh. Ví dụ GPT-4.1 128K, Claude 4 Sonnet 200K, Gemini 2.x up to 2M (tính đến 2025).
Tại sao quan trọng:
- Giới hạn input — tài liệu dài, conversation history, code base phải vừa trong cửa sổ.
- Chi phí & latency — attention là O(n²) theo độ dài context nên context dài → inference chậm và đắt hơn.
- Chất lượng suy giảm — hiện tượng "lost in the middle": model thường chú ý kém với thông tin ở giữa context dài.
Các kỹ thuật xử lý khi vượt context: sliding window / truncation giữ các phần quan trọng nhất, summarization gói gọn history cũ, RAG chỉ retrieve đoạn liên quan thay vì đẩy hết tài liệu vào, prompt compression (LLMLingua) nén prompt, hierarchical processing chia nhỏ rồi tổng hợp.
The context window is the maximum number of tokens the model can see at once — including prompt (system + user + history) and the output being generated. E.g. GPT-4.1 128K, Claude 4 Sonnet 200K, Gemini 2.x up to 2M (as of 2025).
Why it matters:
- Input limit — long documents, conversation history, codebases must fit.
- Cost & latency — attention is O(n²) in context length, so longer context means slower and more expensive inference.
- Quality degrades — the "lost in the middle" phenomenon: models often pay less attention to info in the middle of long contexts.
Handling overflow: sliding window / truncation keep the most important parts, summarization compresses old history, RAG retrieves only relevant chunks instead of dumping entire documents, prompt compression (LLMLingua), hierarchical processing split-then-aggregate.