Vector Arithmetic Playground

Perform add, subtract, and interpolate operations on embedding vectors.

Run king - man + woman style vector arithmetic in your browser. Add, subtract, interpolate, or build analogies on embedding vectors and see the resulting vector with its magnitude and cosine similarity to the inputs. It runs free in your browser on Gera Tools, with nothing uploaded.

Last updated Source: Gera Tools

What is the king - man + woman example?

It is the classic word-embedding analogy showing that embeddings encode relationships as directions. Subtracting the man vector from king and adding woman lands near the queen vector, demonstrating that gender is roughly a consistent offset in the space.

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:

  1. Choose an embedding model — OpenAI text-embedding-3-small, a sentence-transformer, or any other.
  2. Call the API to get the vector for each word or phrase you want to test.
  3. Paste the raw vectors (JSON arrays or comma-separated floats) into the playground.
  4. Run the analogy and inspect the result vector.
  5. 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.