Context Placement Strategies
What you'll learn: Where to position retrieved documents in your prompt to maximize LLM performance in RAG systems.
The Context Placement Challenge
You've retrieved relevant documents and designed a prompt template. Now comes a critical decision: where exactly should those documents go? Should they appear before your instructions, after them, or woven throughout?
This isn't just cosmetic—LLMs exhibit different behaviors depending on where information appears in their context window.
Three Main Placement Strategies
Prefix Placement (Context First)
Place retrieved documents at the beginning of your prompt, followed by instructions and the user's question.
[Retrieved Document 1]
[Retrieved Document 2]
---
Instructions: Answer the following question...
Question: {user_query}
When to use: When you want the LLM to absorb context before receiving its task.
Suffix Placement (Context Last)
Place instructions first, then append retrieved documents at the end.
Instructions: Answer this question using only the context below.
Question: {user_query}
---
Context:
[Retrieved Document 1]
[Retrieved Document 2]
When to use: Research suggests LLMs often pay more attention to information at the start and end of prompts (the "lost in the middle" phenomenon).
Interleaved Placement
Mix instructions and context together, useful for multi-step reasoning or when documents relate to specific instruction segments.
When to use: Complex tasks where different documents support different reasoning steps.
Choosing Your Strategy
Consider your context window budget: prefix placement means the LLM processes context before instructions, while suffix placement lets instructions frame how the model should interpret context. Test both with your specific use case—results vary by model and task complexity.
Key Takeaway: Context placement affects LLM attention and performance; prefix and suffix are most common, with suffix often performing better due to recency bias and reduced "lost in the middle" effects.