Backend Bootcamp

Embedding Dimension Visualizer

Compute real cosine similarity between two texts in your browser using all-MiniLM-L6-v2. Visual 2D vector diagram, no API key needed.

Compute real semantic similarity between two pieces of text β€” entirely in your browser using all-MiniLM-L6-v2. No API key, no server, no data sent anywhere.

Embedding Similarity Visualizer all-MiniLM-L6-v2 Β· 23 MB Β· browser-only
100% client-side β€” no data leaves your browser
Try an example:

How It Works

The tool runs all-MiniLM-L6-v2 directly in your browser via Transformers.js and WebAssembly. The model (~23 MB) is downloaded once and cached permanently β€” subsequent runs are instant.

  1. Both texts are encoded into 384-dimensional vectors (normalized to unit length)
  2. Cosine similarity is computed: dot(A, B) / (|A| Γ— |B|)
  3. The result is projected onto a 2D unit circle where the angle between the two arrows equals arccos(similarity)

The visualization shows the geometric meaning of cosine similarity: the smaller the angle between vectors, the more similar the meaning.


Understanding the Score

ScoreInterpretationExample pair
0.95 – 1.00Near-identical meaning“I love dogs” / “I adore dogs”
0.80 – 0.95Very similar β€” paraphrases“fix the bug” / “resolve the issue”
0.60 – 0.80Related topic“Python programming” / “JavaScript coding”
0.30 – 0.60Loosely related“database indexing” / “cloud storage”
0.00 – 0.30Unrelated“JWT token” / “chocolate cake”
< 0.00Opposing / contradictory“increase performance” / “degrade performance”

Why not 1.0 for identical text? all-MiniLM-L6-v2 uses float32 arithmetic β€” identical inputs should score exactly 1.0000. Small deviations indicate floating-point rounding in the WASM runtime.


Use This in Your Code

Python β€” sentence-transformers (same model, local)

python
from sentence_transformers import SentenceTransformer, util

model = SentenceTransformer('all-MiniLM-L6-v2')

texts = ['I love dogs', 'I adore dogs', 'quantum physics equations']
embeddings = model.encode(texts, normalize_embeddings=True)

for i in range(len(texts)):
    for j in range(i + 1, len(texts)):
        score = util.cos_sim(embeddings[i], embeddings[j]).item()
        print(f'{texts[i]!r} ↔ {texts[j]!r}: {score:.4f}')

JavaScript β€” same model, same library

javascript
import { pipeline } from '@xenova/transformers';

const extractor = await pipeline('feature-extraction', 'Xenova/all-MiniLM-L6-v2');

async function similarity(textA, textB) {
  const [a, b] = await Promise.all([
    extractor(textA, { pooling: 'mean', normalize: true }),
    extractor(textB, { pooling: 'mean', normalize: true }),
  ]);
  const va = Array.from(a.data), vb = Array.from(b.data);
  return va.reduce((s, v, i) => s + v * vb[i], 0); // dot product of normalized vecs = cosine sim
}

console.log(await similarity('I love dogs', 'I adore dogs')); // ~0.97

Python β€” OpenAI embeddings (higher quality, paid)

python
from openai import OpenAI
import numpy as np

client = OpenAI()

def embed(text: str) -> list[float]:
    return client.embeddings.create(
        model='text-embedding-3-small',
        input=text
    ).data[0].embedding

def cosine(a, b):
    a, b = np.array(a), np.array(b)
    return float(np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b)))

print(cosine(embed('I love dogs'), embed('I adore dogs')))  # ~0.97

Choosing an Embedding Model

ModelDimsMax TokensCostBest For
all-MiniLM-L6-v2384256Free (in-browser)Prototyping, client-side tools
text-embedding-3-small15368191$0.02/1MProduction RAG, cost-sensitive
text-embedding-3-large30728191$0.13/1MBest OpenAI quality
voyage-3102432000$0.06/1MTop retrieval benchmarks
nomic-embed-text7688192Free (local)Long-context open source

Search the bootcamp

↑ ↓ to move Β· Enter to open Β· Esc to close See all results