## Definition A **vector database** is a storage and retrieval system optimised for high-dimensional dense vectors, supporting fast approximate nearest-neighbour (ANN) search. The persistence layer of [[Retrieval-Augmented Generation]] and most production [[Semantic Search]] systems. ## What It Stores - **Vectors.** Dense embeddings, typically 256–4096 dimensions. - **IDs.** Stable identifiers for the source items (document chunks, products, images). - **Metadata.** Filterable attributes (date, source, tenant, language, tags). - **Optionally the original text** or a pointer to it. ## The Core Operation Given a query vector $q$ and an index of vectors $\{v_i\}$, return the top-$k$ vectors with highest similarity to $q$ — typically cosine or dot product. Exact nearest-neighbour search is $O(n \cdot d)$ per query — too slow at scale. Vector databases use **ANN algorithms** that trade a small accuracy hit for sub-linear time. ## Common ANN Algorithms - **HNSW** (Hierarchical Navigable Small Worlds) — graph-based; current default for many vector DBs. Fast queries, slower index build. - **IVF** (Inverted File Index) — clusters vectors, searches only nearest clusters. - **PQ** (Product Quantisation) — compresses vectors for memory efficiency. - **DiskANN** — disk-resident variants of HNSW. ## Major Implementations (2026) | Type | Examples | | ------------------- | ------------------------------------------------- | | Dedicated services | Pinecone, Weaviate, Qdrant, Milvus, Vespa | | Postgres extensions | **pgvector** (dominant), Timescale, ParadeDB | | Search engines | Elasticsearch, OpenSearch (vector + BM25 hybrid) | | Lightweight / embedded | Chroma, LanceDB, FAISS, Sqlite-vss | | Cloud-native | Vertex AI Vector Search, Azure AI Search, AWS Kendra | For most teams in 2026, **pgvector** on the existing Postgres is the right starting point unless you've outgrown it (>10–100M vectors with strict latency budgets). ## Hybrid Search Pure vector search misses exact-match cases (product codes, names). Modern systems combine vector similarity with classical lexical search (BM25) and merge the rankings — see [[Semantic Search]]. ## Filtering and Metadata Two design choices, dramatic performance implications: - **Pre-filter then ANN** — filter metadata first, then search the remaining set. Right when filters are highly selective. - **ANN then post-filter** — ANN over the full set, filter results. Right when filters are loose. Most modern vector DBs support both and pick automatically. ## Related - [[Embedding]] - [[Retrieval-Augmented Generation]] - [[Semantic Search]] - [[Embedding-Based Retrieval]]