Phase 3 — Core AI Engineering · Lesson 27 · 20 XP
Embeddings
An embedding is a vector representing meaning — text with similar meaning maps to vectors that are close together, measured with the cosine similarity from Lesson 17. An embedding model turns text into these vectors; unlike a chat model, it doesn't generate text, it just maps text to a point in a high-dimensional space.
response = client.embeddings.create(model="embedding-model", input="the cat sat on the mat")
vector = response.data[0].embedding # e.g. a list of 1536 floatsVectors from two different embedding models are not comparable — they live in different, unrelated spaces, even if both have the same number of dimensions. Always embed your query with the same model you used to embed your documents.
Exercise
Embed 10 short sentences covering a few different topics. Compute pairwise cosine similarity between all of them and confirm sentences on the same topic score noticeably higher than sentences on unrelated topics.
Check yourself
1. Why can't you directly compare embeddings produced by two different embedding models?
2. What does it mean, in terms of the vectors themselves, for two pieces of text to be semantically similar?
Project: streaming chatbot with tools and memory
Answer the check-yourself questions to unlock this