AI EngineeringFoundation14 min

Embeddings & vector search

Represent meaning as vectors so you can find related text by similarity instead of keywords.

See it on the map

An embedding model maps text to a vector so that texts with similar meaning land close together. Search becomes: embed the query, find the nearest stored vectors, and return their source text. Similarity is usually cosine similarity or dot product.

Exact nearest-neighbour search compares against every vector, which is fine for thousands and too slow for millions. Approximate indexes such as HNSW or IVF trade a little recall for large speedups. Always measure recall against the exact result on your own data.

Embeddings are tied to the model that made them. Changing the model means re-embedding everything, and queries and documents must use the same one. Store the model name alongside each vector.

Key points

  • Similar meaning means nearby vectors, not shared words.
  • ANN indexes trade recall for speed. Measure that trade.
  • Never mix vectors from different embedding models.
  • Store metadata with each vector so you can filter and cite.

Trade-offs

ChoiceYou gainYou pay
HNSWHigh recall, low latencyMemory heavy, slower to build
IVFSmaller memory footprintNeeds training, recall depends on probe count

Answer these out loud

  1. 1Why does a query for 'cancel my plan' fail to find a document titled 'terminate subscription' with keyword search but succeed with embeddings?
  2. 2You switch embedding models next quarter. What does the migration look like with zero downtime?

Build it

Embed a folder of notes, store the vectors in Postgres with pgvector, and return the top 5 matches with similarity scores for a query.

Use this from an agent

Any MCP client, including Grok, can read this lesson. See how to connect.

REST
curl https://engineeros-delta.vercel.app/api/v1/topics/embeddings-and-vector-search

This unlocks