Interactive primer
GenAI Decoded
Vectors, agents + more
Understand how modern AI systems are wired — embeddings, retrieval, agents, and tools — in plain language with diagrams you can skim in order.
Use the numbered links in the header to jump chapters · cards below go to the matching section
Meaning in space
Tools & loops
Grounded answers
End-to-end
FIG 0 · Layers 1 → 3 → 5 → 3; left to right is depth. Hand labels are hints — boxes and lines are the diagram.
Words become vectors
How language turns into numbers models can compare, cluster, and retrieve.
An embedding is a dense vector that encodes meaning. Similar ideas land near each other in space — even when the model never saw them co-occur in training.
Models map tokens or spans into hundreds or thousands of dimensions. Retrieval, clustering, and analogies all treat those coordinates as geometry.
Distance ≈ relatedness (with caveats): cosine and dot products score alignment; projection to 2D is for intuition only.
Real-world
Spotify discovers taste by embedding audio and listening behavior — recommendations are neighbors in vector space, not keyword matches.
Click a word to see its embedding.
Vector (first 6 dims)
Positive → right (blue), negative → left (pink); values are illustrative.
2D projection — similar words cluster
“king” — Sits deep in the royalty cluster — strong positive weights on hierarchy and title dimensions in this toy embedding.
Similarity search at scale
How systems find nearest neighbors in huge embedding indexes in milliseconds.
A vector database stores embeddings at scale and returns the closest vectors to a query in milliseconds. HNSW, IVF, and product quantization implement approximate nearest neighbors (ANN).
Pinecone
Managed ANN service with metadata filters and hybrid patterns.
Weaviate
Open vector store with GraphQL and modular retrieval plugins.
pgvector
Postgres extension — one database for relational + vector queries.
Real-world
Pinterest visual search embeds images and pins; nearest vectors surface “looks like this” without hand-tagged ontologies.
FIG 2 · Query travels the graph; lime highlights are approximate top hits after greedy hops.
pick a query profile — watch which nodes approximate-nearest search favors
results
- img D0.94
- img E0.89
- doc B0.71
Image-like queries activate nodes tagged as visual embeddings; ANN hops along the graph toward that region instead of scanning every vector.
Retrieval-augmented generation
Ground the model on your documents: embed, retrieve, augment, answer.
RAG (retrieval-augmented generation) grounds an LLM on your documents: embed the question, retrieve relevant chunks, add them to the prompt, then generate. That tends to improve factual answers on private or fresh data and can reduce hallucinations — it is not a proof against wrong retrieval or bad chunks.
FIG 3 · Five stages from question to grounded answer (purple accent = this chapter).
Support copilot
Retrieves policy snippets per ticket and cites chunk IDs so agents can verify before send.
Internal wiki Q&A
Chunks Confluence or Notion; hybrid BM25 + vector improves recall on rare product names.
Code + docs
Embeds API references next to source; IDE assistants pull the right symbol docs into context.
choose a question, then run the pipeline step-by-step
Plan, act, observe — in a loop
How an LLM cycles through thoughts, tool calls, and observations until done.
An agent here means an LLM that loops: thought → action (tool call) → observation (tool output back in context) → repeat until a stop condition. The pattern matches the widely used ReAct (reason + act) style traces, which keep debugging and audits readable.
FIG 4 · Pink accent = agents; the LLM sits at the center with tools as outlined capabilities.
Research briefs
Searches the web, normalizes sources, and drafts summaries with explicit tool steps in the trace.
Ops automation
Opens tickets, runs runbooks, and pings on-call — bounded by allow-lists and human approval gates.
Coding agents
Read files, run tests, and patch diffs; the loop stops when tests pass or the step budget is exhausted.
step through a ReAct-style trace — thought, tool action, observation
step 1 / 8
Thought
User wants Q3 revenue vs peers. I need public filings and our internal CRM snapshot.
loop
Model Context Protocol
One open protocol (JSON-RPC) so hosts can plug in Drive, GitHub, Slack, databases, and more with the same client pattern.
MCP standardizes how a host (IDE, assistant, agent runtime) discovers and calls tools and reads resources from separate MCP servers. You can add or swap servers (e.g. calendar vs. repo) without bespoke integrations for each tool vendor.
FIG 5 · Solid arrows are the control channel; dashed lines are connector-specific payloads.
pick a tool, invoke it, and inspect mock JSON-RPC-style payloads
request
{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"calendar.freebusy","arguments":{"emails":["you@co.com"],"range":"2025-04-14/7d"}}}response
{"busy":[{"start":"2025-04-15T14:00:00Z","end":"2025-04-15T15:00:00Z"}],"free_slots":["Tue 16:00 UTC","Wed 09:30 UTC"]}Host asks the MCP server; server talks to Google Calendar and returns structured free/busy.
Prompting vs RAG vs Fine-tuning
When to steer with prompts, when to retrieve, and when to train weights.
These are complementary controls: prompting shapes behavior at inference; RAG injects facts; fine-tuning moves weights when you need persistent style or format.
Prompting
- Fastest path; no training pipeline
- Great for tone, format, guardrails
- Weak for large proprietary corpora
- Bounded by context window
- No index to maintain
Best for: fast iteration, tone, guardrails.
RAG
- Grounds answers in your documents
- Updates when docs change
- Needs chunking, indexing, evals
- Retrieval mistakes propagate
- Pairs well with prompting
Best for: factual, updatable knowledge.
Fine-tuning
- Bakes in domain-specific patterns & voice
- Can shorten prompts / latency
- Costly; stale without retraining
- Overfit risk on narrow tasks
- Use offline evals before shipping
Best for: baked-in style or head format.
move the sliders — scores are a toy blend, not a real model
small → huge corpus
flexible → must match style exactly
patient → need it this week
RAG fit
29%
Prompt fit
43%
Fine-tune fit
28%
emphasis right now
Prompting
Ship fast with instructions and tools; keep docs in RAG only when factual grounding is critical. Fine-tune when the same prompt exceeds context or cost.
End-to-end assistant architecture
How ingestion, vectors, RAG, agents, and tools connect in one product surface.
Shipping an assistant wires embeddings, a vector index, RAG, an agent loop, and MCP tools behind one experience — plus auth, rate limits, evals, and on-call.
FIG 6 · Main row: online query path. Dashed path above: offline ingestion into the same vector store.
tap a block to see how data tends to flow in a full assistant stack
LLM
Reasons over the prompt plus retrieved context; drafts answers or tool plans.