Vector Databases
A vector database stores high-dimensional embeddings and retrieves the nearest ones to a query vector, powering semantic search and retrieval-augmented generation.
Why vectors need their own store
Traditional databases index exact or ordered values: they answer equality and range queries efficiently. Machine-learning embeddings are dense vectors of floating-point numbers, often hundreds to thousands of dimensions, where meaning is encoded in geometric proximity. The query is not "find rows where x equals y" but "find the vectors closest to this one." A vector database is built around that similarity query.
Distance metrics
Closeness is defined by a metric. The three common choices are cosine similarity (angle between vectors, insensitive to magnitude), Euclidean distance (straight-line separation), and dot product (magnitude-sensitive). The metric must match how the embedding model was trained; using cosine on vectors trained for dot-product retrieval degrades quality.
The exact-search problem
Comparing a query against every stored vector is a brute-force scan: linear in the number of vectors and in the dimension. For a few thousand vectors this is fine. For hundreds of millions it is far too slow at query time. Vector databases therefore rely on approximate nearest neighbor (ANN) indexes that trade a small amount of recall for a large speedup.
Common index families
- HNSW: a navigable small-world graph you traverse greedily toward the query
- IVF: partition vectors into clusters, search only the nearest few clusters
- PQ: product quantization compresses vectors so more fit in memory
- Flat: exact brute force, used as a correctness baseline
What a vector DB adds beyond the index
A raw ANN library gives you the index. A vector database wraps it with persistence, filtering by scalar metadata (search only vectors tagged with a given source), incremental inserts and deletes, sharding across nodes, and consistency guarantees. The combination of a metadata filter with a similarity search, called hybrid filtering, is deceptively hard: filtering first can leave too few candidates for the ANN graph, so systems interleave the two.
In a technical knowledge base such as this library, embeddings of every page let a reader ask a question in natural language and retrieve the passages nearest in meaning, not just those sharing keywords. See embedding storage and ANN search.