Vector Databases Explained: When You Need One and How to Choose
What Is a Vector Database?
A vector database stores data as high-dimensional numerical arrays (vectors) and enables fast similarity search. Instead of matching exact values (like SQL), vector databases find items that are semantically similar.
How It Works
Step 1: Generate Embeddings
Text, images, or other data are converted into numerical vectors using an embedding model. Similar content produces similar vectors. For example, “dog” and “puppy” would have vectors that are close together, while “dog” and “spreadsheet” would be far apart.
Step 2: Store Vectors
The vectors are indexed in the database using algorithms optimized for high-dimensional similarity search (HNSW, IVF, etc.).
Step 3: Query
When you search, your query is converted to a vector, and the database finds the nearest stored vectors. This is called “semantic search” or “similarity search.”
When You Need One
For more on this topic, see our guide on The State of AI: What Developers Need to Know.
Yes: RAG (Retrieval-Augmented Generation)
The most common use case. Store your documents as vectors, then retrieve relevant context to send with your LLM prompt. This gives the LLM access to your private data without fine-tuning.
Yes: Recommendation Systems
“Users who liked X also liked Y” is fundamentally a similarity search problem.
Yes: Image or Audio Search
Find visually similar images or acoustically similar audio clips.
No: Exact Matching
If you need exact keyword matching, full-text search (Elasticsearch, PostgreSQL FTS) is faster and simpler.
No: Small Datasets
If your dataset is under 10,000 items, you can compute similarity in memory without a specialized database.
Comparison
| Database | Hosting | Cost | Best For |
|---|---|---|---|
| Pinecone | Managed cloud | $$$ | Production RAG, zero ops |
| Weaviate | Self-hosted or cloud | $-$$ | Hybrid search (vector + keyword) |
| ChromaDB | Self-hosted | Free | Prototyping, local dev |
| pgvector | PostgreSQL extension | Free | Adding vectors to existing Postgres |
| Qdrant | Self-hosted or cloud | $-$$ | Performance-critical applications |
The Practical Recommendation
- Prototyping: ChromaDB (pip install, zero config)
- Already using PostgreSQL: pgvector (just an extension)
- Production with minimal ops: Pinecone
- Full control: Weaviate or Qdrant self-hosted