LLMs & Retrieval-Augmented Generation
Vector databases and similarity search · 1/2

A database built for nearness, not exact matches

A vector database, such as Pinecone, Weaviate, or pgvector as a Postgres extension, is built to answer a fundamentally different question than a normal database. Instead of 'give me the row where id equals 42,' it answers 'give me the k stored vectors closest to this query vector.' Under the hood it stores millions of embeddings and needs to search them fast, and checking every single vector one by one, brute force, becomes too slow once you have millions of entries.

To make this fast, vector databases use approximate nearest neighbor, ANN, algorithms like HNSW, which build a navigable graph structure over the vectors so a search can skip most of the database and still find results that are nearly always the true closest matches. You trade a tiny bit of accuracy for a massive speedup, which is a good trade for almost every real application.