a builder's codex
codex · operators · Hamel Husain · ins_husain-retrieval-first-hierarchy

Optimize retrieval and context before touching systems, and post-train only after exhausting both

By Hamel Husain · AI product advisor and ML educator; co-creator of AI Evals for Engineers course · 2026-08-12 · essay · AI Product Engineering Notes

Tier B · TL;DR
Optimize retrieval and context before touching systems, and post-train only after exhausting both

Claim

AI product improvements should follow a specific sequence: retrieval and context first, then systems and harness, then post-training. Jumping to post-training before exhausting the first two stages wastes time and money on the highest-cost option.

Mechanism

Retrieval improvements use the same model more effectively at no model cost. Systems and harness improvements reduce failure modes and overhead without retraining weights. Post-training requires labeled data, compute budget, and a retraining loop that takes days to weeks. Each stage is cheaper and faster than the next. Teams that skip to post-training discover later that retrieval fixes would have closed 80% of the error cases. Husain also notes that nearly every improvement in his 13-session course begins with good evals, placing measurement as the foundation that makes the sequence possible.

Conditions

Holds when: the base model is fundamentally capable of the task and errors come from context gaps or harness failures rather than capability limits; evals exist to measure each stage's impact before moving to the next.

Fails when: the base model genuinely lacks the capability the task requires; or when the task is so domain-specific that retrieval cannot close the gap regardless of volume or quality.

Evidence

Husain organized 13 sessions of his AI product engineering curriculum around this hierarchy. Five of 13 sessions address context improvements (multivector retrieval, search agents, embeddings, OCR, agent steering). He states the sequence directly: "The lowest-hanging fruit is to optimize retrieval and context. Once that's done, you should improve your systems and harness. Finally, consider post-training your own model after other approaches are exhausted."

Signals

Counter-evidence

The hierarchy assumes retrieval is a meaningful lever for the product's error types. For tasks requiring specialized reasoning, nuanced tone, or proprietary formats, retrieval improvements may hit a ceiling quickly. In those cases, post-training earlier can be more efficient than exhausting retrieval iterations that never close the gap.

Cross-references

Open the interactive view → View original source → Markdown source →