AI

Technology · Knowledge Center

Artificial Intelligence: The Complete Engineering Guide

What AI really is, how neural networks and large language models work under the hood, every major type of AI and what it's used for, how to use AI tools effectively, how to write AI code in Python and JavaScript, and how to run models on your own hardware — with live, in-browser tools to train a neural network, size a GPU for local LLMs and build better prompts.

Beginner → Engineer ML · Deep Learning · LLMs Python · PyTorch · APIs 5 interactive tools
Artificial intelligence concept illustration

How to read this guide. AI moves fast: specific model names, prices and limits change every few months, so this page teaches the durable fundamentals and uses placeholders (like MODEL_NAME) in code. Always check a provider's current documentation before building. Never paste passwords, API keys, personal or client data into a public AI tool.

What Is Artificial Intelligence?

Artificial Intelligence (AI) is the field of computer science that builds systems able to perform tasks that normally need human intelligence: recognizing images and speech, understanding and generating language, making decisions, planning and learning from experience.

Classic software follows rules a programmer writes by hand. Modern AI flips that around: you show the system thousands or billions of examples, and a training algorithm learns the rules itself, storing them as millions to billions of numbers called parameters (or weights).

One-line definition: a modern AI model is a mathematical function with learned parameters that maps an input (text, pixels, audio, sensor data) to a useful output (an answer, a label, an image, an action).
AI ⊃ ML ⊃ Deep Learning ⊃ Generative AI
Artificial Intelligence Any technique that makes machines act intelligently — incl. rules & search Machine Learning Learns patterns from data instead of hand-written rules Deep Learning Multi-layer neural networks Generative AI & LLMs Creates new text, images, audio, video, code Transformers · Diffusion models
Neural network and artificial intelligence visualization
Modern AI is built from layers of simple artificial neurons — stacked deep enough, they learn language, vision and reasoning patterns.
What You'll Learn
  • Every major type of AI — by capability, by function, and by learning method
  • How neural networks, Transformers, LLMs and diffusion models actually work
  • What AI is used for across industries — and in your own DIY & home projects
  • How to prompt AI tools well, and how to verify what they say
  • Real, runnable code: scikit-learn, PyTorch, LLM APIs, RAG, local models
  • How to run AI locally and size the GPU you need
  • Risks, ethics, security and regulation (EU AI Act)
Jump to a Section

New to AI? Read the tabs in order. Already technical? Jump straight to AI Code, Run AI Locally or the Neural Net Lab.

A Short History of AI
  1. 1950 Alan Turing asks "Can machines think?" and proposes the Turing Test.
  2. 1956 The Dartmouth workshop coins the term "Artificial Intelligence".
  3. 1958 Frank Rosenblatt's Perceptron — the first trainable artificial neuron.
  4. 1966 ELIZA, the first chatbot, imitates a therapist with pattern matching.
  5. 1970s–80s "AI winters": funding collapses when promises outrun hardware.
  6. 1986 Backpropagation popularized — multi-layer networks become trainable.
  7. 1997 IBM Deep Blue defeats world chess champion Garry Kasparov.
  1. 2012 AlexNet wins ImageNet on GPUs — the deep-learning era begins.
  2. 2014 Generative Adversarial Networks (GANs) generate realistic images.
  3. 2016 DeepMind's AlphaGo beats Go champion Lee Sedol.
  4. 2017 "Attention Is All You Need" introduces the Transformer.
  5. 2020 AlphaFold 2 largely solves protein structure prediction.
  6. 2022 Text-to-image diffusion goes mainstream; ChatGPT launches.
  7. 2024 Nobel Prizes in Physics & Chemistry honor neural-network and AI protein work.
  8. 2025+ Multimodal models, reasoning models and AI agents that use tools.
Three Ways to Classify AI

"Type of AI" can mean three different things: how capable it is, how it functions (memory and awareness), or how it learns. Engineers mostly care about the third; the first two are the ones you'll see in news and debates.

