---
title: "Embeddings"
description: "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."
canonical: "https://motherduck.com/glossary/embeddings/"
related:
  - title: "Introducing the embedding() function: Semantic search made easy with SQL!"
    url: "https://motherduck.com/blog/sql-embeddings-for-semantic-meaning-in-text-and-rag/"
  - title: "EMBEDDING | MotherDuck Docs"
    url: "https://motherduck.com/docs/sql-reference/motherduck-sql-reference/ai-functions/embedding/"
  - title: "DuckLake Architecture Deep Dive: Catalog, Storage, Compute | MotherDuck"
    url: "https://motherduck.com/videos/ducklake-architecture-deep-dive/"
gated_asset:
  title: "DuckLake on MotherDuck"
  url: "https://motherduck.com/product/ducklake/"
---

# 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.

<glossary-callout video="interactive-data-apps-motherduck-dives" />

## 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.

```sql
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.
