Skip to content
AI360Xpert
Cheat Sheets
Cheat sheet

Generative Ai Cheat Sheet

A comprehensive guide for Generative Ai Cheat Sheet

🧠 Generative AI Cheat Sheet — Complete Cheat Sheet

1. Generative AI Fundamentals
TopicDescription
Generative modelA model that learns a data distribution well enough to generate new samples such as text, images, audio, or code.
Discriminative vs generativeDiscriminative models focus on predicting labels/decision boundaries; generative models model how data can be produced.
Foundation modelLarge pretrained model adapted to many downstream tasks through prompting, retrieval, fine-tuning, or tool use.
Multimodal modelA model that can process or generate more than one modality, such as text plus image or audio.
2. Tokens and Context
TopicDescription
TokenA unit used by a model tokenizer; it may be a word, subword, character fragment, or other encoding.
Context windowThe maximum amount of model input/output context the model can attend to in one invocation; practical limits depend on the deployed model.
Token budgetThe number of input/output tokens affects latency, cost, and how much information can be supplied.
Tokenization effectsCode, rare words, long identifiers, and some languages may tokenize differently; never equate token count directly with word count.
3. Transformer Architecture
TopicDescription
Self-attentionAllows each token representation to incorporate information from other tokens through query/key/value interactions.
Attention formula`Attention(Q,K,V) = softmax(QKᵀ / sqrt(d_k))V`.
Multi-head attentionUses several learned projections so the model can represent different relationships in parallel.
Feed-forward networkApplies a learned nonlinear transformation independently to each sequence position after attention.
Residual connectionAdds a layer's input back to its output to improve optimization and preserve information flow.
NormalizationLayer normalization or related normalization stabilizes activations and training.
4. LLM Training Stages
TopicDescription
PretrainingTrain on broad data to learn general language/statistical representations, often using next-token or related self-supervised objectives.
Supervised fine-tuningTrain on curated input/output examples to teach task behavior, formatting, and instruction following.
Preference optimizationUse human or synthetic preference signals to make outputs align better with desired behavior; implementation can use several objective families.
Continued pretrainingTrain a pretrained model further on domain-specific or newly available corpora when additional domain adaptation is needed.
5. Next-Token Prediction
TopicDescription
ObjectiveFor tokens `x₁...x_T`, minimize negative log-likelihood of the next token: `L = -Σ_t log P(x_t | x_<t)`.
LogitsThe model outputs unnormalized scores; softmax converts them into token probabilities when needed.
Cross-entropyStandard next-token training loss based on the negative log probability assigned to the correct token.
6. Decoding
TopicDescription
Greedy decodingChoose the highest-probability next token each step; simple and deterministic but may be less diverse.
SamplingRandomly sample from a probability distribution to produce diverse outputs.
TemperatureTransforms logits before softmax; lower values make the distribution sharper, higher values more diverse.
Top-kRestrict sampling to the highest-probability `k` tokens.
Top-p / nucleusSample from the smallest token set whose cumulative probability reaches threshold `p`.
Repetition controlsFrequency/presence penalties or decoding constraints can reduce repetitive output depending on the model/API.
7. Embeddings
TopicDescription
EmbeddingDense vector representing semantic or task-relevant information about text, code, images, users, products, or other objects.
SimilarityCosine similarity is common: `cos(x,y)=(x·y)/(||x||||y||)`.
Vector searchStore embeddings and retrieve nearest neighbors for semantic search, recommendations, clustering, and RAG.
Chunk embeddingsEmbedding smaller text chunks often improves retrieval precision versus embedding entire long documents.
8. Retrieval-Augmented Generation
TopicDescription
Retrieval pipeline`query → retrieve candidates → rerank/filter → construct context → generate answer`.
ChunkingSplit documents into semantically coherent units; preserve headings and metadata where possible.
OverlapSmall overlap can preserve cross-boundary context but increases index size and redundancy.
Hybrid retrievalCombine dense semantic search with lexical methods such as BM25 when exact terms, identifiers, or rare keywords matter.
RerankingA second model scores retrieved candidates for query relevance before context assembly.
GroundingRequire factual answers to be supported by retrieved evidence and allow abstention when evidence is insufficient.
9. RAG Quality
TopicDescription
Retrieval recallWhether relevant evidence appears in the candidate set.
Context precisionHow much of the supplied context is actually relevant.
FaithfulnessWhether generated claims are supported by supplied/source evidence.
Answer relevanceWhether the answer addresses the user's actual question.
Citation correctnessCitations should point to evidence that genuinely supports the associated claim, not merely related text.
10. Prompt Engineering
TopicDescription
Zero-shotGive the task directly without examples.
Few-shotProvide demonstrations showing the desired mapping and format.
DecompositionBreak difficult work into verifiable stages rather than one unconstrained instruction.
Structured outputRequire JSON/schema-constrained output when downstream systems need deterministic parsing.
Grounded promptingTell the model exactly which context is authoritative and what to do when evidence is missing.
11. Function / Tool Calling
TopicDescription
Tool schemaSpecify name, typed parameters, required fields, constraints, and expected result.
Tool selectionModel decides when a tool is needed; application controls which tools are actually available.
Tool result validationCheck success/failure and validate returned data before using it as truth.
IdempotencyTool actions that can mutate external state should use idempotency keys or equivalent protections against retries.
12. Agents
TopicDescription
AgentA model-driven workflow that selects actions, uses tools, maintains task state, and iterates toward a goal.
ReAct-style loopReason/plan → act → observe → update state → repeat until stop condition.
Planner vs executorSeparating high-level planning from bounded execution can improve reliability and permissions management.
Agent memoryShort-term context stores current task information; long-term memory stores selected persistent facts and should have explicit retention controls.
Stop conditionsDefine maximum steps, time, cost, tool failures, and success criteria to prevent runaway loops.
13. Fine-Tuning
TopicDescription
Full fine-tuningUpdate most/all model parameters; expensive but flexible.
LoRATrain low-rank update matrices while freezing base weights; reduces memory/storage requirements.
Adapter methodsTrain small parameter subsets or modules that can be composed with a frozen base model.
When to fine-tuneUse for consistent behavior/style, specialized formatting, task patterns, or domain adaptation that prompting/RAG does not reliably solve.
When not to fine-tuneDo not use fine-tuning as the primary solution for frequently changing factual knowledge that belongs in retrieval or tools.
14. Prompting vs RAG vs Fine-Tuning
NeedFirst approach
Behavior/format instructionPrompting
Current/private knowledgeRAG / tools
Stable specialized behaviorFine-tuning
Exact deterministic calculationTool/code
External actionTool calling
15. Quantization
TopicDescription
PurposeUse lower-precision weights/activations to reduce memory and often improve inference efficiency.
Common formats8-bit and 4-bit approaches are common; actual quality/performance depends on implementation and hardware.
Trade-offLower precision can reduce memory and cost but may affect quality or operator compatibility.
16. Inference Optimization
TopicDescription
BatchingProcess multiple requests together to improve hardware utilization when latency budget allows.
KV cacheReuse attention key/value states for prior tokens during autoregressive generation, reducing repeated computation.
Continuous batchingDynamic serving can combine requests arriving at different times to improve throughput.
Speculative decodingUse a smaller/faster draft model to propose tokens that a larger model verifies; can reduce latency when the workload and implementation are suitable.
Prefix cachingReuse computations for shared prompt prefixes when supported, reducing repeated work.
17. Evaluation
TopicDescription
Offline benchmarkFixed test set for regression testing and model comparison.
Human evaluationExperts or users judge correctness, usefulness, style, safety, or pairwise preference.
LLM-as-judgeAnother model scores outputs; useful at scale but needs calibration, rubric design, and spot-checking.
Task metricsExact match, F1, pass rate, retrieval recall, groundedness, tool success, code execution success, or domain KPIs.
Golden setA curated high-value evaluation set containing normal, edge, and historically failing examples.
18. Hallucination
TopicDescription
DefinitionGeneration of unsupported, fabricated, or incorrect content presented as though it were reliable.
CausesInsufficient knowledge, ambiguous prompts, weak retrieval, decoding behavior, conflicting context, or model uncertainty.
MitigationsGround with evidence, use tools, require abstention, validate outputs, and evaluate known failure classes.
19. Prompt Injection
TopicDescription
Direct injectionUser attempts to override trusted instructions or exploit the model into violating boundaries.
Indirect injectionUntrusted documents/web content contain instructions that are consumed as context by an agent.
DefenseTreat external content as data, not authority; isolate permissions, constrain tools, validate outputs, and avoid exposing secrets.
20. Security
TopicDescription
Least privilegeGrant agents only the tools and data needed for the task.
Data leakagePrevent accidental exposure of private, tenant-specific, secret, or system-protected information.
Tenant isolationFilter retrieval and tool access by authenticated tenant/user identity.
Audit loggingRecord prompts/tool calls/results and policy-relevant events while respecting privacy and data-retention requirements.
21. Guardrails
TopicDescription
Input guardrailsValidate format, identity, permissions, safety constraints, and suspicious instructions.
Retrieval guardrailsFilter by permissions and metadata before retrieval context reaches generation.
Output guardrailsSchema validation, sensitive-data detection, policy checks, fact/citation checks, and business-rule validation.
Action guardrailsRequire confirmation or approval for destructive, financial, external-communication, or irreversible actions.
22. Cost Model
TopicDescription
Token costTotal cost commonly depends on input and output token volume and provider/model pricing.
Tool costSearch, database, code execution, and external APIs may add separate latency and cost.
OptimizationCache repeated context, reduce unnecessary tokens, retrieve fewer but better chunks, use smaller models for simple subtasks, and batch when possible.
23. Context Engineering
TopicDescription
Relevant contextSupply only information needed for the task.
Authority orderClearly indicate which source outranks which when sources conflict.
Context placementPut critical constraints close to the task/output instructions and use clear sectioning.
CompressionSummarize long histories while retaining key facts, decisions, dates, identifiers, and unresolved issues.
24. Common Architectures
TopicDescription
Simple LLM applicationUser → application → model → response.
RAG applicationUser → query transformation → retrieval → context assembly → model → grounded response.
Tool-using assistantUser → model → tool → observation → model → response/action.
Agentic workflowPlanner/state → bounded tool actions → verification → final answer/action.
HybridUse deterministic code for calculations/rules, retrieval for knowledge, and LLM generation for language/coordination.
25. Production Monitoring
TopicDescription
QualityTrack task success, factuality/groundedness, user feedback, and important failure categories.
ReliabilityTrack error rate, timeout rate, tool failures, retry rate, and fallback rate.
PerformanceTrack p50/p95/p99 latency, time to first token, generation speed, and queueing.
CostTrack tokens, model spend, tool spend, cache hit rate, and cost per successful task.
DriftMonitor changes in user inputs, retrieval distributions, output behavior, and business outcomes.
26. Production Failure Patterns
TopicDescription
Retrieval missRelevant evidence is not retrieved; answer can hallucinate despite a strong generator.
Context pollutionToo much irrelevant context reduces answer focus and can introduce conflicting evidence.
Tool loopAgent repeats unsuccessful actions because stop/recovery logic is weak.
Schema failureGenerated output cannot be parsed; use structured generation plus validation and constrained retry.
Stale knowledgeA model answers using outdated knowledge; route current facts through retrieval or APIs.
27. Practical Selection Guide
RequirementTypical choice
Fixed template text generationLLM + strong prompt
Private docs Q&ARAG
Live dataTool/API lookup
Data transformationLLM + deterministic validator/code
Repeated specialized formatFine-tuning or strong few-shot
Multi-step external actionsBounded agent/tool workflow
Exact arithmeticCalculator/code tool
Search-heavy taskRetrieval + reranking + grounded generation
28. Generative AI Checklist
TopicDescription
Before buildingDefine task, users, allowed actions, trusted data, failure cost, and success metric.
Before launchCreate golden evals, test edge cases, validate prompt-injection resistance, verify access controls, and benchmark latency/cost.
In productionMonitor quality, safety, latency, tool success, cost, and distribution drift; keep rollback/fallback paths.
For high-stakes usePrefer verifiable sources, deterministic tools, human review where appropriate, explicit abstention, and strong auditability.