---
title: "What is a vector database and how does it work?"
description: "A vector database stores embeddings and returns the most similar ones with approximate nearest neighbor search. Learn how it works and how it compares to SQL."
type: "glossary-term"
canonical_url: "https://theaiengineering.com/glossary/vector-database"
markdown_url: "https://theaiengineering.com/glossary/vector-database.md"
topic: "RAG and vector search"
author: "The AI Engineering Editors"
publisher: "The AI Engineering"
updated: "2026-11-06"
keywords: ["Vector database","vector store","vector DB","vector search engine"]
citation: "The AI Engineering Editors. \"What is a vector database and how does it work?\" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/vector-database"
---

# What is a vector database and how does it work?

Also called vector store, vector DB, vector search engine.

> **Definition of Vector database:** A vector database is a database built to store embedding vectors and quickly return the vectors most similar to a query vector, usually with approximate nearest neighbor indexes such as HNSW.

A vector database is a database designed to store [embeddings](https://theaiengineering.com/glossary/embeddings) and answer similarity queries: given a query vector, return the stored vectors closest to it. Each record pairs a vector with an ID and metadata, such as the source document, a date, or access permissions. Vector databases are the usual retrieval layer in [retrieval-augmented generation](https://theaiengineering.com/glossary/retrieval-augmented-generation) systems.

## How a vector database works

A vector database works by building an [approximate nearest neighbor (ANN) index](https://theaiengineering.com/glossary/approximate-nearest-neighbor) over the stored vectors. ANN search gives up a small amount of recall in exchange for queries far faster than comparing the query with every stored vector. Common index types:

- **HNSW**: a layered proximity graph that search descends from coarse layers to fine ones. [Malkov and Yashunin](https://arxiv.org/abs/1603.09320) describe logarithmic complexity scaling for HNSW search.
- **IVF**: clusters vectors into lists and searches only the lists nearest the query.
- **Quantization**: compresses vectors, for example with product quantization, to cut memory use; it is often combined with IVF or HNSW.

A typical query embeds the user's text with the same model used for the documents, applies metadata filters, runs the ANN search with a distance metric (cosine, dot product, or Euclidean), and returns the top k results. Those results often pass to a [reranking](https://theaiengineering.com/glossary/reranking) step. Many vector databases also maintain keyword indexes to support [hybrid search](https://theaiengineering.com/glossary/hybrid-search).

## Vector database vs relational database

A relational database finds rows by exact matches and ranges on structured columns; a vector database finds records by similarity of meaning.

| | Relational database | Vector database |
|---|---|---|
| Query | SQL predicates and joins | Nearest neighbors of a vector |
| Match type | Exact or range | Approximate similarity |
| Typical index | B-tree, hash | HNSW, IVF, quantized indexes |

The line between the two is blurring. PostgreSQL's [pgvector](https://github.com/pgvector/pgvector) extension adds vector columns with exact search plus HNSW and IVFFlat indexes, so a team can keep vectors next to its relational data. Dedicated vector databases focus on larger indexes, higher query rates, and features such as filtered search and multi-tenancy.

The [vector databases directory](https://theaiengineering.com/platforms/vector-databases) lists options by type, and [What is RAG](https://theaiengineering.com/articles/what-is-rag) shows where the database fits in a pipeline.

## Related terms

- [Embeddings](https://theaiengineering.com/glossary/embeddings): Embeddings are fixed-length vectors of numbers that represent data such as text or images so that items with similar meaning sit close together, which lets software compare meaning with arithmetic.
- [Retrieval-augmented generation (RAG)](https://theaiengineering.com/glossary/retrieval-augmented-generation): Retrieval-augmented generation (RAG) is a technique that retrieves relevant passages from an external knowledge source at query time and adds them to a language model's prompt so the answer is grounded in that data.
- [Hybrid search](https://theaiengineering.com/glossary/hybrid-search): Hybrid search is a retrieval method that runs keyword search, typically BM25, and vector similarity search on the same query and merges the two ranked lists into one result set.
- [Reranking](https://theaiengineering.com/glossary/reranking): Reranking is a second retrieval stage that rescores an initial list of candidate documents with a more accurate but slower model, usually a cross-encoder, and keeps only the most relevant ones.
- [Semantic caching](https://theaiengineering.com/glossary/semantic-caching): Semantic caching is a technique that returns a stored LLM response when a new query is close in meaning to an earlier one, measured by embedding similarity instead of exact text match.
- [Approximate nearest neighbor search](https://theaiengineering.com/glossary/approximate-nearest-neighbor): Approximate nearest neighbor (ANN) search is a family of indexing methods that find vectors close to a query vector without comparing it to every stored vector, accepting that some true nearest neighbors are missed.
- [Cosine similarity](https://theaiengineering.com/glossary/cosine-similarity): Cosine similarity is a measure of how closely two vectors point in the same direction, computed as their dot product divided by the product of their lengths, with values from -1 to 1.

## Guides that cover vector database

- [What is retrieval-augmented generation (RAG)? How RAG works](https://theaiengineering.com/articles/what-is-rag): Retrieval-augmented generation (RAG) grounds LLM answers in your documents. Learn the RAG pipeline, hybrid search, agentic RAG, evaluation, and failure modes.
- [Semantic caching for LLMs: how it works and when it pays off](https://theaiengineering.com/articles/semantic-caching): Semantic caching returns a stored LLM response for prompts with similar meaning. Learn how a semantic cache works, how to tune it, and what never to cache.
- [Chunking strategies for RAG: how to choose, tune, and evaluate them](https://theaiengineering.com/articles/chunking-strategies-for-rag): Chunking strategies for RAG compared: fixed-size, recursive, document-aware, semantic, parent-child, and late chunking, with tested Python and an eval method.

Part of the [RAG and vector search](https://theaiengineering.com/topics/rag) topic hub.

## Cite this definition

The AI Engineering Editors. "What is a vector database and how does it work?" The AI Engineering, updated Nov 06, 2026. https://theaiengineering.com/glossary/vector-database

- Title: What is a vector database and how does it work?
- Author: The AI Engineering Editors
- Publisher: The AI Engineering
- Updated: 2026-11-06
- URL: https://theaiengineering.com/glossary/vector-database
- Markdown: https://theaiengineering.com/glossary/vector-database.md
