What is an embedding?
One idea, one win: text becomes a point you can measure distance on.
The idea
An embedding is a function that turns any piece of text into a fixed-length list of numbers — a coordinate in a high-dimensional space.
embed("renew your passport") → [0.12, -0.43, 0.88, …] (384 numbers)
embed("documents for going abroad") → [0.10, -0.40, 0.85, …]
The lists look random, but texts with similar meaning end up with similar coordinates. "Nearby in space" becomes "similar in meaning." That is the whole foundation of semantic search and RAG.
Why this matters for the mission
The ai-smart-gmail library retrieves emails by meaning. That retrieval
is embedding the query, then ranking emails by how close their embeddings are.
No embeddings → no semantic search → no RAG.
Check your understanding
Try it
Run the Day 8 demo and watch the ranking:
cd day8
bun install
bun start
Find a query with zero word overlap with its top result. That gap is the proof embeddings capture meaning, not keywords.
Primary source: read the OpenAI Embeddings guide (10 min) — clearest intro to what embeddings are and how to search with them.
See also the embeddings reference and Sentence Transformers docs.