Vector database
A database optimized for storing and searching embeddings (vectors) by similarity. Vector DBs find the 'nearest neighbors' — most similar items — in milliseconds. Used for RAG, semantic search, and recommendations. Examples: Pinecone, pgvector, Weaviate, Qdrant.
- RAG (retrieve docs for LLMs).
- Semantic search.
- Recommendation systems.
- Deduplication by similarity.
- Exact keyword search (use full-text search).
- Small datasets (scan is fine).
- When you need ACID transactions.
Definition
A vector database stores vectors (embeddings) with metadata and supports nearest-neighbor search — find the k most similar vectors to a query. Uses ANN (approximate nearest neighbor) algorithms (HNSW, IVF) for fast search at scale. Often adds filtering by metadata.
Why it exists
Standard databases can't efficiently search by semantic similarity. Vector DBs use specialized indexes (HNSW, IVF) to find similar vectors in milliseconds even with millions of items.
How it works
Insert: embed your data, store the vector + metadata. Query: embed the query, the DB finds nearest neighbors by cosine/L2 distance using an ANN index (HNSW graph, IVF clusters). Returns similar items with scores. Filter by metadata (e.g., category, date).
Scaling limits
ANN is approximate (recall vs speed tradeoff). Index build time. Memory usage (HNSW is memory-heavy). Sharding for very large scale. Cost of managed services.
Cost shape
Self-hosted (pgvector, Qdrant — free). Managed (Pinecone, Weaviate Cloud — pay per usage/storage).
Alternatives
- pgvector (PostgreSQL extension) — SQL + vectors in one DB, simpler, less specialized.
- Full-text search (Elasticsearch) — Keyword search, no semantic similarity.