← Back to Glossary

Embeddings

Embeddings are dense numeric vector representations of data — text, images, audio, or other objects — learned so that semantically similar inputs end up close together in vector space.

Overview

An embedding is a fixed-length vector of floating-point numbers produced by a machine learning model to represent a piece of data, such as a word, sentence, document, or image. The key property that makes embeddings useful is that geometric distance in the vector space tracks semantic similarity in the original domain: two sentences with similar meaning should produce embeddings that are close together (by cosine similarity or Euclidean distance), even if they share few literal words. Models like OpenAI's text-embedding-3, Cohere's embedding models, and open-source options such as those from the sentence-transformers family are commonly used to generate them.

How embeddings are used

Embeddings are the foundation of several practical techniques: semantic search (finding documents by meaning rather than exact keyword match), recommendation systems (finding similar items or users), clustering and deduplication, classification via nearest-neighbor lookup, and retrieval-augmented generation (RAG), where relevant text chunks are retrieved by embedding similarity and provided as context to a language model.

Storing and querying embeddings with DuckDB

DuckDB can store embeddings as a fixed-size ARRAY column and search them with the vss extension, which adds HNSW indexing and distance functions.

Copy code

INSTALL vss; LOAD vss; CREATE TABLE chunks ( id INTEGER, text VARCHAR, embedding FLOAT[1536] ); -- find the 5 most similar chunks to a query embedding SELECT id, text FROM chunks ORDER BY array_distance(embedding, ?::FLOAT[1536]) LIMIT 5;

This lets an application keep raw text, metadata, and embeddings together in one place and combine similarity search with ordinary SQL filtering — for example, restricting a similarity search to documents from a specific date range or category in the same query.

Related terms

FAQS

It depends on the model — common sizes range from a few hundred to a few thousand dimensions (for example, 384, 768, or 1536), and the dimensionality is fixed by whichever embedding model produced the vector.

Yes. Storing embeddings alongside other columns in a database like DuckDB lets you combine a similarity ORDER BY with standard WHERE clauses, joins, and aggregations in a single query, rather than running vector search and metadata filtering as separate steps.