AI Engineering · Cheat Sheet

Production Rules of Thumb

Fast engineering heuristics for sizing context windows, tuning retrieval precision, and gating production deployments.

Open Glossary →

Token & Context Math

Sizing & Latency

Quick mental rules for budgeting prompt windows and unit costs.

  • 1 token ~ 3.5–4 English characters (~0.75 words); JSON keys and UUIDs inflate token counts 1.5–3x.
  • Output tokens cost 3–5x more than input tokens and dominate total wall-clock latency.
  • Keep RAG chunks to ~300–600 tokens with 10–15% overlap and parent section headers.

Temperature & Decoding Presets

Inference Config

Pick deterministic decoding for code/data boundaries and higher entropy only for ideation.

  • 0.0: Classification, SQL generation, structured JSON extraction, CI evals.
  • 0.2–0.4: Code review, RAG synthesis with strict citation adherence.
  • 0.7–1.0: Brainstorming, marketing copy, synthetic test-case generation.

RAG Upgrade Ladder

Retrieval Precision

Fix retrieval quality in order before jumping to complex agentic loops or fine-tuning.

  • 1. Clean structure-aware chunking + metadata ACL filtering.
  • 2. Hybrid search (BM25 lexical + dense embeddings) fused via RRF.
  • 3. Cross-encoder reranker (top 40 -> top 5) before prompt injection.
  • 4. Agentic query rewriting / multi-hop routing only when single-pass recall plateaus.

Production Readiness Checklist

Reliability Gate

Minimum engineering bars before shipping an AI feature to customers.

  • Enforce Pydantic/JSON schemas at every AI-to-code boundary.
  • Cap agent loops with max_steps, request timeouts, and per-user token budgets.
  • Log OpenTelemetry traces (prompts, retrieved doc IDs, latency, cost) with PII redaction.
  • Run a 30–50+ case golden eval suite in CI on every prompt or model version bump.