Bookmarks

Embedding (vector representation)

A fixed-length vector in which a model encodes the meaning of a text or another object: fragments with similar meaning get similar vectors.

Also: vector representation, vector representations, embedding vector

checked 9 Nov

All terms

An embedding turns text, an image or a piece of code into a list of numbers that ordinary algorithms can work with. Semantic search, RAG, recommendations and clustering are all built on this: the system finds objects with similar meaning even when they share no keywords.

How text becomes a vector

Text is run through an encoder model: it merely encodes existing text into a vector and, unlike a chat model, generates nothing. The output is a vector of several hundred or thousand numbers: for example, the multilingual MiniLM from Sentence Transformers has a dimensionality of 384, while the OpenAI embedding models use 1536 and 3072. Each model has its own space, so both documents and the query are encoded with the same model — otherwise their vectors cannot be compared. The encoder also has an input length limit, for example 8192 tokens for the OpenAI models, so long texts are split into chunks in advance.

StepWhat happens
Corpus fragmentsthe model encodes each chunk of a document as a fixed-length vector
Vector indexthe vectors are put into an index or a vector database
Querythe question is encoded with the same model and the nearest vectors are looked up
Answerfrom the found fragments the reader or a model gets the material

How similarity is measured

A metric computes vector similarity. In many libraries the default is cosine similarity — the angle between vectors: one means the same direction, zero means no relation. On normalised vectors the dot product gives the same value, while for clustering Euclidean distance is more often used.

MetricWhat it measuresWhere it is used
Cosine similaritythe angle between vectors, from −1 to 1semantic search, the default in many libraries
Dot productthe sum of coordinate productson normalised vectors gives the same ranking as cosine, but is faster
Euclidean distancethe distance between points in spaceclustering, duplicate detection

Where embeddings are used

  • semantic search and RAG: the query vector is used to find document fragments with a similar meaning
  • recommendations: similar articles, products or vacancies get close vectors
  • clustering and deduplication: grouping news, finding repeats and duplicates
  • classification and moderation: the vector serves as a ready-made set of features for a simple classifier

Vectors are stored and searched in vector databases. The word itself comes from mathematics: there, an embedding is a mapping of one space into another that preserves the structure of objects; machine learning borrowed it for vector representations of words, texts and images.

Sources

the term is written from these pages

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • vector database

    An embedding is the meaning vector itself, while a vector database stores millions of such vectors and quickly finds the nearest neighbours.

  • fine-tuning

    Fine-tuning changes the model’s weights for a task, while embeddings are obtained from the ready model without changing its weights.

In depth in the references

where the topic is covered in detail

Appears in the references