Vector Database
A database optimized for storing and querying high-dimensional vectors. Powers AI applications like semantic search and recommendation systems.
What is Vector Database?
In short
A vector database stores data as high-dimensional numeric vectors (embeddings) and finds the ones closest to a query vector using similarity math, so it answers "what is most like this?" instead of "what exactly matches this?". It is the storage layer behind semantic search, recommendations, and retrieval for AI systems like RAG chatbots.
What a vector database actually is
A vector database is built to store and search embeddings. An embedding is a list of numbers, often 384, 768, or 1,536 of them, produced by a model that turns text, an image, or audio into a point in high-dimensional space. Items that mean similar things land close together in that space, even when they share no words. The sentence "how do I reset my password" sits near "forgot my login" because the model placed them close, not because the strings overlap.
A normal database answers exact and range queries: find the row where email = x, or price between 10 and 20. A vector database answers a different question: given this query vector, return the k nearest vectors. Nearness is measured with cosine similarity or Euclidean distance. This is called k-nearest-neighbor (k-NN) search, and it is the core operation everything else is built on.
Most vector databases store more than the raw vector. Each record carries the original text or a reference to it, plus metadata like tenant ID, document source, or timestamp. That lets you combine similarity search with normal filters, for example "the 5 most similar paragraphs, but only from documents this user owns, written after January."
How search works under the hood
Comparing a query to every stored vector is exact but slow. With 100 million vectors of 768 dimensions, a brute-force scan touches tens of billions of floating-point operations per query, which is far too slow for an interactive app. So vector databases use Approximate Nearest Neighbor (ANN) indexes that trade a tiny bit of accuracy for huge speed gains.
The most common index is HNSW (Hierarchical Navigable Small World), a layered graph where each vector links to its near neighbors. A search starts at the top sparse layer, greedily hops toward the query, then drops into denser layers to refine. It typically reaches the right neighborhood in a few hundred comparisons instead of millions, giving sub-10ms queries with 95 to 99 percent recall. Other approaches include IVF (inverted file lists that cluster vectors and only scan nearby clusters) and product quantization, which compresses vectors to shrink memory.
Recall is the metric that matters: of the true top-k neighbors, how many did the index return? You tune index parameters like ef_search in HNSW or nprobe in IVF to slide between faster-but-fuzzier and slower-but-exact. Distance metric, vector dimension, and index type are usually fixed when a collection is created because changing them means rebuilding the whole index.
When to use one, and the trade-offs
Reach for a vector database when relevance is fuzzy and language varies: semantic search over docs, product or content recommendations, deduplication, image search by example, and Retrieval-Augmented Generation, where you fetch the most relevant chunks to feed an LLM as context. If your queries are exact lookups, joins, or aggregations, a regular SQL or document database is the right tool.
The big trade-offs are memory and accuracy. HNSW keeps the graph in RAM for speed, so a billion 768-dimension float32 vectors need roughly 3 TB before index overhead, which pushes teams toward quantization or disk-backed indexes. ANN also means results are approximate; you accept the occasional missed neighbor in exchange for speed, and you tune that balance per workload.
You do not always need a dedicated system. Postgres with the pgvector extension handles millions of vectors well and keeps your embeddings next to your relational data, which simplifies filtering and transactions. Dedicated engines like Pinecone, Milvus, Qdrant, or Weaviate earn their place at hundreds of millions of vectors, high query volume, or when you need built-in sharding and replication. A common pattern is hybrid search: blend vector similarity with traditional keyword (BM25) scoring so exact terms like product codes still rank correctly.
A concrete example: RAG support bot
Say you build a support assistant over 50,000 help articles. Offline, you split each article into ~500-token chunks, run every chunk through an embedding model, and store each resulting vector plus its text and article ID in the vector database. This is a one-time ingestion job that you re-run when content changes.
At query time a user asks "my card was charged twice." You embed that question into one vector, ask the database for the 5 nearest chunks filtered to the user's language, and get back the most relevant passages in a few milliseconds. You paste those passages into the LLM prompt as context and the model answers grounded in your real docs instead of guessing.
That retrieval step is what keeps the answer accurate and current. Update an article, re-embed its chunks, and the bot's answers change immediately, with no model retraining. The vector database is doing the heavy lifting of finding the right needle in the haystack.
Where it is used in production
Pinecone
Fully managed vector database used by many RAG and search products; you push embeddings and query by similarity with metadata filters, no index ops to run.
pgvector on PostgreSQL
Postgres extension that adds a vector column type and HNSW/IVFFlat indexes, letting teams keep embeddings beside relational data instead of running a separate system.
Spotify
Open-sourced Annoy, an ANN library that powers music recommendations by finding tracks whose embeddings sit closest to what you have been listening to.
OpenAI / ChatGPT retrieval
Embedding APIs (text-embedding-3) feed vector stores so assistants can retrieve relevant documents and answer grounded in private data.
Frequently asked questions
- What is the difference between a vector database and a regular database?
- A regular database answers exact and range queries (email = x, price < 20) using B-tree indexes. A vector database answers similarity queries (find the items most like this one) using nearest-neighbor search over embeddings. They solve different problems and are often used together.
- What is an embedding?
- An embedding is a fixed-length list of numbers, commonly 384 to 1,536 dimensions, produced by a model that maps text, images, or audio into a space where similar meanings end up close together. The vector database stores and searches these numbers.
- Do I need a dedicated vector database, or is pgvector enough?
- For up to a few million vectors with moderate query volume, pgvector on Postgres is usually enough and keeps everything in one system. Dedicated engines like Pinecone, Milvus, Qdrant, or Weaviate pay off at hundreds of millions of vectors, high throughput, or when you need built-in sharding and replication.
- What is HNSW and why is it used?
- HNSW (Hierarchical Navigable Small World) is a layered graph index for approximate nearest-neighbor search. It navigates from a sparse top layer down to dense layers, reaching the right neighbors in a few hundred comparisons instead of scanning everything, giving sub-10ms queries with 95 to 99 percent recall.
- What does approximate mean in approximate nearest neighbor search?
- It means the index may occasionally miss one of the true closest vectors in exchange for being far faster than scanning every record. You measure this with recall and tune parameters like ef_search or nprobe to balance speed against accuracy for your workload.
Learn Vector Database hands-on
This page explains the idea. The full lesson lets you step through the ring as servers join and leave, read the implementation, and check yourself with a quiz. It is one of 760+ lessons in the System Design Masterclass, from your first API call to distributed consensus. Eleven Foundation lessons are free, no signup. Lifetime access is ₹499 in India or $7.99 worldwide, one payment, no subscription.
Related lessons
Lessons that touch on Vector Database as part of a larger topic.
Vector Database
Databases built for AI, storing and searching high-dimensional embeddings that power semantic search, RAG, and recommendation engines
intermediate · database types storage
Vector Databases and Approximate Nearest Neighbor Search
How embeddings become searchable points in space, why exact nearest-neighbor search breaks at scale, and how ANN indexes like HNSW, IVF, and PQ make retrieval fast enough to serve
ml-advanced · llm genai ops
Design a RAG System at Scale
Design a production Retrieval-Augmented Generation system - vector databases, chunking strategies, retrieval pipelines, reranking, hybrid search, caching, evaluation, and cost management
capstone · capstone
Embedding Storage
How to efficiently store, manage, and serve high-dimensional embedding vectors at scale
intermediate · database types storage
RAG Caching and Cost: Semantic Cache, Embedding Reuse, and the Bill
RAG triples a chat bill through retrieved context. Cut it with a semantic cache, embedding reuse, and a reranker, without serving confidently wrong answers.
ml-intermediate · retrieval rag
See also
Related glossary terms you might want to look up next.
NoSQL
Databases that don't use traditional table-based relational models. Includes document stores, key-value, graph, and column-family databases.
Database
An organized collection of data that can be easily accessed, managed, and updated. The backbone of almost every application.
Index
A data structure that speeds up database lookups. Like the index at the back of a book that lets you jump to the right page instead of reading every page.
CAP Theorem
In a distributed system, you can only guarantee two of three: Consistency, Availability, and Partition tolerance. You must choose your trade-off.
Consensus
The process of getting multiple nodes in a distributed system to agree on a single value. The foundation of distributed databases and coordination services.
Paxos
A family of protocols for solving consensus in unreliable networks. Famously difficult to understand but mathematically proven correct.