Lesson 03 · Foundations · 13 min
Embeddings and similarity
An embedding turns text into a list of numbers positioned so that related text lands nearby. The corpus here becomes 1024 numbers per chunk. A query becomes 1024 numbers, and retrieval is the arithmetic of finding the closest ones.
"Similar" means something specific and slightly alien: near in the space this model was trained to build. That is usually close to what you mean by relevant, and sometimes is not. A question and its answer are related but do not read alike — a question is short and interrogative, the answer is declarative.
Which is why embedding models for retrieval are asymmetric, and why the API takes an input type. The same sentence embedded as a query lands somewhere different from the same sentence embedded as a passage. Getting that wrong costs recall in a way nothing in your logs will point at.
// Indexing the corpus
embed({ texts: chunks, inputType: "passage" })
// Answering a question
embed({ texts: [question], inputType: "query" })Read the scores in the lab as a shape, not a number. An absolute value of 0.5 means little on its own; a top hit at 0.53 with the next at 0.45 means retrieval found something distinct. Four hits clustered at 0.30 means it found nothing and is showing you the nearest available text.
Similarity has no idea what is true. Two passages giving different return windows are both highly similar to a question about return windows. Retrieval finds text about the topic; deciding which applies is somebody else's job, and lesson 6 is about whose.
Checkpoint
Find a question where the top two scores are close, and say why the model cannot tell them apart.