GenAI Decoded

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

embeddingsvector db

Tools & loops

agentsMCP

Grounded answers

RAGchunks

End-to-end

full stacksearch
inputfeeds forwardoutputactivations flow left → right; opacity suggests relative strength (illustrative)

FIG 0 · Layers 1 → 3 → 5 → 3; left to right is depth. Hand labels are hints — boxes and lines are the diagram.

01Representation

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.

Try it · embedding lab

Click a word to see its embedding.

Royalty
People
Animals
Cities

Vector (first 6 dims)

d1
0.82
d2
-0.12
d3
0.71
d4
0.18
d5
-0.05
d6
0.28

Positive → right (blue), negative → left (pink); values are illustrative.

2D projection — similar words cluster

kingqueenmancatparis

kingSits deep in the royalty cluster — strong positive weights on hierarchy and title dimensions in this toy embedding.

02Retrieval substrate

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).

< 10mssimilarity search over 1M+ vectors (order-of-magnitude; depends on hardware and index params)

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.

Diagram · ANN search
query flies in…neighbors light upqueryvectorANN index (e.g. HNSW)greedy hops along the graph → top-k neighbors without scanning every vector

FIG 2 · Query travels the graph; lime highlights are approximate top hits after greedy hops.

Try it · ANN lab

pick a query profile — watch which nodes approximate-nearest search favors

qdoc Adoc Bimg Cimg Dticket Eimg Epolicy Fpolicy Grunbook H

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.

03Grounded answers

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.

Diagram · RAG pipeline
facts in → grounded answer outstep 1Questionuser intentEmbedquery vectorRetrievetop-k chunksAugmentbuild contextAnswergrounded genretrieve relevant chunks → condition the LLM on grounded text

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.

Try it · RAG lab

choose a question, then run the pipeline step-by-step

What is the refund policy for annual plans?
1. Question
2. Embed
3. Vector DB
4. Chunks
5. LLM
6. Answer
04Autonomous loops

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: thoughtaction (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.

Diagram · agent loop
round & roundtools plug in belowLLMThoughtplan next stepActiontool callObserveresult → contextweb_searchrun_coderead_filesend_msg

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.

Try it · agent trace

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.

thought
action
observation

loop

05Tooling standard

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.

Diagram · MCP bridge
one adapter, many backendsLLMhostMCP ProtocolJSON-RPCtools · resources · promptsGoogle DriveGitHubSlackDatabasesone standard · any tool · any model — USB-C for AI tooling

FIG 5 · Solid arrows are the control channel; dashed lines are connector-specific payloads.

Try it · MCP invoke

pick a tool, invoke it, and inspect mock JSON-RPC-style payloads

LLM host——→MCP serverbackend

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.

06Design trade-offs

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.

Try it · trade-off explorer

move the sliders — scores are a toy blend, not a real model

Proprietary knowledge base55

small → huge corpus

Brand voice / format rigidity40

flexible → must match style exactly

Time to ship70

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.

07Capstone

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.

Diagram · full stack
offline ingestionbatch path · not on every user clickDocsChunkEmbedStorelive query pathUserqueryEmbedmodelVectorDBLLM+ agent + MCPAnswerstreamintentvectorizeANN searchreason + toolsresponsetracing, auth, rate limits, and evals wrap every edge in production

FIG 6 · Main row: online query path. Dashed path above: offline ingestion into the same vector store.

Try it · stack trace

tap a block to see how data tends to flow in a full assistant stack

EmbeddingVector DBLLMAgentMCP tools

LLM

Reasons over the prompt plus retrieved context; drafts answers or tool plans.

GenAI Decoded — Visual guide to modern AI