We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Embeddings

The tool that powers semantic search is embeddings: numerical representations of text that capture meaning.

Specifically, our embeddings are vectors: a fancy word for a list of numbers. You can think of a vector as a point in space, or as a direction and a magnitude from the origin point (0, 0).

Here are two 2-dimensional vectors:

  • Red: [3, 2] (3 units right, 2 units up)
  • Blue: [1, 2] (1 unit right, 2 units up)

Embedding happens when we take a piece of text and convert it into a vector. For example:

  • "King" → [3.5, 2.5]
  • "Queen" → [3.0, 2.0]
  • "Human" → [3.0, -3.0]

The idea is that the distance between vectors represents how similar the meanings of the words are. King and queen are very similar, so their vectors are close together. Human is less similar, so its vector is further away.

Vector values are often normalized to a smaller floating-point range, such as -1.0 to 1.0, so they're easier to compare.