1:1 mentoring with Big Tech AI engineers
RAG & MCP

Embeddings

How a chunk becomes a vector: cosine, dot and L2, query and document prompts, vector size and how to shrink it, and how to shortlist and test a model on your own questions.

Last updated

Core11 min readFirst readRAG Architecture

After this section you can

  • Compare two texts with cosine, dot and L2, and say when the three rank chunks alike
  • Apply the right query and document prompts, and stamp every vector so a mismatched model is caught
  • Shortlist an embedding model by licence, language and input cap, and decide on your own questions
02

Embeddings: Text In, Vector Out

How a chunk becomes a vector: cosine, dot and L2, query and document prompts, vector size, and choosing a model.

Key idea

An embedding model turns a text into a vector, a fixed-length list of numbers, so similar meanings land close together. Search is then arithmetic: embed the question, find the nearest chunk vectors. Both sides need the same model and version, each with the prompt that model expects; a mismatch can be silent.

Question and chunk go through one model; the nearest vectors are the candidates, even at 0.38
TEXT INONE MODELVECTOR OUTCLOSENESS · COSINE Chunk 12QuestionEmbedding model Refunds are acceptedwithin 30 daysof delivery.Can I still return thisafter three weeks?one model,one version document promptquery prompt equal dimensions: a mismatch raises no error [0.05, 0.09, …][0.09, 0.03, …] 256 numbers256 numbers question ↔ chunk 12question ↔ runbook line 0.380.01 1 = same direction

Pans sideways on narrow screens.

Related

More in RAG & MCP

Get full access to all 149 sections with code examples, diagrams, and interactive animations.

Unlock Premium