Lesson 04.04 · Phase 04 · Memory & Context Engineering

Embeddings from scratch

An embedding turns text into a direction. Texts that mean similar things should point the same way. Build three of them by hand and you will know exactly what the real ones are fixing.

Learning objectives

  • Explain what an embedding is, and why cosine similarity is used to compare them.
  • Implement three embedders by hand: TF-IDF, hashed character n-grams, and PPMI word vectors.
  • Predict which kinds of query each one fails on (typos, word forms, synonyms) and why.
  • Evaluate any embedder, including a real embedding model, with a small labelled retrieval test.

An agent's long-term memory is useless if it can't find the right memory. The user asks to "see a doctor"; the note that matters says "the physician has a clinic on weekdays". Search by keyword and you get nothing: the two texts share no words.

Loading the full lesson…