Agent Engineering

Embedding

Also known as: vector embedding, text embedding

Definition

An embedding is a dense vector representation of text, an image or other content, positioned so that semantically similar items sit close together under a distance measure such as cosine similarity. Embeddings are what make semantic search, clustering and retrieval possible without exact keyword matches.

Last reviewed · Part of the Architecture Glossary

In practice

Operational properties that decide designs:

  • Embeddings are model-specific. Vectors from two different models are not comparable, so changing the embedding model means re-embedding the entire corpus. Store the model name and version alongside every vector, or the migration becomes archaeology.
  • Dimensionality is a cost. 1,536 dimensions at 4 bytes is 6 KB per vector; ten million chunks is 60 GB before the index structure. Matryoshka-style truncation and quantisation to int8 cut this substantially with modest recall loss.
  • Asymmetry. Query text and document text have different shapes. Models trained for retrieval expect a query prefix and a document prefix; using the wrong one silently degrades recall.
  • Similarity is not relevance. Cosine similarity finds text about the same topic, which includes the document that contradicts the answer you want. Reranking exists for this reason.

When it matters

Semantic search, RAG, deduplication, clustering support tickets, recommendation, and classification with a small labelled set.

Common mistake

Embedding whole documents. A 20-page PDF as one vector averages away everything specific in it, so it matches everything weakly and nothing strongly. Chunk first, and keep the parent document as metadata for context expansion at read time.

See also

Go deeper