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.