Skip to main content
AI · patterns

Pattern library

18 patterns. Every entry documents: problem statement, naive approach + why it fails, correct mental model, step-by-step solution, code example, trade-offs, failure modes, when to use / not to use, and citations.

Author me

RAG — Retrieval-Augmented Generation

Ground your LLM in your own data. The single most-adopted pattern in production AI.

Author me

ReAct agent loop

Reason + Act + Observe. The pattern that turns an LLM into an agent.

Author me

Reflexion loop

Self-critique and retry. How agents recover from their own mistakes.

Author me

Tree-of-Thought

Explore multiple reasoning paths, prune, backtrack. When linear CoT isn't enough.

Author me

Hybrid search with Reciprocal Rank Fusion

Dense + sparse retrieval combined by RRF — the RAG upgrade that beats vanilla.

Author me

Query decomposition

Break a complex question into sub-questions before retrieval.

Author me

HyDE — Hypothetical Document Embedding

Ask the LLM to write the answer, then embed THAT and retrieve.

Author me

Prompt compression

Cut your tokens 50-80% without losing quality — LLMLingua and friends.

Author me

Prompt caching

Cache the invariant prefix of your prompt for 10x cost savings on repeat requests.

Author me

LLM as judge

Use one LLM to grade another's output — with the caveats.

Author me

Output parsing with retries

How to reliably get JSON out of an LLM.

Author me

Streaming + tool use

The UX pattern that makes agents feel fast.

Author me

Multi-agent orchestration

Orchestrator + workers, hierarchical, or market-based — when each wins.

Author me

Input & output guardrails

The defense-in-depth pattern for safe LLM apps.

Author me

Model routing

Route cheap queries to Haiku, hard queries to Opus — with the eval to prove it.

Author me

Batch inference

50% cost savings for non-real-time workloads.

Author me

Shadow-mode evaluation

Ship two models side-by-side, log both, compare in prod without user impact.

Author me

Prompt injection defense

Input filtering, output filtering, privilege separation, sandboxing — the layered defense.