1 · By Capability
TypeWhat it meansExamplesStatus
Narrow AI (ANI)Excellent at one task or a bounded family of tasks; can't transfer that skill freelySpam filters, face unlock, recommendation engines, chess engines, today's chatbotsExists today
General AI (AGI)Human-level ability across virtually any intellectual task, learning new ones on its ownA research goal — definitions and timelines are actively debatedDebated
Superintelligence (ASI)Hypothetical AI far exceeding the best humans in every domainDiscussed in AI safety research and policyHypothetical
Large language models are general-purpose (they write, code, translate, summarize) but are still classed as narrow by most researchers: they can fail at simple tasks outside their training patterns and don't learn continuously from experience.
2 · By Functionality (Memory & Awareness)
Reactive Machines
Respond to the current input only, with no memory of the past. Same input → same output.
ExistsDeep Blue
Limited Memory
Use recent data or a context window to decide. Nearly all modern AI: self-driving perception, chatbots, recommenders.
ExistsLLMs
Theory of Mind
Would genuinely model other agents' beliefs, intentions and emotions. Partial abilities are being studied.
Research
Self-Aware AI
Would have its own consciousness and sense of self. No scientific evidence any system has this.
Hypothetical
3 · By Learning Method (the Engineer's View)
ParadigmTraining dataTypical tasksCommon algorithms
Supervised learningLabeled pairs (input → correct answer)Classification, regression, price prediction, defect detectionLinear/logistic regression, decision trees, random forest, gradient boosting, neural nets
Unsupervised learningUnlabeled dataClustering customers, anomaly detection, compressionk-means, DBSCAN, PCA, autoencoders
Self-supervised learningRaw data where the label comes from the data itself (e.g. the next word)Pre-training LLMs and vision foundation modelsNext-token prediction, masked modeling, contrastive learning
Reinforcement learningRewards from interacting with an environmentGames, robotics, control systems, aligning chatbots (RLHF)Q-learning, policy gradients, PPO
Semi-supervisedA few labels + lots of unlabeled dataMedical imaging, speech with limited transcriptsPseudo-labeling, consistency training
Transfer learning / fine-tuningA pre-trained model + a small task datasetCustom classifiers, domain chatbotsFull fine-tune, LoRA / QLoRA adapters
AI Fields by What They Perceive or Produce
Natural Language Processing
Understanding and generating human language: chat, translation, summarization, sentiment.
Computer Vision
Classifying images, detecting objects, segmentation, OCR, measuring from photos, quality inspection.
Speech & Audio
Speech-to-text, text-to-speech, voice assistants, music generation, fault detection by sound.
Generative AI
Creates new text, images, video, 3D and code from a prompt — LLMs and diffusion models.
Robotics & Control
Perception plus planning plus motor control: warehouse robots, drones, robotic arms.
Expert & Symbolic Systems
Rule-based "if-then" reasoning and knowledge graphs — older, but still used where explainability is required.
Predictive Analytics
Forecasting demand, energy use, prices or equipment failure from historical data.
AI Agents
An LLM in a loop that plans, calls tools (search, code, APIs), checks results and continues until the goal is met.
The Artificial Neuron

Every neural network is built from one simple unit. A neuron multiplies each input by a weight, adds a bias, and passes the sum through a non-linear activation function.

y = f( w₁·x₁ + w₂·x₂ + … + wₙ·xₙ + b )

# f = activation, e.g.
ReLU(z)    = max(0, z)
sigmoid(z) = 1 / (1 + e^(−z))
tanh(z)    = (e^z − e^(−z)) / (e^z + e^(−z))

Without the non-linearity, stacking layers would collapse into a single linear equation — the activation is what lets deep networks model curves, edges, grammar and meaning.

x₁ x₂ x₃ w₁w₂w₃ Σ + b f(z) y
How a Model Learns — The Training Loop
1Forward pass

Feed a batch of examples through the network to get predictions.

2Loss

Measure how wrong the predictions are: mean-squared error for numbers, cross-entropy for classes and tokens.

3Backpropagation

Use the chain rule to compute the gradient: how much each weight contributed to the error.

4Gradient descent

Nudge every weight a small step against its gradient: w ← w − η·∂L/∂w.

5Repeat & validate

Loop over the data for many epochs and check on held-out data to catch overfitting.

See it happen: the Neural Net Lab tab runs this exact loop live in your browser.
HyperparameterWhat it controlsTypical starting point
Learning rate (η)Step size of each update. Too high diverges, too low crawls.1e-3 (Adam), 1e-4 – 2e-5 for fine-tuning
Batch sizeExamples per update — trades memory for gradient stability16 – 256
EpochsFull passes over the training setUntil validation loss stops improving
OptimizerHow gradients become updatesAdamW; SGD with momentum for some vision tasks
RegularizationFights overfittingDropout 0.1–0.5, weight decay 0.01, early stopping, data augmentation
Neural Network Architectures
ArchitectureCore ideaBest at
MLP (feed-forward)Fully connected layersTabular data, small classification/regression
CNN (convolutional)Small filters slide over the image, sharing weights to detect edges → shapes → objectsImage classification, detection, medical imaging
RNN / LSTM / GRUProcesses a sequence step by step with a hidden memory stateTime series, older speech & translation systems
TransformerSelf-attention lets every token look at every other token in parallelLLMs, translation, code, and increasingly vision & audio
Diffusion modelLearns to remove noise step by step, turning random noise into an imageImage, video and audio generation
GANA generator and a discriminator competeSuper-resolution, style transfer, synthetic data
Autoencoder / VAECompresses input to a small latent code and reconstructs itAnomaly detection, compression, latent space for diffusion
Graph Neural NetworkPasses messages between connected nodesMolecules, social networks, route planning
Mixture of Experts (MoE)A router activates only a few "expert" sub-networks per tokenVery large LLMs with lower compute per token
How a Large Language Model Generates Text
1 · Tokenizer "Fix a leaky faucet" → [ 21, 845, 3021, 11, 9044 ] — words split into sub-word tokens
2 · Embeddings each token ID → a vector of thousands of numbers + position information
3 · Transformer blocks × N self-attention (which tokens matter to which) + feed-forward layers
4 · Output head a probability for every token in the vocabulary
5 · Sampling → repeat pick the next token (temperature / top-p), append it, run again
Scaled dot-product attention
Attention(Q, K, V) = softmax( Q·Kᵀ / √d_k ) · V

# Q = what each token is looking for
# K = what each token offers
# V = the information passed along
Pre-training → assistant
  1. Pre-training — predict the next token over trillions of tokens of text and code.
  2. Supervised fine-tuning — learn from high-quality instruction/answer examples.
  3. Preference tuning (RLHF, DPO and similar) — learn which answers people rate as more helpful, honest and harmless.
  4. Tools & retrieval — at run time, connect to search, documents or code execution.
Why LLMs "hallucinate": the model produces the most plausible continuation, not a verified fact. It has no built-in truth check — which is why retrieval (RAG), citations and human review matter.
How Image Generators Work (Diffusion)
  1. Training: real images get progressively buried in noise; the network learns to predict and remove that noise.
  2. Text conditioning: a text encoder turns your prompt into vectors that steer each denoising step.
  3. Generation: start from pure random noise and denoise over ~20–50 steps into a new image — usually in a compressed "latent" space for speed.
Training vs. Inference
TrainingInference
GoalLearn the weightsUse the weights
ComputeHuge GPU clusters, weeks–monthsOne GPU, laptop or phone, milliseconds–seconds
MemoryWeights + gradients + optimizer state (~16 bytes/param with Adam, mixed precision)Weights + KV cache (as low as ~0.5 bytes/param quantized)
Who does itAI labs, researchersEveryone who uses AI
How Models Are Measured
MetricFormula / meaningUse when
Accuracy(TP + TN) / totalBalanced classes
PrecisionTP / (TP + FP)False alarms are costly (spam filter)
RecallTP / (TP + FN)Misses are costly (fault or disease detection)
F1 score2·P·R / (P + R)Imbalanced classes
MAE / RMSEAverage / root-mean-square errorPredicting numbers
Perplexitye^(cross-entropy)Language models — lower is better
BenchmarksStandard test sets for knowledge, math, coding, reasoningComparing models — but always test on your task

Neural Network Playground

A real 2-layer neural network, trained with backpropagation, running entirely in your browser.

Class AClass BLoss
Too few → can't fit the shape
Too high → loss jumps around
Epoch
0
Loss (BCE)
—
Accuracy
—
Parameters
—
Try this: pick Two spirals with 2 hidden neurons — the network can't solve it. Raise it to 16+ and watch it learn. Then set the learning rate to maximum and see training become unstable. Those two lessons — capacity and step size — apply to every model up to the largest LLMs.
What the Playground Runs Under the Hood
// Network: 2 inputs → H hidden (activation) → 1 output (sigmoid)
for (each point (x, y, target)) {
  h   = act(W1 · [x, y] + b1)          // hidden layer
  out = sigmoid(W2 · h + b2)            // probability of class B
  loss += −[t·log(out) + (1−t)·log(1−out)]  // binary cross-entropy

  dOut = out − t                        // gradient of BCE through sigmoid
  dW2 += dOut · h ;  db2 += dOut
  dH   = dOut · W2 · act'(h)            // chain rule back to hidden layer
  dW1 += dH ⊗ [x, y] ;  db1 += dH
}
W −= η · dW / N   // full-batch gradient descent
What AI Does — Core Functions
Classify
Put things in categories: spam / not spam, wood species from a photo, a healthy vs. diseased leaf.
Predict
Estimate a number: energy use, project cost, time to failure of a motor or battery.
Detect & Recognize
Find objects, faces, text, cracks, rust or leaks in images and video.
Understand & Generate Language
Answer questions, summarize manuals, translate, draft emails and documentation.
Write & Review Code
Autocomplete, explain, debug, refactor and test software — including Arduino and Raspberry Pi projects.
Create Media
Images, concept renders, voice-overs, music and video from text descriptions.
Search & Recommend
Semantic search by meaning, not keywords; "people who bought this also bought…".
Plan & Act
Agents that break a goal into steps and use tools — browsing, spreadsheets, code, APIs.
Categories of AI Tools
CategoryWell-known examplesGood for
Chat assistantsChatGPT, Claude, Gemini, Microsoft Copilot, Le ChatResearch, writing, planning, explanations, analysis of files
Coding assistantsGitHub Copilot, Claude Code, Cursor, Gemini Code AssistWriting, debugging and reviewing code in your editor or terminal
Image generationMidjourney, DALL·E / GPT image, Adobe Firefly, Stable Diffusion, FLUXConcept art, mood boards, product mockups, thumbnails
Video & audioRunway, Sora, Veo, ElevenLabs, SunoShort clips, voice-overs, narration, music beds
Speech-to-textWhisper, built-in phone & OS dictationTranscribing tutorials, meetings, voice notes
Research & searchPerplexity, "deep research" modes in chat assistantsCited answers, literature and market research
Local / open modelsLlama, Mistral, Qwen, Gemma, DeepSeek via Ollama, LM Studio, llama.cppPrivacy, offline use, no per-token cost — see Run AI Locally
Developer platformsHugging Face, PyTorch, TensorFlow/Keras, scikit-learn, provider APIsBuilding and deploying your own AI features
AutomationZapier, Make, n8n with AI steps; Home Assistant voiceConnecting AI to email, spreadsheets, smart-home devices

Product names and features change quickly — this list shows the landscape, not an endorsement. Pick tools by task, privacy policy and price, and re-evaluate every few months.

AI for DIY, Home & Workshop
  • Diagnose repairs: describe symptoms (or upload a photo) of a noisy boiler, a tripping breaker or a car warning light to get likely causes and a checklist.
  • Plan projects: generate cut lists, material lists and step-by-step build plans — then verify them with the calculators on this site.
  • Identify things: plants, pests, wood species, fasteners, electronic components.
  • Write code for makers: Arduino, ESP32, Raspberry Pi and Home Assistant automations.
  • Read manuals faster: summarize a 200-page PDF into the three pages you need.
  • Visualize: try paint colors, garden layouts or kitchen ideas before buying.
Safety first: never rely on AI alone for gas, mains electrical, structural or brake work. Use it to learn and prepare, then follow local codes and hire a licensed professional where required.
AI Across Industries
HealthcareImaging analysis, drug discovery, protein structure
ManufacturingVisual inspection, predictive maintenance, robotics
AutomotiveDriver assistance, autonomous driving, diagnostics
EnergyGrid forecasting, solar output prediction, smart thermostats
AgricultureCrop disease detection, precision irrigation, yield forecasting
FinanceFraud detection, credit risk, document processing
ConstructionEstimating, site safety monitoring, generative design
RetailRecommendations, demand forecasting, support chatbots
Prompting: Getting Great Results From AI

A prompt is a work order. The model knows nothing about you, your project or your standards unless you tell it. Clear context + a clear task + a clear output format beats "clever tricks" every time.

TechniqueHowExample
Give a role & audienceSay who the answer is for and what expertise to use"You're a licensed electrician explaining to a first-time homeowner…"
Provide contextPaste the data, specs, error message or document"Here is my wiring diagram and the breaker label: …"
Be specific about the taskOne clear goal; split big jobs into steps"List the 5 most likely causes, most likely first."
Show examples (few-shot)Give 1–3 input → output samples"Format each tool like: Name — use — price range"
Ask for reasoningLet it work step by step on math, logic and diagnosis"Work through the load calculation step by step, then give the result."
Specify the formatTable, JSON, checklist, word count, language"Return a Markdown table with columns: Part, Qty, Size."
Set constraintsBudget, tools you own, standards, what to avoid"Only hand tools. Metric units. Under €100."
IterateTreat the first answer as a draft; refine it"Good — now make step 3 more detailed and add safety notes."
Ask it to check itselfRequest assumptions, uncertainty and sources"List any assumptions and anything I should verify."

Prompt Builder

Fill the fields — a structured prompt is assembled live, ready to copy into any AI assistant.

Token & Cost Estimator

Estimate how many tokens a text uses, how much of a context window it fills, and what an API call costs.

Check your provider's pricing page
Characters / words
0 / 0
Est. input tokens
0
Cost per call
$0.0000
Cost per month
$0.00
InputOutput0% of context window used

Estimates use the average characters-per-token of modern sub-word tokenizers; each provider's exact tokenizer differs by roughly ±15%. Output tokens are usually priced several times higher than input tokens.

Model Settings Explained
temperatureRandomness. ~0–0.3 for facts, code and extraction; ~0.7–1.0 for brainstorming.
top_pOnly sample from the most likely tokens whose probabilities add up to p. Tune this or temperature, not both.
max_tokensHard limit on answer length (and cost).
system promptStanding instructions: persona, rules, format — applied to every turn.
context windowHow many tokens (prompt + history + answer) the model can see at once.
stop sequencesStrings that end generation early.
Verify Before You Trust
  • Check numbers, measurements and load ratings against manufacturer data or a calculator.
  • Ask for sources — then open them. Models can invent convincing citations.
  • Run generated code in a safe test environment first; read what it does.
  • Cross-check important answers with a second source or a professional.
  • Watch for outdated information — models have a training cut-off date.
  • Keep private data out of tools that train on your inputs; check the privacy settings.
Your AI Development Toolkit

Python is the language of AI. Set up an isolated environment once, then every example below runs as-is (replace MODEL_NAME with a current model ID from your provider's docs).

# 1 · Create and activate a virtual environment
python3 -m venv ai-env
source ai-env/bin/activate          # Windows: ai-env\Scripts\activate

# 2 · Install the libraries used on this page
pip install numpy pandas scikit-learn torch sentence-transformers anthropic openai requests

# 3 · Store API keys as environment variables — never in your code
export ANTHROPIC_API_KEY="sk-..."   # Windows PowerShell: $env:ANTHROPIC_API_KEY="sk-..."
export OPENAI_API_KEY="sk-..."
LibraryUse it for
NumPy / pandasArrays, math and tabular data wrangling
scikit-learnClassic ML: regression, trees, clustering, metrics, pipelines
PyTorchDeep learning research and production (most popular)
TensorFlow / KerasDeep learning, mobile & edge deployment (LiteRT)
Hugging Face transformersThousands of pre-trained open models for text, vision and audio
sentence-transformersText embeddings for semantic search and RAG
Provider SDKsCalling hosted LLMs (Anthropic, OpenAI, Google, Mistral…)
JupyterInteractive notebooks for experiments
Example 1 · Classic Machine Learning (scikit-learn)

Train a Random Forest to classify flower species from four measurements — the "hello world" of supervised learning.

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.ensemble import RandomForestClassifier
from sklearn.metrics import classification_report

X, y = load_iris(return_X_y=True)
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42, stratify=y
)

model = RandomForestClassifier(n_estimators=200, random_state=42)
model.fit(X_train, y_train)                 # training

pred = model.predict(X_test)                # inference
print(classification_report(y_test, pred))  # precision / recall / F1

# Which measurements mattered most?
for name, imp in zip(load_iris().feature_names, model.feature_importances_):
    print(f"{name:<20} {imp:.2f}")
Example 2 · A Neural Network in PyTorch

The same training loop as the Neural Net Lab, written the way professionals do it — with automatic differentiation and GPU support.

import torch
from torch import nn

device = "cuda" if torch.cuda.is_available() else "cpu"

# Synthetic "circle" dataset: label 1 if the point is inside radius 0.5
X = torch.rand(2000, 2) * 2 - 1
y = ((X ** 2).sum(dim=1) < 0.25).float().unsqueeze(1)
X, y = X.to(device), y.to(device)

model = nn.Sequential(
    nn.Linear(2, 16), nn.ReLU(),
    nn.Linear(16, 16), nn.ReLU(),
    nn.Linear(16, 1)                    # raw logit
).to(device)

loss_fn = nn.BCEWithLogitsLoss()
opt = torch.optim.AdamW(model.parameters(), lr=1e-2)

for epoch in range(500):
    opt.zero_grad()
    loss = loss_fn(model(X), y)   # 1. forward  2. loss
    loss.backward()               # 3. backpropagation
    opt.step()                    # 4. gradient descent
    if epoch % 100 == 0:
        acc = ((model(X) > 0).float() == y).float().mean()
        print(f"epoch {epoch:3d}  loss {loss.item():.4f}  acc {acc:.2%}")

torch.save(model.state_dict(), "circle_model.pt")
Example 3 · Calling a Hosted LLM API
Python · Anthropic SDK
import anthropic

client = anthropic.Anthropic()  # reads ANTHROPIC_API_KEY

msg = client.messages.create(
    model="MODEL_NAME",
    max_tokens=1024,
    system="You are a concise DIY expert.",
    messages=[{
        "role": "user",
        "content": "How do I fix a dripping tap?",
    }],
)
print(msg.content[0].text)
Python · OpenAI SDK
from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY

resp = client.chat.completions.create(
    model="MODEL_NAME",
    messages=[
        {"role": "system",
         "content": "You are a concise DIY expert."},
        {"role": "user",
         "content": "How do I fix a dripping tap?"},
    ],
)
print(resp.choices[0].message.content)
JavaScript · Node.js (server-side) with plain fetch
// Run on a server (Node 18+). NEVER call a paid API with your key from browser JavaScript.
const res = await fetch("https://api.anthropic.com/v1/messages", {
  method: "POST",
  headers: {
    "x-api-key": process.env.ANTHROPIC_API_KEY,
    "anthropic-version": "2023-06-01",
    "content-type": "application/json",
  },
  body: JSON.stringify({
    model: "MODEL_NAME",
    max_tokens: 512,
    messages: [{ role: "user", content: "Suggest 3 beginner woodworking projects." }],
  }),
});
if (!res.ok) throw new Error(`API error ${res.status}`);
const data = await res.json();
console.log(data.content[0].text);
Security rule #1: an API key in front-end JavaScript (including a WordPress page) is public — anyone can copy it and spend your money. Call AI APIs from your server (a PHP endpoint, a serverless function) and add rate limiting.
Example 4 · RAG — Answer Questions From Your Own Documents

Retrieval-Augmented Generation finds the most relevant passages from your content by meaning (embeddings + cosine similarity) and hands them to the LLM, so answers are grounded in your data and can cite it.

import numpy as np
import anthropic
from sentence_transformers import SentenceTransformer

docs = [
    "Use a 6 mm masonry bit and brown plugs for 6 mm screws in solid brick.",
    "Hollow brick needs long nylon plugs or chemical anchors for heavy loads.",
    "Plasterboard can hold light shelves with metal cavity (molly) fixings.",
]

embedder = SentenceTransformer("all-MiniLM-L6-v2")
doc_vecs = embedder.encode(docs, normalize_embeddings=True)   # index once

def retrieve(question, k=2):
    q = embedder.encode([question], normalize_embeddings=True)[0]
    scores = doc_vecs @ q                   # cosine similarity (vectors are normalized)
    top = np.argsort(scores)[::-1][:k]
    return [docs[i] for i in top]

question = "What fixing should I use for a heavy shelf on hollow brick?"
context = "\n".join(f"- {c}" for c in retrieve(question))

client = anthropic.Anthropic()
answer = client.messages.create(
    model="MODEL_NAME", max_tokens=400,
    messages=[{"role": "user", "content":
        f"Answer using ONLY this context. If it's not there, say so.\n\n"
        f"Context:\n{context}\n\nQuestion: {question}"}],
)
print(answer.content[0].text)

For thousands of documents, store the vectors in a vector database (pgvector, Qdrant, Chroma, FAISS) and split long documents into overlapping chunks of ~300–800 tokens.

Example 5 · How an AI Agent Works
# Simplified agent loop (pseudo-code)
messages = [user_goal]
while True:
    reply = llm(messages, tools=[search, calculator, read_file])
    if reply.wants_tool:
        result = run_tool(reply.tool_name, reply.args)
        messages += [reply, tool_result(result)]
    else:
        return reply.text   # goal reached

The model never executes anything itself — your code runs the tool and returns the result. Validate every argument and limit what tools can touch.

Example 6 · Talk to a Local Model (Ollama API)
import requests

r = requests.post("http://localhost:11434/api/chat", json={
    "model": "llama3.2",
    "messages": [{"role": "user",
                  "content": "Explain PWM in one paragraph."}],
    "stream": False,
}, timeout=120)
r.raise_for_status()
print(r.json()["message"]["content"])

Free, private and offline — the model runs on your own machine. Setup is in the next tab.

The ML Project Lifecycle
1Define

The problem, the metric that means success, and a simple non-AI baseline.

2Data

Collect, clean, label, split into train / validation / test. Most of the work lives here.

3Model

Start with the simplest model or an existing pre-trained one before building your own.

4Evaluate

Test on unseen data, check errors by category, test for bias.

5Deploy

Serve via API, app or edge device; version the model and the data.

6Monitor

Track accuracy, drift, latency and cost; retrain when the world changes.

Why Run AI on Your Own Hardware?
Privacy
Your documents never leave your machine.
No per-token cost
Pay once for hardware and electricity.
Offline & hackable
Works without internet; integrates with Home Assistant, scripts and your home server.

The trade-off: open models you can run at home are typically smaller than the largest hosted models, so they can be less capable on complex tasks. The key constraint is memory — GPU VRAM, or unified memory on Apple Silicon.

Quick Start With Ollama
# Linux (macOS / Windows: installer from ollama.com)
curl -fsSL https://ollama.com/install.sh | sh

ollama pull llama3.2        # download a small model
ollama run llama3.2         # chat in the terminal
ollama list                 # installed models
ollama ps                   # what's loaded, CPU/GPU split

Ollama also serves an HTTP API on port 11434 (see Example 6 in AI Code). Add Open WebUI for a ChatGPT-style interface in the browser.

Other Local AI Tools
LM StudioDesktop app: browse, download and chat with models — no terminal needed
llama.cppThe fast C/C++ engine behind many tools; runs GGUF files on CPU, GPU and Apple Metal
vLLMHigh-throughput server for NVIDIA GPUs, many users at once
ComfyUINode-based local image and video generation
whisper.cppLocal speech-to-text
# llama.cpp: serve a GGUF model, all layers on GPU, 8K context
llama-server -m model-Q4_K_M.gguf -c 8192 -ngl 99 --port 8080
Quantization — Fitting Big Models Into Small Memory

Quantization stores each weight with fewer bits. Around 4–5 bits per weight is the usual sweet spot: roughly a quarter of the full-precision size with a small quality loss.

Format≈ Bits / weight8B model sizeQuality vs. FP16
FP16 / BF1616~16 GBReference
Q8_08.5~8.5 GBPractically identical
Q6_K6.6~6.6 GBVery close
Q5_K_M5.7~5.7 GBExcellent
Q4_K_M4.8~4.9 GBGood — the popular default
Q3_K_M3.9~4.0 GBNoticeable loss
Q2_K~3~3.2 GBSignificant loss — last resort

Local LLM VRAM & Speed Calculator

Weights + KV cache + runtime overhead → the memory you need, and a realistic generation speed.

Weights
—
KV cache
—
Overhead
—
Total memory
—
Est. speed
—
WeightsKV cacheOverhead
Formulas used
Weights (GB)  = params × bits_per_weight ÷ 8 ÷ 1.0735 # → GiB
KV cache (GB) = 2 × layers × kv_heads × head_dim × context × kv_bytes × parallel ÷ 1024³
Overhead (GB) = 0.06 × weights + 0.5              # CUDA context, activations, buffers
Speed (tok/s) ≈ 0.6 × memory_bandwidth ÷ (weights + KV)   # decode is memory-bound
If total > memory → layers spill to system RAM and speed drops sharply.

Estimates for dense Transformer models at batch size 1. Mixture-of-Experts models need memory for all parameters but run at the speed of their active parameters. Real numbers vary by ±15% with engine, driver and prompt length.

Hardware Guide for Local AI
Budget tierHardwareWhat runs well (Q4)
EntryAny modern PC with 16 GB RAM, or an 8 GB GPU1–8B models: chat, summaries, coding help
Enthusiast12–16 GB GPU, 32 GB RAM8–14B models with long context; SDXL-class image generation
Prosumer24–32 GB GPU, or Mac with 36–64 GB unified memory32B models comfortably; 70B only with offload or heavy quantization
Workstation2× 24 GB GPUs, or 96 GB+ unified memory70B-class models at usable speed
EdgeRaspberry Pi 5 + AI accelerator, NVIDIA JetsonObject detection, small vision & speech models, sensors
Rule of thumb: memory decides what you can run; memory bandwidth decides how fast. NVIDIA GPUs have the widest software support (CUDA). Pair this guide with our Home Server Build and PC Builder tools to plan a dedicated AI box.
Risks You Should Understand
Hallucinations
Confident but false answers, invented sources or wrong numbers. Mitigate with RAG, citations and verification.
Bias & Fairness
Models learn biases present in their data, which can affect hiring, lending or policing decisions. Test outcomes across groups.
Privacy & Data
Inputs may be stored or used for training. Under GDPR, personal data needs a legal basis. Use business plans or local models for sensitive data.
Copyright & Ownership
Rules on training data and on who owns AI output are still being settled by courts and lawmakers. Check tool terms before commercial use.
Deepfakes & Scams
Cloned voices and fake videos power fraud. Agree a family "safe word" and verify urgent money requests through another channel.
Prompt Injection
Hidden instructions in web pages, emails or files can hijack an AI agent. Treat content as data, limit tool permissions, require confirmation for actions.
Energy & Environment
Training and serving large models consumes significant electricity and water. Use right-sized models for the job.
Work & Skills
AI automates tasks more than whole jobs. The durable skills: judgment, domain knowledge, and knowing how to direct and check AI.
Regulation: The EU AI Act in Brief

The EU AI Act (Regulation (EU) 2024/1689) is the first comprehensive AI law. It entered into force in August 2024 and applies in phases through 2027, classifying AI systems by risk. Other regions (US states, UK, China, Canada) have their own approaches. This is an overview, not legal advice.

Risk levelExamplesRequirement
UnacceptableSocial scoring, manipulative techniques that cause harm, untargeted scraping of facial imagesProhibited
High riskAI in critical infrastructure, hiring, education, credit scoring, medical devices, law enforcementRisk management, data quality, logging, human oversight, conformity assessment
Limited riskChatbots, AI-generated or manipulated content (deepfakes)Transparency: users must know they're dealing with AI; synthetic content must be labeled
Minimal riskSpam filters, AI in video games, most everyday toolsNo specific obligations
General-purpose AIFoundation models / LLMsTechnical documentation, copyright policy, training-data summary; extra duties for systemic-risk models
Responsible AI Checklist
  • Tell people when content or a conversation is AI-generated.
  • Keep a human in the loop for decisions affecting safety, money or rights.
  • Don't upload personal, client or confidential data to consumer AI tools.
  • Check licenses before using AI images or code commercially.
  • Test models for bias and failure cases before deploying them.
  • Log AI decisions so they can be reviewed and explained.
  • Give AI agents the minimum permissions they need.
  • Keep learning — the technology and the rules change every year.

AI Glossary

Search 0 essential AI terms, explained in plain English.

Gear for Learning & Running AI

You can learn everything on this page with a normal laptop and free tools. These upgrades matter once you want to run models locally or build AI hardware projects.

Hardware
16 GB Graphics Card
The sweet spot for local 8–14B LLMs and image generation.
Check Price
24 GB+ Graphics Card
Runs 32B-class models and larger image models comfortably.
Check Price
64 GB DDR5 RAM Kit
Headroom for offloading big models and handling large datasets.
Check Price
2 TB NVMe SSD
Model files are 4–40 GB each — fast storage means fast loading.
Check Price
Edge AI & Learning
Raspberry Pi 5 + AI Accelerator HAT
Real-time object detection for cameras, doorbells and robots.
Check Price
NVIDIA Jetson Developer Kit
A compact CUDA computer for robotics and edge AI projects.
Check Price
Hands-On Machine Learning (book)
A practical, code-first introduction with scikit-learn and deep learning.
Check Price
USB Conference Microphone
Clean audio for local voice assistants and speech-to-text.
Check Price

Some links on this page are affiliate links — if you buy through them we may earn a small commission at no extra cost to you.

Step-by-Step AI Projects From the Community

This page covers the fundamentals; the KreatedByU forum is where full AI project walkthroughs live. The cards below are placeholders, ready to link as tutorials are posted.

Built something with AI? Share it in the forum — well-documented projects get featured here.
logo3

Artificial Intelligence: 

The Complete Engineering Guide