Embeddings

Numeric vectors representing meaning, enabling similarity search.

CurrentintermediateFull course available

Overview

Embeddings map text (or images) to numeric vectors such that semantically similar inputs produce nearby vectors -- enabling similarity search ('find text like this') that keyword matching can't do, since it captures meaning rather than exact word overlap.

What it is
Numeric vector representations of text (or other data) where distance/similarity reflects semantic similarity.
Why it's used
It enables 'search by meaning' -- finding relevant content even when the query and the source text share no exact words.
Where it fits
The retrieval half of retrieval-augmented generation (RAG); this platform's own AI tutor uses keyword search today, with embeddings as a documented future upgrade path.

Core concepts

  • Vectors and dimensionality
  • Cosine similarity
  • Embedding models
  • Vector search vs. keyword search

Example

Cosine similarity measures the angle between two vectors, not their length -- a common way to compare embeddings regardless of their overall magnitude. This platform's AI, LLMs & RAG course has learners implement exactly this function.

function cosineSimilarity(a, b) {
  const dot = a.reduce((s, ai, i) => s + ai * b[i], 0);
  const magA = Math.sqrt(a.reduce((s, ai) => s + ai * ai, 0));
  const magB = Math.sqrt(b.reduce((s, bi) => s + bi * bi, 0));
  return dot / (magA * magB);
}

Common use cases

  • Semantic search
  • Recommendation systems
  • The retrieval step of RAG pipelines

Project ideas

  • Implement cosine similarity by hand and use it to rank a small set of text snippets by relevance to a query

Official references