---
title: "Vector database"
description: "A vector database stores high-dimensional numeric vectors (typically embeddings) and provides fast similarity search over them, powering use cases like semantic search and retrieval-augmented generation."
canonical: "https://motherduck.com/glossary/vector-database/"
related:
  - title: "Building Vector Search in DuckDB"
    url: "https://motherduck.com/blog/search-using-duckdb-part-1/"
  - title: "Vector Technologies for AI: Extending Your Existing Data Stack"
    url: "https://motherduck.com/blog/vector-technologies-ai-data-stack/"
  - title: "DuckLake | MotherDuck Docs"
    url: "https://motherduck.com/docs/concepts/ducklake/"
gated_asset:
  title: "DuckLake on MotherDuck"
  url: "https://motherduck.com/product/ducklake/"
---

# Vector database

> A vector database stores high-dimensional numeric vectors (typically embeddings) and provides fast similarity search over them, powering use cases like semantic search and retrieval-augmented generation.

## Overview

A vector database is a system optimized for storing dense numeric vectors — usually embeddings produced by a machine learning model — and answering nearest-neighbor queries: "which stored vectors are most similar to this query vector?" Because exact nearest-neighbor search is expensive at scale, most vector databases rely on approximate nearest-neighbor (ANN) index structures, such as HNSW (Hierarchical Navigable Small World graphs) or IVF, which trade a small amount of accuracy for large speedups. Purpose-built vector databases (like Pinecone, Weaviate, or Milvus) exist alongside vector search capabilities added to general-purpose databases.

<glossary-callout guide="ai-analytics-eval-field-guide" />

## Similarity metrics

Vector similarity is typically measured with cosine similarity, Euclidean (L2) distance, or dot/inner product, and the choice of metric should match how the embedding model was trained.

## Vector search in DuckDB

DuckDB supports vector similarity search through its `vss` extension, which adds an HNSW index type and built-in distance functions over DuckDB's native `ARRAY` (fixed-size) type.

```sql
INSTALL vss;
LOAD vss;

CREATE TABLE docs (id INTEGER, embedding FLOAT[384]);

CREATE INDEX docs_hnsw_idx ON docs
USING HNSW (embedding) WITH (metric = 'cosine');

SELECT id, array_cosine_similarity(embedding, [0.1, 0.2, ...]::FLOAT[384]) AS score
FROM docs
ORDER BY score DESC
LIMIT 10;
```

Built-in functions include `array_distance` (Euclidean), `array_cosine_similarity`, and `array_inner_product`. The HNSW index must fit entirely in memory, which makes DuckDB's vector search well suited to small-to-medium embedding sets queried locally, rather than the massive, horizontally-scaled indexes that dedicated vector database services target.

## Why it matters

Vector search underpins semantic search (finding conceptually similar text rather than exact keyword matches) and retrieval-augmented generation (RAG), where relevant document chunks are retrieved by embedding similarity before being passed to a language model as context.
