Databases
Vector Databases
How vector databases store embeddings and power similarity search for AI applications like semantic search and RAG.
- Vector DB
- AI
- Embeddings
What is a Vector Database?
A vector database stores data as high-dimensional numeric vectors (embeddings) and is optimized to answer one core question fast: “which vectors are most similar to this one?” This makes it the backbone of semantic search, recommendation systems, and Retrieval-Augmented Generation (RAG) for LLMs.
From Text to Vectors
An embedding model turns text (or images, audio) into a fixed-length list of numbers that captures its meaning — similar meanings land close together in that vector space.
Similarity Search Query
Distance Metrics
| metric | measures | typical use |
|---|---|---|
| Cosine similarity | Angle between vectors (ignores magnitude) | Text embeddings (most common default) |
| Euclidean (L2) | Straight-line distance | Image embeddings, general clustering |
| Dot product | Magnitude-sensitive similarity | Recommendation scoring |
Approximate Nearest Neighbor (ANN) Indexes
Scanning every vector for every query doesn’t scale. Vector databases use ANN indexes to find very likely nearest neighbors in a fraction of the time:
| index | idea | trade-off |
|---|---|---|
| HNSW | Navigable small-world graph of vectors | Fast + accurate; more memory |
| IVF | Clusters vectors into buckets, searches nearby buckets | Good speed/memory balance |
| PQ (Product Quantization) | Compresses vectors to save memory | Lower precision, huge memory savings |
Retrieval-Augmented Generation (RAG)
The most common real-world use case today: store document chunks as embeddings, retrieve the most relevant chunks for a user’s question, then feed them to an LLM as context — grounding the model’s answer in your own data instead of relying purely on what it memorized during training.
Popular Vector Databases
Pinecone, Weaviate, Milvus, Qdrant, and Chroma are purpose-built vector databases; PostgreSQL (via the pgvector extension), Elasticsearch, and MongoDB Atlas also added vector search on top of their existing engines — a useful option when you don’t want to run a separate database just for embeddings.