Embeddings Explained: How Text Becomes Vectors for Search and AI

What embeddings are, how cosine similarity measures meaning, dimensions and normalisation, common uses like semantic search and clustering, and pitfalls.

Published December 1, 2026

An embedding is a list of numbers that represents the meaning of a piece of text (or an image, or code). Texts with similar meanings get vectors that point in similar directions. That simple property powers semantic search, RAG, recommendations, deduplication, clustering and classification, all without training your own model.

The concept

Embedding models are trained so that related inputs land close together in a high-dimensional space, often 384 to 3,072 dimensions. "How do I reset my password?" and "I forgot my login" share few words but end up near each other, while "reset the router" ends up further away despite sharing "reset".

Closeness is usually measured with cosine similarity, the cosine of the angle between two vectors, ranging from -1 to 1. Many models output normalised vectors, in which case cosine similarity equals the dot product and is cheap to compute. Vector databases and indexes (HNSW, IVF) make finding the nearest neighbours among millions of vectors fast.

How embeddings are used

inputencodesearch"forgot my login"Embedding model[0.12, -0.48, …]1,024 dimsNearest neighbourscosine
Text in, vector out, then similarity search.

Similarity reflects meaning

"I forgot my login"0.91"Change account email"0.63"Reset the router"0.32"Pizza recipes"0.05
Illustrative cosine similarity to "How do I reset my password?".

Common uses

Use caseHow embeddings help
Semantic search / RAGFind passages by meaning, not keywords
DeduplicationDetect near-duplicate tickets or articles
ClusteringGroup feedback or logs by topic
ClassificationNearest labelled examples or a light classifier on vectors
RecommendationsFind similar items or content

Practical examples

Cosine similarity with NumPy

For normalised vectors this is just a dot product.

import numpy as np
def cosine(a, b):
    a, b = np.asarray(a), np.asarray(b)
    return float(a @ b / (np.linalg.norm(a) * np.linalg.norm(b)))

Local embeddings with sentence-transformers

Open models run on CPU for small workloads.

from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2")          # 384 dimensions
vecs = model.encode(["How do I reset my password?", "I forgot my login"], normalize_embeddings=True)
print(vecs[0] @ vecs[1])

Store and query in pgvector

Keep vectors next to your relational data.

CREATE TABLE faqs (id serial PRIMARY KEY, question text, embedding vector(384));
SELECT question, 1 - (embedding <=> $1) AS similarity
FROM faqs ORDER BY embedding <=> $1 LIMIT 3;

Common mistakes

  • Mixing vectors from different embedding models in one index; they are not comparable.
  • Treating similarity scores as calibrated probabilities with a universal threshold.
  • Embedding huge documents as one vector, blurring their meaning.
  • Re-embedding everything without versioning when switching models.

Key takeaways

  • Embeddings map meaning to vectors; similar meaning → nearby vectors.
  • Cosine similarity (or dot product for normalised vectors) measures closeness.
  • They power search, RAG, clustering, dedup and recommendations.
  • Never mix models in one index; version your embeddings.

FAQ

How many dimensions should I use?

Whatever the model produces; some models support shorter truncated vectors to save storage with a small quality trade-off.

Can embeddings work across languages?

Multilingual embedding models place translations near each other, enabling cross-language search.

Do I need a vector database?

For thousands of vectors, NumPy or pgvector is plenty. Dedicated vector databases help at large scale or with advanced filtering needs.

More AI articles