Vector database

On this page 7

A vector database is a database system designed to store high-dimensional vectors, usually embeddings, and retrieve the vectors most similar to a query vector with low latency at large scale. Among database models, it is defined by its primary query: not exact matching on keys or values, but similarity search under a distance metric such as cosine distance or Euclidean distance.

Embeddings are numeric representations produced by machine learning models, in which semantically similar items lie close together. A vector database makes that geometry searchable, which is why it underpins semantic search, recommendation and retrieval-augmented generation. The capability exists both as dedicated products and as extensions of relational, document and search engines.

How a vector database finds similar items

A vector database finds similar items by computing distances between the query vector and stored vectors and returning the k closest, a k-nearest neighbor (k-NN) query. Exact search compares the query with every stored vector, which is precise but costs time proportional to the collection size and the dimension, typically 384 to 3,072 dimensions for modern text embeddings.

At millions or billions of vectors, exact search becomes too slow, so vector databases use approximate nearest neighbor (ANN) indexes. These indexes give up a small amount of recall, the share of true nearest neighbors returned, in exchange for answering in milliseconds. Recall of 0.90 to 0.99 is a common operating target, and it is tuned by index parameters at build and query time.

MetricWhat it measuresTypical use
Cosine distanceAngle between vectors, ignoring lengthText embeddings
Dot productAlignment including magnitudeNormalized embeddings, recommendation
Euclidean (L2) distanceStraight-line distanceImage and audio features
Hamming distanceDiffering bitsBinary quantized vectors
Distance metrics used in vector search

The metric must match how the embedding model was trained. Using Euclidean distance on embeddings meant for cosine similarity can noticeably reduce result quality, although for unit-length vectors the rankings of cosine, dot product and Euclidean distance coincide.

Approximate nearest neighbor index types

The index type determines a vector database’s speed, memory footprint, recall and update behavior. Most systems offer several, and the choice depends on data volume and hardware.

IndexMechanismStrengthWeakness
HNSWMulti-layer proximity graph navigated greedilyHigh recall at low latencyHigh memory use, slow builds
IVFVectors clustered; only nearby clusters searchedLower memory, fast buildsRecall depends on clusters probed
Product quantizationVectors compressed into short codesFits billions of vectors in memoryLossy distances reduce recall
Disk-based graphGraph index stored mostly on SSDLarge collections on modest RAMHigher latency than in-memory
Common ANN index families

Key tuning parameters include the graph degree and the search breadth in HNSW, often called M and ef, and the number of probed clusters in IVF. Raising them improves recall and increases latency and memory, so they are set by measuring recall against an exact baseline on a sample of real queries.

Vector database compared with other database models

A vector database differs from neighboring database models in what a query asks for: closeness in meaning rather than equality, structure or time order.

ModelCore queryTypical indexTypical workload
Vector databaseTop-k most similar vectorsHNSW, IVF, quantizationSemantic search, recommendations
Document databaseMatch fields in JSON documentsB-tree on fieldsApplication data, catalogs
Graph databaseTraverse relationshipsAdjacency structuresNetworks, fraud paths
Time-series databaseAggregate values over timeTime-partitioned columnsMetrics, sensor data
Relational with vector extensionSQL plus similarity operatorANN index beside B-treesModerate scale, joined filters
Vector databases and neighboring database models

Real applications rarely search vectors alone. Filtered vector search combines similarity with conditions such as tenant, language or date, and hybrid search merges vector results with keyword ranking. How well a system handles selective filters is often more decisive than its raw similarity speed.

Choosing and operating a vector database

The right setup depends on collection size, filter needs and update rate. Smaller collections rarely require a dedicated system.

SituationReasonable choiceReason
Up to a few million vectors, existing SQL dataVector extension in the current databaseOne system, transactional consistency
Hundreds of millions of vectorsDedicated distributed vector databaseSharded ANN indexes and replication
Strict memory budgetIVF with quantization or disk-based indexLower RAM per vector
Frequent deletes and updatesIndex with incremental updates and compactionAvoids recall decay from stale entries
Decision guide by situation

Memory planning is concrete arithmetic: a float32 vector of 1,536 dimensions occupies about 6 KB, so ten million such vectors need about 60 GB before index overhead. Quantization to 8-bit integers cuts this roughly fourfold, at some cost in accuracy.

Limitations and common mistakes

Vector search fails quietly: it always returns the nearest results, even when none of them is relevant. The usual mistakes follow from that property.

  • Mixing embeddings from different models or versions in one index, which makes distances meaningless.
  • Skipping a relevance threshold, so irrelevant neighbors reach users or language models.
  • Measuring speed without measuring recall, which hides poor result quality.
  • Embedding long documents whole instead of chunking them into passages.

The simple explanation

A vector database is a search engine for similarity. Instead of looking for exact words, it turns texts, pictures or products into lists of numbers. Things with similar meaning get similar numbers.

Imagine a huge map where every song is a dot. Songs that sound alike sit close together. When you ask for something like a given song, the database looks around that spot on the map and returns the nearest dots. It does this quickly, even with millions of songs.

How it is used in practice

A software company runs a support assistant over 400,000 help articles and resolved tickets. Each document is split into passages of a few hundred words and embedded into 768-dimensional vectors, about 2.5 million in total, stored in an HNSW index with filters for product and language.

When a customer asks a question, the system embeds it, retrieves the 20 most similar passages within the customer’s product, and passes them to a language model that drafts an answer. Queries return in about 30 milliseconds at a measured recall of 0.95. Because results below a similarity threshold are discarded, the assistant escalates to a human instead of answering when no relevant passage exists.