Gen AI Cheat Sheet
Quick reference guide for prompt engineering, sampling hyperparameters, Transformer math, RAG architecture, and fine-tuning.
Sampling Hyperparameters
| Command / Pattern | Description |
|---|---|
Temperature (T = 0.0 – 0.2) | Deterministic, greedy decoding. Best for code, math, factual extraction, and JSON schema formatting. |
Temperature (T = 0.7 – 1.0) | Higher entropy and creative variance. Best for brainstorming, creative writing, and open synthesis. |
Top-P / Nucleus (P = 0.9) | Truncates long-tail low-probability tokens by dynamically sampling top cumulative 90% probability mass. |
Presence Penalty (-2.0 – 2.0) | Penalizes tokens based on presence in generated text; positive values force model to introduce new topics. |
Frequency Penalty (-2.0 – 2.0) | Penalizes tokens based on exact occurrence count; positive values reduce verbatim word repetition. |
RAG Pipeline Steps
| Command / Pattern | Description |
|---|---|
1. Document Chunking | Split raw corpus using recursive character splitting (500–1000 tokens) with 10–20% chunk overlap. |
2. Dense Embedding | Convert chunks into dense vectors using embedding models (e.g. text-embedding-3-small). |
3. Vector Indexing (HNSW) | Index embeddings in vector store using Hierarchical Navigable Small World graphs for fast ANN lookups. |
4. Similarity Search | Query vector DB via Cosine Distance or Inner Product to fetch Top-K (K=3–5) context chunks. |
5. Prompt Synthesis | Inject retrieved context chunks into System/User prompt template before executing generation. |
Prompt Engineering Patterns
| Command / Pattern | Description |
|---|---|
Role & Persona Pattern | Begin prompt with explicit expert domain role (e.g. 'You are a Principal Kubernetes Architect...'). |
Few-Shot Examples Pattern | Provide 2–3 input/output demonstration pairs prior to presenting the target problem query. |
Chain-of-Thought (CoT) | Append 'Think step-by-step before producing your final answer' to force reasoning before generation. |
Structured JSON Output | Specify explicit JSON schema structure in system prompt and set `response_format: { type: 'json_object' }`. |
Transformer & Attention Formulas
| Command / Pattern | Description |
|---|---|
Scaled Dot-Product Attention | Softmax((Q * K^T) / sqrt(d_k)) * V — computes pairwise contextual token weights. |
Multi-Head Attention | Concat(head_1, ..., head_h) * W_O — projects queries/keys/values into parallel sub-spaces. |
LoRA Weight Update | W = W_0 + (B * A) * (alpha / r) — trains low-rank adapter matrices while keeping base weights frozen. |
