AI Engineering Playbook
Embeddings & Search

Embeddings & Search

Turning meaning into geometry, then searching that geometry fast enough to matter.

Prerequisites

  • How LLMs Work — transformers, and the difference between an encoder and a generator.
  • Tokens & Context Windows — embedding models have token limits too, and silently truncate past them.

Why this section exists

Keyword search matches strings. Users ask in meaning. Someone searching "how much time off do I get" will never match a document titled "PTO accrual policy" on shared words alone.

The fix is an old idea executed well: represent text as a point in high-dimensional space, trained so that things meaning the same thing land near each other. Then "find relevant documents" becomes "find nearby points" — and nearest-neighbour search is a problem computer science has spent decades making fast.

That single move is the engine under RAG, semantic search, recommendations, deduplication, and clustering. Which means this section is load-bearing: nearly every retrieval question eventually bottoms out in "…and why does that work?" — and the answer is here.

The chain you're building:

Each stage in that chain has its own page, in that order.

What's in here

PageThe question it answers
EmbeddingsWhat an embedding is, how contrastive training produces one, how to pick a model
Similarity MetricsCosine vs dot product vs Euclidean — and when the choice actually changes results
ANN IndexesHNSW and IVF, quantization, and the recall/speed/memory triangle you trade along
Hybrid SearchWhy BM25 still wins on IDs and rare terms, and how RRF fuses two ranked lists
RerankersBi-encoder vs cross-encoder, and why two-stage retrieval is the standard shape
Embeddings Beyond RAGClassification, recommendation, dedup, anomaly detection — the uses that get overlooked

Where this connects

  • Vector Databases — where these vectors live in production, and what operating that store costs you.
  • RAG — the flagship consumer of everything in this section.
  • Multimodal — the same geometry trick, applied to images and audio.
ANN Indexes

On this page