General

What is Vector Database?

A database optimized for storing embeddings and finding nearest neighbors by semantic similarity at scale.

Definition

A vector database indexes high-dimensional embedding vectors and answers approximate nearest-neighbor queries—"find the 10 items most similar to this one"—in milliseconds across millions of entries, using ANN algorithms like HNSW or IVF rather than exact scans. Similarity is measured by cosine or dot-product distance, typically with metadata filtering combined in the same query. Dedicated engines include Pinecone, Weaviate, Qdrant, and Milvus, while pgvector brings vector search into Postgres and many teams prefer that operational simplicity. Vector stores are the retrieval backbone of RAG systems, semantic search, recommendations, and deduplication pipelines. How does a vector database work? When you insert data, an embedding model such as OpenAI's text-embedding-3 or an open source sentence-transformers model turns each text chunk, image or product into a vector of a few hundred to a few thousand numbers. The database stores the vectors alongside metadata and builds an approximate nearest neighbour (ANN) index. HNSW (hierarchical navigable small world graphs) is the most common index and gives fast, accurate searches at the cost of memory; IVF indexes cluster vectors into lists and search only the nearest clusters; DiskANN-style indexes keep most of the graph on SSD to cut memory costs; and product quantization compresses vectors to fit more in RAM. At query time the search text is embedded with the same model, and the index returns the closest vectors by cosine similarity, dot product or Euclidean (L2) distance, usually combined with metadata filters such as tenant, language or date. Open source vector databases are a large part of the market. Milvus (Apache 2.0, a Linux Foundation AI and Data project) targets very large, distributed deployments; Qdrant (Apache 2.0, written in Rust) is known for fast filtering and a simple API; Weaviate (BSD-3) adds built-in vectorisation modules and hybrid search; Chroma (Apache 2.0) is popular for local prototyping and embedded use; and LanceDB (Apache 2.0) stores vectors in the columnar Lance format on local disk or object storage. FAISS, from Meta, is a widely used open source library for similarity search rather than a full database. Pinecone, by contrast, is a proprietary fully managed service. Postgres vector search is the other major option. The open source pgvector extension adds a vector column type, distance operators (<-> for L2 distance, <#> for negative inner product and <=> for cosine distance) and HNSW and IVFFlat indexes, plus halfvec and sparse vector types for smaller or sparse embeddings. Because embeddings live next to your relational data, you can filter, join and update them with ordinary SQL inside transactions, and you avoid running a second database. Extensions such as pgvectorscale add DiskANN-style indexing for larger datasets. Most managed Postgres services, including Amazon RDS and Aurora, Azure Database for PostgreSQL, Google Cloud SQL and AlloyDB, Supabase and Neon, support pgvector. Search engines and general databases have followed: Elasticsearch, OpenSearch, MongoDB Atlas, Redis, Azure Cosmos DB and Oracle Database all offer vector search, so a dedicated vector database is now one choice among several.

When to Use Vector Database

Start with what you already run. If your application uses PostgreSQL and you have up to a few million vectors, pgvector with an HNSW index is usually the simplest and cheapest choice: one database, transactional consistency, SQL filters and joins, and no new service to operate. Add a dedicated vector database when vector search becomes a core, high-scale workload: hundreds of millions of vectors, very high query rates, demanding filtered search, multi-tenant isolation at scale, or features such as built-in hybrid search and quantization that your general database lacks. Among open source vector databases, Qdrant and Weaviate are common choices for self-hosted production, Milvus for very large distributed deployments, and Chroma or LanceDB for local and embedded use; choose a managed service such as Pinecone, or the managed cloud editions of the open source engines, when you do not want to operate infrastructure. Whatever you pick, use the same embedding model for indexing and querying, store the model name and version with the vectors, measure recall and latency on your own data rather than vendor benchmarks, combine vector search with keyword (BM25) search for queries with exact terms such as product codes, and plan for re-embedding when you change models.

Vector Database in Practice

  • Postgres vector search with pgvector, from setup to query: CREATE EXTENSION IF NOT EXISTS vector; CREATE TABLE documents (id bigserial PRIMARY KEY, content text, embedding vector(1536)); CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops); SELECT id, content, 1 - (embedding <=> $1) AS similarity FROM documents ORDER BY embedding <=> $1 LIMIT 5; Here $1 is the query embedding passed as a parameter, <=> is cosine distance, and 1 minus the distance gives cosine similarity.
  • Filtering plus similarity in one SQL query, the main reason teams choose pgvector: SELECT id, title FROM articles WHERE tenant_id = 42 AND published = true ORDER BY embedding <=> $1 LIMIT 10;
  • Running an open source vector database locally with Docker, using Qdrant as an example: docker run -p 6333:6333 -v qdrant_data:/qdrant/storage qdrant/qdrant The REST API on port 6333 and the official Python, TypeScript, Go and Rust clients can then create a collection with a vector size and distance metric, upsert points with payload metadata and run filtered searches.
  • A RAG retrieval step: a support bot embeds the question 'How do I change my billing email?', queries the vector database for the five most similar help-centre chunks filtered by product = 'billing', and passes those chunks to the LLM as context so the answer cites current documentation.
  • Choosing an index: with 2 million 768-dimensional vectors, an HNSW index in memory gives the lowest latency, while a DiskANN or IVF-PQ style index trades a little recall for a much smaller memory footprint and lower hosting cost.

Common Mistakes

  • Adding a separate vector database for a small dataset when pgvector in the existing Postgres would be simpler and cheaper.
  • Mixing embeddings from different models or model versions in one index; distances between them are meaningless.
  • Expecting exact results from an approximate index. ANN indexes trade a little recall for speed, so tune parameters such as HNSW ef_search and measure recall.
  • Relying on vector search alone for queries with exact identifiers, names or codes, where keyword or hybrid search performs better.
  • Forgetting metadata filters and access control, which can leak another tenant's documents into a RAG answer.

Related Terms

Try it with a free tool

Keep the references coming

One email a week: new and trending developer tools, fresh comparisons, and what shipped. Unsubscribe in one click.