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.
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.
- Both texts are encoded into 384-dimensional vectors (normalized to unit length)
- Cosine similarity is computed:
dot(A, B) / (|A| Γ |B|) - 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
| Score | Interpretation | Example pair |
|---|---|---|
0.95 β 1.00 | Near-identical meaning | “I love dogs” / “I adore dogs” |
0.80 β 0.95 | Very similar β paraphrases | “fix the bug” / “resolve the issue” |
0.60 β 0.80 | Related topic | “Python programming” / “JavaScript coding” |
0.30 β 0.60 | Loosely related | “database indexing” / “cloud storage” |
0.00 β 0.30 | Unrelated | “JWT token” / “chocolate cake” |
< 0.00 | Opposing / contradictory | “increase performance” / “degrade performance” |
Why not 1.0 for identical text?
all-MiniLM-L6-v2uses float32 arithmetic β identical inputs should score exactly1.0000. Small deviations indicate floating-point rounding in the WASM runtime.
Use This in Your Code
Python β sentence-transformers (same model, local)
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
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)
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.97Choosing an Embedding Model
| Model | Dims | Max Tokens | Cost | Best For |
|---|---|---|---|---|
all-MiniLM-L6-v2 | 384 | 256 | Free (in-browser) | Prototyping, client-side tools |
text-embedding-3-small | 1536 | 8191 | $0.02/1M | Production RAG, cost-sensitive |
text-embedding-3-large | 3072 | 8191 | $0.13/1M | Best OpenAI quality |
voyage-3 | 1024 | 32000 | $0.06/1M | Top retrieval benchmarks |
nomic-embed-text | 768 | 8192 | Free (local) | Long-context open source |