# What is a vector database?

> A vector database stores embeddings and returns the items closest in meaning to a query. It is the search index behind semantic search in RAG systems.

Canonical: https://promptlyfound.com/glossary/vector-database
Updated: 2026-11-20

## Short answer

A vector database is **a database that stores embeddings and returns the stored items closest in meaning to a query**. An application embeds each document or passage, stores the vectors, and at query time looks up the nearest ones. OpenAI recommends a vector database for searching many embeddings quickly, and RAG systems use one to find passages for a language model.

## Key findings

- OpenAI recommends a vector database for searching over many vectors quickly, and recommends cosine similarity as the distance function for its embeddings. [1]
- OpenAI's text-embedding-3-small model returns vectors of 1,536 numbers by default, and text-embedding-3-large returns 3,072. [1]
- pgvector runs exact nearest neighbor search by default. Its HNSW and IVFFlat indexes run approximate search, which trades some recall for speed. [3]
- In 2019, Microsoft said Bing had turned more than 150 billion pieces of indexed data into vectors, and released its vector search algorithm, SPTAG, as open source. [5]

Vector databases let AI search find passages by meaning, so a page can match a question even when it shares no words with it. Microsoft said in May 2019 that Bing had turned more than 150 billion pieces of indexed data into vectors.

A vector database stores embeddings, the lists of numbers that represent the meaning of a piece of text, and finds the stored items closest to a query. It is the index behind semantic search. Texts with similar meanings have vectors that sit close together, so the nearest vectors to a query belong to the most similar texts.

## How a vector database works

A vector search runs in two stages. First, an embedding model turns each document or passage into a vector, and the database stores it. [OpenAI's embeddings guide](https://developers.openai.com/api/docs/guides/embeddings) says its text-embedding-3-small model returns 1,536 numbers per text by default, and text-embedding-3-large returns 3,072. At query time, the application embeds the query with the same model and asks the database for the closest stored vectors.[1]

Closeness is measured with a distance function. OpenAI recommends cosine similarity. Its embeddings are normalized to length 1, so cosine similarity and Euclidean distance give the same ranking. For searching over many vectors quickly, OpenAI recommends a vector database.[1]

## Exact and approximate search

An exact search compares the query with every stored vector. [The pgvector documentation](https://github.com/pgvector/pgvector) says the PostgreSQL extension does this by default, which gives perfect recall. Adding an HNSW or IVFFlat index switches to approximate nearest neighbor search, which trades some recall for speed. Results can then differ from those before the index was added.[3]

HNSW comes from [a 2016 paper on Hierarchical Navigable Small World graphs](https://arxiv.org/abs/1603.09320). It builds layers of proximity graphs over the stored vectors and starts each search from the top layer, which the authors say allows logarithmic complexity scaling.[4]

## Vector databases in AI search

Retrieval-augmented generation uses a vector database to find passages for a model. [Anthropic's post on Contextual Retrieval](https://www.anthropic.com/news/contextual-retrieval) describes the steps: split documents into chunks, embed each chunk, store the embeddings in a vector database, and at query time add the most similar chunks to the prompt.[6] [OpenAI's retrieval guide](https://developers.openai.com/api/docs/guides/retrieval) calls its vector stores the containers that power semantic search for its file search tool.[2]

Web search engines use vector search at a larger scale. In May 2019, [Microsoft said](https://news.microsoft.com/source/features/ai/bing-vector-search) Bing had turned more than 150 billion pieces of indexed data into vectors, including words, page snippets and full queries. It released SPTAG, the algorithm Bing uses to search them, as open source.[5]

Anthropic's pipeline combines embedding search with BM25 keyword search, which finds chunks by exact matches.[6] pgvector supports the same kind of hybrid search by pairing vector search with PostgreSQL full-text search.[3] [What is semantic search?](https://promptlyfound.com/ai-search/semantic-search) covers hybrid search, and [What are vector embeddings?](https://promptlyfound.com/llms/embeddings) covers dimensions and similarity measures.

A search engine can only embed a page it has crawled and indexed. [How Google crawls and indexes pages](https://promptlyfound.com/crawlers/how-google-crawls-and-indexes) covers that step.

## Sources

1. Vector embeddings. OpenAI API documentation. https://developers.openai.com/api/docs/guides/embeddings
2. Retrieval. OpenAI API documentation. https://developers.openai.com/api/docs/guides/retrieval
3. pgvector: open-source vector similarity search for Postgres. pgvector (GitHub). https://github.com/pgvector/pgvector
4. Efficient and robust approximate nearest neighbor search using Hierarchical Navigable Small World graphs. arXiv, 2016-03-30. https://arxiv.org/abs/1603.09320
5. As search needs evolve, Microsoft makes AI tools for better search available to researchers and developers. Microsoft Source, 2019-05-15. https://news.microsoft.com/source/features/ai/bing-vector-search
6. Introducing Contextual Retrieval. Anthropic, 2024-09-19. https://www.anthropic.com/news/contextual-retrieval

---

This is a plain-text copy of https://promptlyfound.com/glossary/vector-database from Promptly Found. The web page is the canonical version and includes the charts.
