Vector DB
A vector DB is the component that stores embeddings and answers 'which vectors are closest to this one?' in milliseconds. It is where ANN (HNSW, IVF) pays the cost of semantic search.
What it is
A vector DB is a database specialized in storing dense vectors and answering neighborhood queries. The typical query is 'top-k nearest neighbors of this vector', and it runs at low latency even with millions or billions of indexed vectors.
Unlike a relational database, the primary index is geometric distance, not the primary key. Exact comparison (term, id) still exists, but the main search uses (ANN) algorithms, which give up the exact result in exchange for speed.
ANN: HNSW and IVF
Two algorithms dominate the state of practice. HNSW () builds a layered graph: each layer is a navigable graph, and vertices hop from layer to layer following the nearest neighbors. Search enters through the top layer, descends and converges. Excellent latency, high memory usage.
IVF (Inverted File Index) partitions the space into cells and stores, per cell, the vectors that belong to it. At search time, we compare the query vector with the centroids, pick the closest cells, and only then compare with the vectors in those cells. Less memory than HNSW, slightly higher latency. Most databases use IVF combined with quantization (PQ, SQ) to cut the cost even further.
Metadata and filters
A vector alone solves little. In production, each embedding comes with metadata: source document, date, author, category, tags, language, access level. The search combines 'nearest neighbors' with 'metadata filter'. Filters cut the search space before ANN runs, so they reduce latency and improve precision.
Two patterns stand out. Pre-filter: applies the metadata filter, and runs ANN over the subset. Post-filter: runs the full ANN, and discards what does not pass the filter. Pre-filter is better when the filter is restrictive; post-filter is better when almost everything passes.
In practice
pgvector is PostgreSQL's vector extension: it runs alongside the relational database and lets you filter metadata in the WHERE clause before the search. The example creates the table with a 1536-dimension vector (typical size for text-embedding-3-small), inserts chunks and runs a top-5 search with a category filter.
-- creation
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE chunks (
id BIGSERIAL,
doc_id TEXT NOT NULL,
category TEXT NOT NULL,
content TEXT NOT NULL,
embedding vector(1536),
PRIMARY KEY (id)
);
CREATE INDEX chunks_embedding_hnsw
ON chunks USING hnsw (embedding vector_cosine_ops);
CREATE INDEX chunks_category_idx ON chunks (category);
-- insertion (chunks with embeddings already computed in another step)
INSERT INTO chunks (doc_id, category, content, embedding)
VALUES ($1, $2, $3, $4);
-- top-5 search with metadata filter
SELECT id, doc_id, content,
1 - (embedding <=> $1::vector) AS score
FROM chunks
WHERE category = 'manual'
ORDER BY embedding <=> $1::vector
LIMIT 5;Strengths
- similarity search at scale: ANN delivers top-k in milliseconds with millions of vectors
- hybrid filtering: combines geometric neighborhood with SQL WHERE or a native filter, so searching by space is achievable
- options for every budget: pgvector saves additional infrastructure; Pinecone/Qdrant/Weaviate deliver dedicated throughput
Limitations
- ANN is approximate: ranking may swap true neighbors for near neighbors; tuning recall vs latency is ongoing work
- high memory: HNSW in high dimensionality consumes more RAM than the original data
- consistency between sharding and reindexing: rebuilding the index under real traffic demands care, and downtime becomes a production problem
connections on the map
- EmbeddingsstoresVector DB
- Vector DBqueriesRetrieval
updated on 14/10/2026 · sources to go deeper · report an error
in other domains
- KMS & crypto - keys and envelopescloudsecencrypt the index with a managed key
Study before
Unlocks
test what you learned
Loading questions…