0Pricing
Claude Architect · บทเรียน

ผลกระทบจากข้อมูลที่หายไปตรงกลาง

โมเดลอ่านตอนต้นและตอนท้ายได้เชื่อถือได้มากกว่าตอนกลาง

ผลกระทบจากข้อมูลที่หายไปตรงกลาง เป็นบทเรียน Claude Architect ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Claude Architect และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน

บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ

The Effect, Stated Plainly

When you pack a long prompt into Claude's context window, the model does not attend to every token equally. Information near the start and the end of the context is recalled far more reliably than information buried in the middle.

This is the lost-in-the-middle effect. It is not a bug you can patch — it is a property of how attention behaves over long inputs. As an architect, you design around it.

Why It Matters for Reliability

On the Claude Certified Architect exam, this sits in Domain 5: Context Management & Reliability. The practical risk: a critical instruction, policy rule, or transactional fact that you placed in the middle of a bloated prompt gets silently ignored.

The failure is quiet. The model still produces a fluent answer — it just dropped the constraint you cared about. That makes lost-in-the-middle a reliability problem, not a formatting preference.

Position Your Key Instructions

The simplest mitigation: put your most important instructions where attention is strongest. Lead with them in the system prompt, and restate the critical constraint at the end, right before the model generates.

Remember the API contract: the model keeps no state. You send the FULL messages history every turn. So every turn is a fresh chance — and a fresh risk — for middle content to be under-weighted.

resp = client.messages.create(
    model="claude-sonnet-4-5",
    max_tokens=1024,
    system=(
        "You are a refund agent. CRITICAL RULE: never "
        "process a refund before get_customer returns a "
        "verified ID."
    ),
    # ...long retrieved context goes in the middle...
    messages=messages,
)

Bookend the Critical Constraint

A robust pattern is to bookend: state the rule up front in system, then echo a short reminder of it as the final line of the last user turn. The start anchors it; the end keeps it top-of-mind at generation time.

Keep the echo short. You are not duplicating the whole instruction — just the single decision the model must not forget.

messages = [
    {"role": "user", "content": (
        retrieved_docs
        + "\n\n---\nReminder: cite a source URL for every "
          "claim. If a fact is absent from the docs above, "
          "say so explicitly — do not invent it."
    )},
]

Trim Verbose Tool Output

A major source of middle-bloat is raw tool output. An API or MCP tool can return hundreds of fields when you need three. Dumping all of it pushes your real signal into the low-attention middle.

Trim tool results to the relevant fields before appending them to the message history. Less noise in the middle means the model spends its attention on what matters.

def trim_order(raw: dict) -> dict:
    # keep only what the model needs to reason about
    return {
        "order_id": raw["order_id"],
        "status": raw["status"],
        "total": raw["total"],
        "refundable": raw["refundable"],
    }

# append the trimmed result, not the 200-field blob
messages.append({
    "role": "user",
    "content": [{
        "type": "tool_result",
        "tool_use_id": tu_id,
        "content": json.dumps(trim_order(raw_result)),
    }],
})

Keep Case Facts Verbatim

When context grows, teams reach for progressive summarization. Useful — but it makes numbers, percentages, and dates vague. Combined with lost-in-the-middle, a summarized transactional fact sitting mid-context is doubly fragile.

The fix: pull transactional facts into a separate "case facts" block kept verbatim, outside the summary. Don't let an order total or a refund threshold survive only as a paraphrase in the middle of a summary.

case_facts = (
    "CASE FACTS (verbatim, do not summarize):\n"
    "- order_id: A-4821\n"
    "- order_total: $612.40\n"
    "- refund_policy_cap: $500.00\n"
    "- customer_verified: true"
)

system = case_facts + "\n\n" + rolling_summary

/compact Has the Same Risk

In Claude Code, /compact compresses the conversation to free up context. The benefit is room to keep working; the risk is identical to progressive summarization: numbers and dates become vague.

Before compacting a session that hinges on exact values, capture those values somewhere durable — for example in CLAUDE.md via /memory, which persists across sessions — so they survive compaction rather than dissolving into a fuzzy middle summary.

# In a Claude Code session:
/memory   # write exact build numbers / API contract to CLAUDE.md
/compact  # now safe(r): the hard facts persist outside the summary

Order Retrieved Documents Deliberately

