A vector is an ordered list of numbers. In embedding systems, the list is a point or direction in a learned high-dimensional space. Distance functions compare vectors, and nearby vectors may represent inputs the model learned to treat similarly. The coordinates are useful computational features, not guaranteed human-readable concepts or facts.
The vector [0.2, -0.4, 0.8] has three dimensions. Order matters: changing the coordinate order changes the vector. The magnitude, or L2 norm, is:
The L2 distance between vectors a and b is the magnitude of their difference:
You need not calculate hundreds of coordinates manually. Understanding the small case lets you inspect the database operator without treating it as magic.
Cosine distance compares direction. L2 distance compares physical separation, which includes both direction and magnitude. Inner product combines alignment and magnitude. An embedding model's documentation or evaluation should guide the metric; choosing a familiar metric by taste can damage ranking.
Some models produce normalized vectors whose magnitude is approximately one. For unit vectors, cosine ranking, L2 ranking, and inner-product ranking have close mathematical relationships, although their numeric scores differ.
Real text embeddings commonly use hundreds or thousands of dimensions. You cannot draw them faithfully. High-dimensional spaces also behave differently from a room: many distances can concentrate into a narrow range, data distribution matters, and intuition from two dimensions can mislead.
Treat the visualization as a map, not the territory. Validate neighborhoods with labeled queries from your own domain.
Function availability can vary by installed extension version; confirm against \dx vector and upstream documentation.
Calculate three 2D distances on paper, then run them in SQL. Include identical vectors, perpendicular unit vectors, and opposite unit vectors. Record L2 and cosine distances. Explain each result geometrically before moving to model-generated embeddings.
Teach me vector magnitude, L2 distance, cosine similarity, and inner product using the two vectors [insert small vectors]. Ask me to predict each value before revealing the calculation. Then give me PostgreSQL expressions to verify them and explain how the intuition changes in 1,000 dimensions.
Verification contract: Calculate independently with a second method or SQL. The assistant must not assign semantic labels to coordinates that were not defined by the example.