If you have used semantic search, a recommendation engine, or any "chat with your documents" feature, you have used embeddings . They are the way modern AI systems represent meaning as numbers, and the idea is simpler than the name suggests.
In this walkthrough we will cover what an embedding actually is, then run a small Java program that shows the two things that make embeddings useful: measuring similarity and doing arithmetic on meaning. The code was compiled and run on JDK 21 (Temurin 21.0.13), and the outputs shown are real runs.
Core concepts
An embedding is just a vector. A list of floating point numbers, like [0.12, -0.44, 0.87, ...] . An embedding model turns a piece of text (a word, a sentence, a whole document) into one of these vectors. The numbers are not chosen by hand; the model learns them from large amounts of text, so that the position of each vector captures something about the meaning of the text.
Distance means relatedness.…