If you inject N retrieved chunks, their order changes what the model uses. The most relevant evidence should sit at the start or the end of the block — not at chunk number 7 of 14.

Two practical moves:

  • Re-rank so the highest-relevance chunks bracket the block.
  • Cut the block down. Fewer, sharper chunks beat a long tail of marginal ones diluting attention.
ranked = rerank(query, chunks)            # best first
top = ranked[:6]                          # cut the long tail
# bracket: strongest at start AND end
ordered = [top[0]] + top[2:] + [top[1]]
context = "\n\n".join(c.text for c in ordered)

Split Work, Don't Dilute Attention

Lost-in-the-middle is one reason single-pass multi-file review dilutes attention. Cramming ten files into one prompt buries the middle files.

Decompose instead: a per-file local pass, then a separate cross-file integration pass. Each pass has a focused, shorter context where nothing important is stranded in the middle.

# Multi-pass review (avoids single-prompt dilution)
for path in changed_files:
    review_local(path)        # focused, short context per file

review_cross_file(changed_files)  # separate integration pass

Subagents Need Explicit Context

Multi-agent systems are hub-and-spoke. Subagents do not inherit the coordinator's conversation history — every fact must be passed explicitly in each subagent prompt.

This intersects with lost-in-the-middle: when the coordinator builds that subagent prompt, the critical instructions still belong at the start and end, and verbose blobs still get trimmed. Context isolation is an opportunity to hand each subagent a clean, well-positioned prompt instead of an inherited mess.

Task(
    description="Summarize Q3 revenue",
    prompt=(
        "TASK: extract Q3 net revenue from the report below.\n"
        + report_text +
        "\n\nOUTPUT: a single number in USD, plus the source "
        "page. If absent, reply 'NOT FOUND'."
    ),
)

A Mental Checklist

Before you ship a long-context prompt, run this checklist:

  • Top: most important instruction in system, stated explicitly.
  • Bottom: short echo of the single critical constraint at the end.
  • Middle: trimmed tool output, re-ranked docs, no raw blobs.
  • Facts: exact numbers/dates kept verbatim in a case-facts block, never only in a summary.
  • Length: if it's huge, split into focused passes.

Position is design. Treat the middle as low-trust real estate.

Quick Check

Apply the lesson to a concrete architecture decision.

Recap

Key takeaways on the lost-in-the-middle effect:

  • Models attend to the start and end more than the middle — treat the middle as low-trust space.
  • Put critical instructions in system and echo the one constraint that matters at the end.
  • Trim verbose tool output and re-rank retrieved docs so signal brackets the context.
  • Keep exact numbers and dates verbatim in a case-facts block; summarization and /compact make them vague.
  • For large work, split into focused passes rather than one diluted prompt.
  • Position mitigates the symptom — but for rules with financial, legal, or safety stakes, enforce with hooks, not placement.

คำถามที่พบบ่อย

บทเรียน “ผลกระทบจากข้อมูลที่หายไปตรงกลาง” ฟรีหรือไม่

ใช่ — ข้อความเต็มของ “ผลกระทบจากข้อมูลที่หายไปตรงกลาง” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Claude Architect ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Claude Architect มีบทเรียนทั้งหมด 4 บทเรียน

คุณจะเรียนรู้อะไรในบทเรียน “ผลกระทบจากข้อมูลที่หายไปตรงกลาง”

โมเดลอ่านตอนต้นและตอนท้ายได้เชื่อถือได้มากกว่าตอนกลาง คุณปฏิบัติ Claude Architect ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน

คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Claude Architect หรือไม่

ไม่จำเป็นต้องมีประสบการณ์มาก่อน Claude Architect บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน

บทเรียน “ผลกระทบจากข้อมูลที่หายไปตรงกลาง” ใช้เวลานานแค่ไหน

บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย

ฉันเขียนและรันโค้ดในบทเรียน Claude Architect นี้ได้ไหม

ได้ บทเรียน Claude Architect ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ

บทเรียนทั้งหมดในหลักสูตรนี้

  1. ต้องใช้ประวัติทั้งหมด
  2. ความเสี่ยงของการสรุปแบบค่อยเป็นค่อยไป
  3. ผลกระทบจากข้อมูลที่หายไปตรงกลาง
  4. บล็อกข้อเท็จจริงของกรณีและการตัดผลลัพธ์
← กลับไปที่ Claude Architect