AI Lab

Tool 03

Embedding Explorer

Turn text into vectors, compare cosine similarity, and project embeddings into 2D.

Learn

Embeddings turn discrete token IDs into continuous vectors — lists of numbers that capture meaning. Similar concepts end up near each other in vector space. This is the foundation of semantic search, RAG retrieval, and clustering.

Text → meaning as vectors

After tokenization, each token ID is looked up in an embedding table — a large matrix where each row is a vector. The model learns these vectors during training so that useful relationships emerge.

"Cat" and "kitten" end up close together. "Cat" and "refrigerator" end up far apart. The model never sees a dictionary definition — it learns geometry from billions of examples.

Embedding lookup table

The embedding matrix has shape [vocab_size, embedding_dim]. Token ID 42 simply picks row 42. That row is the vector fed into the first transformer layer.

Larger embedding_dim (e.g. 768, 4096) means more capacity to represent nuance, but also more parameters and compute.

Cosine similarity vs distance

Cosine similarity measures the angle between two vectors — 1.0 means identical direction, 0 means orthogonal, -1 means opposite. It ignores vector length, focusing on direction (meaning).

Euclidean distance measures how far apart points are in space. For normalized embeddings, cosine and distance often agree on ranking. Search systems usually rank by cosine similarity.

Why 2D plots are lossy

Real embeddings live in hundreds or thousands of dimensions. The 2D scatter plot above squashes that space down so you can see it — but neighbors can shift when projected.

Treat the plot as intuition, not ground truth. Trust the cosine similarity numbers more than visual proximity for close calls.

What to try in this tool

Enter synonym pairs (cat/kitten, happy/joyful) and antonym pairs (hot/cold) — compare cosine scores. Try domain-specific terms (Python/JavaScript) vs unrelated words.

Toggle Ollama to get real embeddings from a local model, or use synthetic vectors to learn the mechanics when Ollama is unavailable.

Try it above

  • Enter cat, kitten, car, automobile — which pairs score highest?
  • Add antonyms like hot and cold — compare to synonym scores.
  • Try technical terms vs everyday words and read the distance column.
  • Toggle Ollama on/off and note when fallback vectors are used.