1. Embed text
An embedding model maps a piece of text to a fixed-length numeric vector.
const res = await embedder.embed("the quick brown fox");Typorithm · medium
Step 1 of 8 · intro card
RAG & Embeddings
An embedding maps text to a dense vector where distance encodes semantic meaning. Cosine similarity ranks how related two pieces of text are, and these vectors are the foundation of semantic search and RAG.
An embedding model turns text into a dense vector of floats — often hundreds or thousands of dimensions. Unlike keyword matching, the vector captures meaning, so paraphrases land near each other even with no shared words.
To compare two pieces of text you compare their vectors. Cosine similarity looks at the angle between them: a score near 1 means very similar meaning, near 0 means unrelated. This turns 'how related are these?' into simple arithmetic.
Because semantically close text produces nearby vectors, embeddings power semantic search: embed a query, find the nearest stored vectors, and you retrieve the most relevant passages. That retrieval step is the heart of RAG.
An embedding is a dense vector encoding text meaning.
Cosine similarity scores how related two vectors are.
Embeddings underpin semantic search and RAG.
const res = await embedder.embed("the quick brown fox");
// vector: [0.12, -0.04, ...] e.g. 1536 dims
const sim = cosineSimilarity(vecA, vecB);
// near vectors mean similar meaningConnect each part of the code to the concept before you type.
An embedding model maps a piece of text to a fixed-length numeric vector.
const res = await embedder.embed("the quick brown fox");The result is a dense vector of floats (here 1536 dimensions) that encodes the text's meaning.
// vector: [0.12, -0.04, ...] e.g. 1536 dimsCosine similarity measures the angle between two vectors to score how related their texts are.
const sim = cosineSimilarity(vecA, vecB);Vectors that sit close together represent text with similar semantic meaning.
// near vectors mean similar meaningRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.