What is a vector database?

A vector database stores embeddings (lists of numbers that represent meaning) and quickly finds the ones closest to a query vector, using approximate nearest-neighbour indexes. It is the retrieval layer in most RAG systems.

Also called vector store, vector DB, vector search engineUpdated

An ordinary database answers exact questions: find order 9182, or every invoice after a date. A vector database answers a fuzzier one: which stored items are most similar to this one? It stores embeddings, arrays of a few hundred to a few thousand numbers that an embedding model produces from text, images or audio. Items with similar meaning end up close together, so "similar" becomes a distance calculation.

How it works

Distance. Vectors are compared with a metric such as cosine similarity, dot product or Euclidean distance. Use the one your embedding model was designed for.

Indexes. Comparing a query with every stored vector (exact search) is accurate but slow at millions of rows. Vector databases build approximate nearest-neighbour (ANN) indexes instead. The most common is HNSW (hierarchical navigable small world), a layered graph that the search walks from coarse to fine. IVF indexes cluster the vectors and search only the clusters nearest the query. ANN gives up a little recall for a large gain in speed, and you tune that balance with index parameters.

Filters and metadata. Each vector is stored with fields such as tenant, document type, language and access group. A good engine applies these filters during the search, so a query for one customer never returns another customer's data, and restrictive filters still return enough results.

Hybrid search. Many engines also keep a keyword index, so one query can combine meaning with exact matches on product codes, names or section numbers.

Example: retrieval for a support assistant

A SaaS company stores 400,000 help-centre chunks, each with a vector and metadata. A customer on the Pro plan asks "can I export invoices to Tally?". With PostgreSQL and the pgvector extension, retrieval is one query:

SELECT id, title, body
FROM help_chunks
WHERE plan_level <= 2          -- Pro and below
  AND language = 'en'
ORDER BY embedding <=> $1      -- cosine distance to the question's vector
LIMIT 5;

$1 is the embedding of the question, and <=> is pgvector's cosine distance operator. With an HNSW index on the embedding column, the query stays fast as the table grows. The five closest chunks go to the LLM as context, which is the retrieval step of retrieval-augmented generation.

Do you need a dedicated one?

"Vector database" covers three kinds of product:

  • Extensions to a database you already run, such as pgvector for PostgreSQL. Vectors sit next to the data they describe, and SQL filters and joins work as normal.
  • Dedicated vector engines, such as Qdrant, Milvus, Weaviate and Pinecone, built for very large indexes and heavy filtering.
  • Search engines with vector support, such as Elasticsearch, OpenSearch and Typesense, which suit product and site search with facets.

For most products with up to tens of millions of vectors, the extension route is simpler: one less system to secure, back up and keep in sync. A dedicated engine makes sense when vector search is a core, high-volume workload. Our comparison of pgvector vs Pinecone vs Qdrant covers scale, multi-tenancy and hosting in Indian regions.

Common mistakes

  • Mixing models in one index. Vectors from two embedding models live in different spaces. Changing the model means re-embedding everything.
  • Filtering after retrieval. It either leaks data or returns too few results.
  • Blaming the database for poor answers. Chunking, hybrid search and re-ranking usually matter more than the engine.
  • Forgetting deletes. When a source document is removed or a user asks for erasure, its vectors must go too.

We design retrieval layers on Postgres and dedicated engines as part of our data and AI work.

Any idea in mind? Let's make it real.

Tell us what you're building. You'll hear back from an engineer, not a sales team, usually within one working day.

Book a 30-min call