AI glossary

Vector Database

A vector database is a database designed to store and efficiently search high-dimensional vectors, called embeddings, using similarity search rather than the exact-match queries used by traditional relational databases. It finds the stored items closest in meaning to a query, not just items that match it exactly.

Unlike traditional systems that rely on keywords or rigid schema structures, a vector database translates unstructured content into numeric representations. This allows systems to find items based on their underlying meaning and context, making it the backbone for modern semantic search and retrieval-augmented generation pipelines.

How similarity search works

The core function of a vector database revolves around how it handles data and queries. To store an item, such as a chunk of text, an image, or a product, the system first converts that content into a numeric vector. This process is typically produced by an embedding model. The database stores this vector alongside the original content or a reference to it.

When a user submits a query, that query is also converted into a vector. The database then calculates the distance or similarity between the query vector and all stored vectors. It uses measures such as cosine similarity or Euclidean distance to determine which stored items are closest to the query. The system returns the items with the highest similarity scores.

However, checking a query against every single stored vector individually, known as exact nearest-neighbor search, becomes too slow as datasets grow to millions or billions of records. To solve this, vector databases use approximate nearest-neighbor (ANN) search algorithms. These algorithms trade a small amount of accuracy for a massive improvement in search speed, allowing for real-time responses even at scale.

Indexing algorithms

To achieve the speed required for large-scale applications, vector databases rely on specific indexing algorithms. Two of the most common approaches are HNSW and IVF.

HNSW (Hierarchical Navigable Small World graphs) builds a multi-layered graph structure. This structure allows the search process to navigate quickly toward nearby vectors without checking every point in the dataset. It is currently one of the most widely used ANN algorithms in modern vector databases due to its balance of speed and recall.

IVF (inverted file index) takes a different approach. It partitions the vector space into clusters ahead of time. When a search is initiated, the system first identifies the most relevant clusters. It then searches only within those specific clusters, rather than scanning the entire dataset. This method is particularly effective for datasets with distinct clusters or varying densities.

Vector database vs relational database

Understanding the difference between a vector database and a traditional relational database is crucial for system architecture. A traditional relational database is optimized for exact-match and range queries over structured rows and columns. For example, it excels at queries like “find all orders placed after this date.” These systems use indexes like B-trees to organize data hierarchically.

A vector database is optimized for similarity queries over high-dimensional embeddings. It answers questions like “find the passages most similar in meaning to this query.” A relational database’s exact-match indexes are not designed to handle high-dimensional similarity searches efficiently.

It is worth noting that some general-purpose databases have added vector search as an extension. Examples include pgvector for PostgreSQL and vector search features added to Elasticsearch and OpenSearch. While these hybrid approaches are useful, purpose-built vector databases are often optimized specifically for the nuances of ANN search and vector storage.

Vector database examples

The ecosystem for vector databases includes both purpose-built solutions and extensions to existing systems. Purpose-built vector databases are designed from the ground up to handle high-dimensional vector data. Common examples include Pinecone, Weaviate, Milvus, Chroma, and Qdrant. These systems often offer specialized features for handling vector metadata, filtering, and scaling.

On the other hand, many existing databases have integrated vector capabilities to serve hybrid workloads. As mentioned, pgvector adds vector search to PostgreSQL. Similarly, Elasticsearch and OpenSearch have added vector search capabilities, allowing teams to manage both traditional text search and semantic search in a single infrastructure. This can simplify operations for teams that already rely on these platforms for their information retrieval needs.

When to use one

Deciding when to implement a vector database depends on the nature of your data and your application’s requirements. Vector databases are commonly used as the retrieval component in retrieval-augmented generation systems. In this context, they store embeddings of a document collection so that relevant passages can be retrieved for a large language model at query time. This helps ground LLM responses in specific, relevant data.

Beyond RAG, vector databases are ideal for semantic search applications. If you need to find results by meaning rather than an exact keyword match, a vector database is the right tool. They are also essential for recommendation systems, where the goal is to find items similar to ones a user has liked in the past. Additionally, they are effective for duplicate or near-duplicate detection, where subtle variations in content need to be identified across large datasets.

If your data is purely structured data with rigid relationships, a traditional relational database may still be more appropriate. However, as soon as you introduce unstructured data like text, images, or audio, and you need to find relationships based on similarity, a vector database becomes a critical component of your stack. The embedding process is the bridge that connects your raw data to these powerful search capabilities.

FAQ

What is a vector database used for?

Vector databases are primarily used for similarity searches, semantic search, and as the memory layer for AI applications like RAG. They allow systems to retrieve information based on meaning rather than exact keyword matches.

How is a vector database different from a regular database?

Regular databases use exact-match queries on structured data using indexes like B-trees. Vector databases use approximate nearest-neighbor algorithms to search for similar high-dimensional vectors, making them suitable for unstructured data like text and images.

Do I need a vector database for my LLM application?

If your application needs to ground responses in specific external data, you likely need a vector database. It serves as the retrieval engine that finds the most relevant context chunks to feed into the large language model.

Popular purpose-built vector databases include Pinecone, Weaviate, Milvus, Chroma, and Qdrant. Many traditional databases like PostgreSQL (via pgvector) and Elasticsearch also now support vector search.