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.
| Step | What happens |
|---|---|
| Corpus fragments | the model encodes each chunk of a document as a fixed-length vector |
| Vector index | the vectors are put into an index or a vector database |
| Query | the question is encoded with the same model and the nearest vectors are looked up |
| Answer | from 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.
| Metric | What it measures | Where it is used |
|---|---|---|
| Cosine similarity | the angle between vectors, from −1 to 1 | semantic search, the default in many libraries |
| Dot product | the sum of coordinate products | on normalised vectors gives the same ranking as cosine, but is faster |
| Euclidean distance | the distance between points in space | clustering, 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- Semantic Textual Similarity — Sentence Transformerssbert.net/docs/sentence_transformer/usage/semantic_textual_similarity.html(opens in a new tab)
- Embeddings — OpenAI docsplatform.openai.com/docs/guides/embeddings(opens in a new tab)
- paraphrase-multilingual-MiniLM-L12-v2 — Hugging Facehuggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2(opens in a new tab)
Verified 9 Nov