概念概述
上下文窗口(The Context Window)指的是:模型的上下文窗口限制其一次能考虑的 token 数量,这一硬上限决定截断、成本以及可提供的检索文本量。
从更严格的定义看,The context window is the maximum number of tokens a language model can attend to in a single request, comprising the system prompt, conversation history, retrieved context, and the generated completion. 该概念在工程实践中的价值,在于它能帮助团队用统一的语言描述一个具体的质量属性或设计约束,从而在评审与协作中减少歧义。
为什么需要它
It is a primary constraint when designing prompts, retrieval pipelines, and multi-turn conversations. 它与 Prompt Injection、Semantic Caching、Document Chunking Strategies 等概念经常一起出现,用于解决相近的工程问题。理解它的适用场景,有助于在多种备选方案之间做出有依据的取舍,而不是凭直觉选择技术方案。
常见误解
- text within the window is always used equally well
- a larger window eliminates the need for retrieval or summarisation
需要避免的反模式
- filling the window with low-value context and crowding out instructions
- never truncating history and silently dropping the system prompt
实践要点
- Every part of a request competes for the same budget, so a long retrieved document can push out conversation history or instructions without warning.
- Attention degrades with position, and content in the middle of a very long input is often used less reliably, which favours putting key facts near the edges.
- Managing the window means selecting, summarising, or dropping content deliberately rather than letting a naive concatenation overflow.