RAG Systems1 code example
⚡ +100 XP

Vector Databases

1

What is a Vector Database?

A vector database stores high-dimensional embedding vectors and provides fast nearest-neighbor search. When you embed a query, the vector DB finds the stored vectors most similar to it — returning semantically related documents.

2

Similarity Metrics

Cosine Similarity: measures angle between vectors. Range [-1, 1]. Best for text (magnitude doesn't matter, direction does). Equivalent to dot product on L2-normalized vectors. Dot Product: fast, used when vectors are already normalized. Euclidean (L2) Distance: measures absolute distance. Good for image embeddings.

3

ANN — Approximate Nearest Neighbor

Exact nearest-neighbor search over millions of vectors is too slow (O(n·d)). ANN algorithms trade a tiny bit of accuracy for massive speed gains: HNSW (Hierarchical Navigable Small World): builds a multi-layer graph. Used in Weaviate, Qdrant, pgvector. IVF (Inverted File Index): clusters vectors, searches only relevant clusters. Used in FAISS. LSH (Locality Sensitive Hashing): hash-based bucketing. Fast but lower recall.

4

Vector DB Comparison

FAISS — Meta. In-memory. Best for: local development, prototyping, embedded use. Pinecone — Managed SaaS. Best for: production, serverless, no-ops. Weaviate — Open-source. Best for: hybrid search (vector + BM25), GraphQL API. Qdrant — Open-source, Rust. Best for: filtering, self-hosted production, speed. Chroma — Open-source. Best for: fast local dev, LangChain/LlamaIndex integration. pgvector — Postgres extension. Best for: existing Postgres stack, ACID compliance.

5

Production Vector DB with Qdrant

💡

Qdrant's filtering happens BEFORE vector search (pre-filtering), not after — much more efficient than post-filtering.

Finished reading? Mark it complete to earn your XP.