Explore the geometry of embeddings
Embeddings turn words and concepts into vectors, and one of their most striking
properties is that meaning behaves like geometry: relationships become directions
you can add and subtract. This playground lets you run those operations directly —
the famous king − man + woman ≈ queen analogy, simple vector sums, and smooth
interpolation between two points — and inspect the result.
How it works
You enter vectors as comma-separated numbers or JSON arrays, and the tool parses
them and checks that every vector shares the same dimension. For an analogy it
computes A − B + C; for add and subtract it does the element-wise operation; for
interpolation it computes A·(1−t) + B·t with a slider for t. Alongside the
resulting vector it reports the magnitude and the cosine similarity between the
result and each input, so you can see how the operation moved you through the
space. Everything runs client-side with no network calls.
The four operations explained
Analogy (A − B + C): The classic example is king − man + woman, which in a
well-trained word embedding space lands close to queen. The idea is that the
direction from man to king encodes some concept of royalty applied to a male
entity. Subtracting man removes that gender direction, and adding woman reapplies
it for the female equivalent. The result is not guaranteed to be exactly queen, but
it is typically closer to queen than to most other words. Real-world analogies in
production embeddings are noisier than the textbook example — the relationship holds
directionally but the nearest neighbor may be queens, monarch, or king itself.
Add and subtract: Element-wise addition and subtraction let you blend or contrast concepts. Adding two concept vectors can produce a result that reads as their combination; subtracting one from the other isolates the difference.
Interpolation (lerp): A·(1−t) + B·t traces a straight line through the
embedding space between A and B. At t = 0 you have A exactly, at t = 1 you have
B exactly, and values in between are blends. The cosine similarity to each endpoint
swaps dominance somewhere around the midpoint. This is useful for visualising how
gradually one concept transitions into another in the model’s learned geometry.
Using it with real embeddings
To run a proper analogy test:
- Choose an embedding model — OpenAI
text-embedding-3-small, a sentence-transformer, or any other. - Call the API to get the vector for each word or phrase you want to test.
- Paste the raw vectors (JSON arrays or comma-separated floats) into the playground.
- Run the analogy and inspect the result vector.
- Compare the result against candidate vectors using a nearest-neighbor search to find what the result is closest to in the full vocabulary.
The playground handles the arithmetic and shows the result; the nearest-neighbor step
requires a separate search over your embedded vocabulary. Many vector databases and
libraries expose a search(vector, k=5) call you can use for this.
Why cosine similarity, not magnitude
Most embedding models normalize their output vectors to unit length, meaning every vector has the same magnitude (1.0). In that case, cosine similarity and Euclidean distance rank results identically. Cosine similarity is the standard choice because it is intuitive (1 = identical direction, 0 = orthogonal, −1 = opposite) and holds even when vectors are not perfectly normalized. Magnitude can mislead if one vector was not normalized — a longer vector can appear “closer” by Euclidean distance purely because of its scale, not because its direction is a better match.