Embeddings and Vector Search · Vectors · lesson 1 of 8
What an embedding is
about 14 minutes · free · runs in your browser
A position, not a summary
An embedding is a list of numbers describing where a text sits in a space the model learned. The numbers mean nothing individually — dimension 7 is not "how much this is about cooking". What means something is the direction the whole list points, because texts about the same thing end up pointing the same way.
Two properties make the rest of this course possible:
- Same text, same vector. It is a function, not a sample. Embed a text twice and you get the identical list, which is what makes caching worthwhile.
- Fixed width. Every text — a word or a page — becomes the same number of dimensions, so any two are comparable.
import fake_embeddings
v = fake_embeddings.embed("bake the dough in a hot oven")
len(v) # fake_embeddings.DIM, always
The vectors here are already unit length (their length is exactly 1), which is what most embedding APIs return. That detail makes the next lesson's arithmetic much shorter.
Your turn: write describe(text) returning (width, length) — the number of
dimensions and the geometric length of the vector, rounded to three places.
You start from this, and edit it in the browser:
import fake_embeddings
def describe(text):
"""Return (number of dimensions, vector length rounded to 3 places)."""
return (0, 0.0)