Dataset entry
Positional Strategy: Engineering Around 'Lost in the Middle' in Long Context + RAG
Positional Strategy: Engineering Around 'Lost in the Middle' in Long Context + RAG
Attribution
Creator: Dzmitryi Kharlanau (SAP Lead).
Canonical: https://dkharlanau.github.io/datasets/LLM-prompts/CE-02.json
JSON (copy / reuse)
{
"byte_id": "CE-02",
"title": "Positional Strategy: Engineering Around 'Lost in the Middle' in Long Context + RAG",
"category": "context_engineering",
"audience": [
"consultants",
"business_analysts",
"solution_architects"
],
"thesis": "Long-context LLMs are not position-robust: the same fact can be ignored or used depending on where it appears. Therefore, context placement and repetition are first-class design parameters (like indexes in databases), especially in RAG and multi-document reasoning.",
"research_basis": {
"phenomena": [
{
"name": "lost_in_the_middle",
"what_it_means": "Model performance is often highest when relevant info is near the beginning or the end, and degrades when relevant info is placed in the middle.",
"sources": [
"turn0search4",
"turn0search12"
]
},
{
"name": "more_retrieval_is_not_monotonic",
"what_it_means": "Adding more retrieved passages can help at first, then hurt (noise + distraction + position effects).",
"sources": [
"turn0search9"
]
},
{
"name": "attention_sink",
"what_it_means": "Early tokens can attract disproportionate attention due to transformer dynamics, which interacts with long-context behavior.",
"sources": [
"turn0search2",
"turn0search10"
]
},
{
"name": "positional_bias_calibration",
"what_it_means": "There are methods to mitigate middle-position failures by calibrating positional attention biases.",
"sources": [
"turn0search8",
"turn0search20"
]
}
],
"practical_implication": "If you don't control placement, you are gambling. 'Context engineering' includes ordering, anchoring, and redundancy."
},
"core_rules": [
{
"rule": "Front-load hard constraints.",
"why": "Critical constraints buried mid-context are less reliably followed in long prompts.",
"risk_if_ignored": "Model violates non-negotiables (security, scope, budget, SoR ownership)."
},
{
"rule": "Put the output contract at the end.",
"why": "Recency helps: the last instructions steer formatting and deliverable compliance.",
"risk_if_ignored": "Good analysis, wrong deliverable shape."
},
{
"rule": "Never rely on a single mention of a critical fact.",
"why": "Position sensitivity causes intermittent misses; redundancy is a reliability technique.",
"risk_if_ignored": "Random failures across runs or after small context changes."
}
],
"positional_design_patterns": [
{
"pattern_id": "PD-01",
"name": "Query Sandwich",
"intent": "Make the model repeatedly align to the task, reducing drift.",
"structure": [
"Top: 1-2 line task objective + constraints",
"Middle: evidence / retrieved chunks",
"Bottom: restated objective + explicit output contract"
],
"use_when": "RAG, long context, multi-doc analysis, policy-heavy tasks"
},
{
"pattern_id": "PD-02",
"name": "Anchor Tokens + Headings",
"intent": "Give the model strong navigational landmarks to stabilize attention.",
"structure": [
"### NON-NEGOTIABLES",
"### DEFINITIONS (GLOSSARY)",
"### FACTS (VERIFIED)",
"### ASSUMPTIONS (NEED CONFIRMATION)",
"### OPEN QUESTIONS",
"### OUTPUT CONTRACT"
],
"use_when": "Enterprise architecture, SAP landscapes, governance-heavy work"
},
{
"pattern_id": "PD-03",
"name": "Critical Facts Duplication (CFD)",
"intent": "Repeat only the few facts that must never be missed.",
"structure": [
"Place the same 3–7 critical facts in both: NON-NEGOTIABLES (top) and OUTPUT CONTRACT footer (bottom)"
],
"use_when": "High-stakes client deliverables, compliance, security"
},
{
"pattern_id": "PD-04",
"name": "Top-K + Diversity Retrieval",
"intent": "Avoid the 'more is worse' regime by controlling noise and redundancy.",
"structure": [
"Retrieve N (e.g., 20) -> rerank -> keep top K (e.g., 5–8) -> ensure topical diversity -> order by relevance"
],
"use_when": "RAG systems, long-context Q&A, research synthesis",
"research_hook": "Long-context LLMs in RAG show non-monotonic gains when increasing retrieved passages.",
"sources": [
"turn0search9"
]
},
{
"pattern_id": "PD-05",
"name": "Middle Rescue: Extract-Then-Reason",
"intent": "Reduce dependence on middle context by forcing extraction first.",
"structure": [
"Step 1: Extract relevant quotes/facts into a short 'Evidence Board' (<= 200 tokens)",
"Step 2: Reason ONLY over the Evidence Board"
],
"use_when": "When the model misses details in the middle or hallucinates connections"
}
],
"consulting_protocol": {
"name": "Position-Aware Context Assembly (PACA)",
"steps": [
{
"step": 1,
"action": "Identify 3–7 'critical facts/constraints' (CFC).",
"acceptance": "Each CFC is atomic, testable, and phrased as a rule."
},
{
"step": 2,
"action": "Place CFC at the top under NON-NEGOTIABLES.",
"acceptance": "CFC appear before any retrieved chunks."
},
{
"step": 3,
"action": "Insert evidence chunks; keep top K after reranking; delete near-duplicates.",
"acceptance": "Signal density is high; each chunk is used for a known purpose."
},
{
"step": 4,
"action": "Add a bottom footer with: task restatement + output contract + CFC repeated (CFD).",
"acceptance": "The model sees the contract last."
},
{
"step": 5,
"action": "Run a 'constraints recall check' before final answer.",
"acceptance": "If recall misses any CFC, you must re-anchor and rerun."
}
]
},
"templates": {
"constraints_recall_check": "Before solving, restate NON-NEGOTIABLES as 5 bullets. If any are missing, ask clarifying questions instead of proceeding.",
"paca_skeleton": [
"### NON-NEGOTIABLES (repeat critical rules here)",
"### GLOSSARY (lock terms here)",
"### FACTS (verified only)",
"### ASSUMPTIONS (explicit)",
"### EVIDENCE (top-K ordered chunks)",
"### TASK (one paragraph)",
"### OUTPUT CONTRACT (JSON schema + required sections; repeat NON-NEGOTIABLES)"
],
"evidence_board_schema": {
"evidence_items": [
{
"id": "E1",
"fact": "Atomic extracted fact",
"source_chunk_id": "C3",
"confidence": "high|medium|low"
}
],
"rules": [
"Reason only over evidence_items. If something is missing, request it explicitly."
]
}
},
"anti_patterns": [
{
"name": "Unbounded Retrieval Dump",
"symptom": "You append 15–50 chunks because the model supports long context.",
"damage": "Performance declines due to noise + distraction + position sensitivity.",
"fix": "Top-K + rerank + diversity + ordering.",
"research_hook": "Non-monotonic effect of adding passages in RAG with long-context LLMs.",
"sources": [
"turn0search9"
]
},
{
"name": "Middle-Only Critical Detail",
"symptom": "The only mention of the key constraint sits inside a long evidence chunk.",
"damage": "Intermittent constraint violation ('randomness' that is actually position bias).",
"fix": "Critical Facts Duplication + Query Sandwich.",
"research_hook": "U-shaped utilization and middle-position drop.",
"sources": [
"turn0search12"
]
}
],
"success_metrics": [
{
"metric": "constraint_recall_rate",
"definition": "Percent of runs where the model correctly restates all CFC before solving.",
"target": ">= 0.95"
},
{
"metric": "constraint_compliance_rate",
"definition": "Percent of outputs that satisfy all CFC without manual correction.",
"target": ">= 0.90"
},
{
"metric": "evidence_usage_density",
"definition": "How many provided chunks are actually cited/used by the model.",
"target": "High; unused chunks are removed in next iteration."
}
],
"next_byte_suggestion": {
"byte_id": "CE-03",
"title": "Retrieval as a Product: RAG Refinement, Compression, and Long-Context Noise Control"
},
"citations": [
{
"topic": "lost_in_the_middle",
"refs": [
"turn0search4",
"turn0search12"
]
},
{
"topic": "rag_non_monotonic_passages",
"refs": [
"turn0search9"
]
},
{
"topic": "attention_sink",
"refs": [
"turn0search2",
"turn0search10"
]
},
{
"topic": "positional_bias_mitigation",
"refs": [
"turn0search8",
"turn0search20"
]
}
],
"meta": {
"schema": "dkharlanau.dataset.byte",
"schema_version": "1.1",
"dataset": "LLM-prompts",
"source_project": "cv-ai",
"source_path": "LLM-prompts/CE-02.json",
"generated_at_utc": "2026-02-03T14:33:32+00:00",
"creator": {
"name": "Dzmitryi Kharlanau",
"role": "SAP Lead",
"website": "https://dkharlanau.github.io",
"linkedin": "https://www.linkedin.com/in/dkharlanau"
},
"attribution": {
"attribution_required": true,
"preferred_citation": "Dzmitryi Kharlanau (SAP Lead). Dataset bytes: https://dkharlanau.github.io"
},
"license": {
"name": "",
"spdx": "",
"url": ""
},
"links": {
"website": "https://dkharlanau.github.io",
"linkedin": "https://www.linkedin.com/in/dkharlanau"
},
"contact": {
"preferred": "linkedin",
"linkedin": "https://www.linkedin.com/in/dkharlanau"
},
"canonical_url": "https://dkharlanau.github.io/datasets/LLM-prompts/CE-02.json",
"created_at_utc": "2026-02-03T14:33:32+00:00",
"updated_at_utc": "2026-02-03T15:29:02+00:00",
"provenance": {
"source_type": "chat_export_extraction",
"note": "Extracted and curated by Dzmitryi Kharlanau; enriched for attribution and crawler indexing."
},
"entity_type": "llm_prompt_byte",
"entity_subtype": "category:context_engineering",
"summary": "Positional Strategy: Engineering Around 'Lost in the Middle' in Long Context + RAG"
}
}