A vector database stores high-dimensional numeric representations of data — embeddings — and enables fast similarity search to find semantically similar content. This guide explains how vector databases work, why they are central to modern AI applications, and how they compare to traditional databases and search systems.
A vector database is a database system designed to store high-dimensional numeric vectors — called embeddings — and enable fast similarity search across them. Instead of querying for exact matches or range conditions (the query model for relational databases), a vector database returns the items most similar to a query vector according to a distance metric.
Vector databases have become central infrastructure for AI applications because modern machine learning models — particularly large language models and their embedding derivatives — represent the semantic meaning of text, images, and other data as vectors. Similarity search over these vectors enables semantic search, recommendation systems, retrieval-augmented generation (RAG), and duplicate detection at scales that traditional databases cannot handle efficiently.
What Embeddings Are
An embedding is a dense numeric vector that represents some piece of data in a way that captures semantic meaning. Two pieces of text with similar meaning will have similar embedding vectors — their vectors will be close together in the high-dimensional space, even if the words used are completely different.
For example:
- "What is the capital of France?" and "What city serves as France's national capital?" have similar embeddings, even though they share almost no words.
- "Paris" (the city) and "Berlin" (another European capital) have more similar embeddings than "Paris" and "banana."
Embedding models (such as OpenAI's text-embedding-ada-002, Anthropic's embeddings, or open-source models like Sentence-BERT) transform input text, images, or other data into these vectors, typically with 768, 1536, or 3072 dimensions.
The Core Operation: Approximate Nearest Neighbor Search
The fundamental query a vector database answers is: "given this query vector, find the N vectors in the database that are most similar (nearest) to it."
Exact nearest neighbor search — computing the distance between the query vector and every vector in the database — is too slow at scale. A database with 100 million embeddings at 1536 dimensions each cannot brute-force the distance calculation for every query.
Vector databases use **Approximate Nearest Neighbor (ANN)** algorithms to find the most similar vectors efficiently — trading a small amount of recall accuracy (occasionally missing a true nearest neighbor) for dramatically better query speed. The most common algorithms:
**HNSW (Hierarchical Navigable Small World)** — builds a multi-layer graph structure over vectors. Queries traverse from coarse layers to fine layers, pruning the search space at each step. High recall (typically above 95%), fast query times, and reasonable memory usage. The dominant algorithm in most production vector databases.
**IVF (Inverted File Index)** — clusters vectors using k-means, assigns each vector to a cluster, and at query time searches only the most relevant clusters. Fast, memory-efficient, slightly lower recall than HNSW.
**Product Quantization (PQ)** — compresses vectors into shorter codes by quantizing subvectors separately, reducing memory by 4-16x at the cost of some accuracy. Often combined with IVF for large-scale deployments where memory is a constraint.
Common Vector Databases
**Pinecone** — fully managed cloud vector database. No infrastructure to operate; API-based. Strong performance, automatic scaling, metadata filtering (combining vector similarity with attribute filters). The most commonly used managed vector database for production RAG applications.
**Weaviate** — open-source vector database with a managed cloud option. Supports multi-modal vectors (text, images, audio), built-in embedding generation, and a graph-like data model with object relationships. Strong for knowledge graph + vector hybrid use cases.
**Qdrant** — open-source vector database with efficient HNSW implementation, on-disk indexing for large datasets, and rich payload filtering. Written in Rust; good performance characteristics. Cloud managed option available.
**Milvus** — open-source vector database designed for large-scale deployment. Separated storage and compute architecture. Zilliz Cloud is the managed offering. Strong for very large vector collections.
**Chroma** — open-source, designed for simplicity and developer experience. Popular for prototyping and small-to-medium scale RAG applications. Can be embedded directly in a Python process or run as a standalone server.
**pgvector** — PostgreSQL extension that adds vector storage and similarity search to PostgreSQL. Enables storing embeddings alongside structured relational data without a separate system. Performance is acceptable for moderate scale (millions of vectors); for hundreds of millions of vectors, dedicated vector databases perform better.
**Snowflake Cortex, BigQuery, Databricks** — major cloud data platforms have added vector similarity search capabilities, enabling storing embeddings in the same system as analytical data. Convenient for analytics applications; purpose-built vector databases typically offer better performance for pure semantic search workloads.
Vector Databases and RAG
Retrieval-Augmented Generation (RAG) is the pattern that drove widespread vector database adoption in enterprise settings. The problem RAG solves: language models have a fixed knowledge cutoff and cannot access private organizational knowledge. RAG enables a language model to retrieve relevant context from an external knowledge base before generating a response.
The RAG architecture:
1. A knowledge base (documents, policies, product information, support tickets) is embedded into vectors and stored in a vector database
2. When a user submits a query, the query is also embedded
3. The vector database returns the most semantically similar documents to the query embedding
4. The retrieved documents are included in the language model's context window
5. The language model generates a response grounded in the retrieved documents, not just training data
The quality of a RAG system depends heavily on embedding quality, chunking strategy (how documents are split into embeddable units), and retrieval accuracy. The vector database is the retrieval component; its ANN implementation determines whether the most relevant documents are actually found.
Hybrid Search: Combining Vector and Keyword
Pure vector similarity search is excellent for semantic meaning but can miss exact keyword matches. A query for a specific product ID or technical term may be better served by traditional keyword (BM25) search than by semantic similarity.
Production search systems often combine both: vector search for semantic relevance, keyword search for exact term matching, with a reranking step that combines the two scores. Weaviate, Qdrant, Elasticsearch, and OpenSearch all support hybrid search with configurable weighting between vector and keyword results.
When You Need a Vector Database
Vector databases are appropriate when:
- Your application retrieves content based on semantic similarity rather than exact match (semantic search, RAG, recommendation systems)
- You are storing and querying embeddings generated by ML models
- Query volume and collection size make brute-force distance computation impractical
- You need metadata filtering alongside vector similarity (find the most similar documents that also match region = 'EMEA' and document_type = 'policy')
A vector database may be unnecessary when:
- Your collection is small enough that brute-force search is fast enough (pgvector handles millions of vectors adequately)
- Your application does not generate embeddings or perform semantic search
- Full-text keyword search (Elasticsearch, Solr, PostgreSQL full-text) is sufficient for your retrieval use case
Our data architecture practice designs AI-ready data infrastructure including vector search and RAG architectures — contact us to discuss your AI data platform requirements.
A former Microsoft data architect audits your data foundation, identifies your top priorities, and sends you a written plan. Free. No pitch.
Book a Call →