Skip to content

Embedding

Also called: embeddings, vector embedding, vector embeddings

Published:

How does an embedding work?

A lot of machine learning data is sparse. Picking one item out of thousands takes a very long vector that is almost all zeros, known as a one-hot vector. Embeddings turn that sparse data into a lower-dimensional representation [1]. A shorter vector means fewer weights in the model, which cuts the data, computation and memory it needs [1].

The model usually learns the embedding itself by mapping high-dimensional data into a lower-dimensional space. In that space each item is described by as many floating-point numbers as there are dimensions [2].

How is similarity measured?

The distance between two points in the space serves as a measure of how alike the two items are [2]. Google's teaching example places foods on imagined axes such as "sandwichness", "dessertness" and "liquidness". Shawarma and a hot dog land close to each other, while apple strudel sits far from both [2]. Real embedding spaces have many more dimensions, and individual dimensions are rarely as easy to read as "dessertness" [2].

Where are embeddings used?

Embedding models can encode text, images and audio as vectors that capture meaning and context [3]. Once those vectors are stored in a vector database, finding the nearest neighbours of a query powers semantic search, visual search and recommendation systems [3]. Retrieval-augmented generation (RAG) relies on the same lookup to find relevant documents.

Frequently asked questions

What do the dimensions of an embedding mean?

Teaching examples give dimensions names like dessertness, but in real models individual dimensions usually have no simple meaning on their own.

Are embeddings only for text?

No. Embedding models can also represent images and audio as vectors.

Sources

  1. Embeddings — Google for Developers
  2. Embeddings: Embedding space and static embeddings — Google for Developers
  3. What is a Vector Database? — AWS