October 30, 2024

What is a vector database? Understanding vector databases for AI, ML, LLM, and other uses

See Liquibase in Action

Accelerate database changes, reduce failures, and enforce governance across your pipelines.

Watch a Demo

Table of contents

Vector databases have grown in popularity thanks to their usefulness for Large Language Models (LLMs), Machine Learning (ML), and Artificial Intelligence (AI) applications. With a different approach than traditional structured and relational databases, vector databases excel at AI-friendly tasks like semantic search and recommendations. 

A vector database stores its data as high-dimensional vectors. These vectors help give data context and relation rather than only distinct attributes. By breaking down the elements of a vector database, you’ll understand how they can enhance your development and data pipelines.  

What is a vector?

A vector is a way to turn complex data (like words, images, or sounds) into a structured list of numbers, with each number capturing a specific feature. Think of it as a digital fingerprint that encodes an item’s unique qualities. Whether it’s a product image, a document, or user interaction, nearly anything can be turned into a vector to simplify processing and searching.

This understanding and connecting of data attributes allows AI models to compare items based on similarity and make both broader and more nuanced conclusions. Vectors help make sense of unstructured data by finding relationships in meaning and context, critical for applications like recommendation systems and natural language processing.

Which leads right into data storage – a vector database is a data store specialized for this kind of retrieval. 

What is a vector database?

A vector database is built specifically for handling data represented as vectors: the lists of numbers that capture the important details of complex data like text, images, or video. 

These databases make it easier for machines to discover and understand related information based on meaning or similarity rather than just exact matches. 

This is a huge advantage for AI-powered systems, like recommendation engines or large language models (LLMs), which need to connect data to reflect context and subtle relationships. 

In addition to the concept of a vector itself, certain elements are foundational to vector databases: embeddings, similarity search, cosine similarity/distance metrics, and dimensionality reduction. 

What are embeddings?

Embeddings are vectors, but they’re a type specially designed by machine learning models to capture complex relationships within data. Think of embeddings as compressed, context-rich representations of high-dimensional information. 

For example, in natural language processing, an embedding for a word or sentence encodes not just the word itself but also its relationships to other words based on meaning. This allows systems to perform similarity searches based on context, not just surface-level features.

Embeddings are vectors optimized to capture the “essence” of data, making them foundational for AI tasks like search, recommendation, and language understanding.

What is similarity search?

This is where vector databases shine. Rather than looking for exact matches, they find data points that are similar to what’s being searched for based on their vectors. Instead of looking for identical matches, a similarity search finds entries that are “close” to the input based on certain features, like context or visual resemblance

So, if you search for an image of a shoe, the database will pull up other shoes, even if they don’t match exactly. This ability to retrieve contextually relevant items is crucial for AI-driven tasks like recommendation engines.

What is cosine similarity (and other distance metrics)?

Remember your trigonometry classes? Cosine similarity and other distance metrics are mathematical tools that measure how close two vectors are in high-dimensional space. These tools allow vector databases to quantify relationships, enabling precise results for similarity searches. 

Think of them as the numerical basis for deciding whether two items are meaningfully related.

Cosine similarity calculates the angle between vectors to determine their similarity, as if they were making one angle of a triangle. Vectors pointing in similar directions have a higher cosine similarity score. Additional metrics include:

  • Euclidean distance, measuring the straight-line distance between two vectors, commonly used for continuous data thathelps capture thosenuanced relationships
  • Manhattan distance, calculating the sum of absolute differences across dimensions, suitable for grid-based data
  • Hamming distance, counting the differing elements, often used with binary or categorical data
  • Jaccard similarity, measuring similarity between two sets, ideal for sparse data like document word frequencies
  • Minkowski distance, which flexes to generalize Euclidean and Manhattan distances, adjustable for various data types

These distance metrics enable vector databases to efficiently match related data points. But as vectors capture more features, they grow in size and complexity, which can slow down searches. That’s where dimensionality reduction comes in.

What is dimensionality reduction?

Data can have many dimensions (think features or characteristics). To speed things up and make the data easier to work with, dimensionality reduction reduce the number of features without losing the most important ones.

Approaches like principal component analysis (PCA), t-SNE, and others (below) compress data into fewer dimensions, maintaining its core characteristics. This helps vector databases perform similarity searches faster and more efficiently, especially as datasets grow larger.

t-SNE (t-distributed Stochastic Neighbor Embedding) projects high-dimensional data into two or three dimensions for visualization. It preserves the relative distances of similar data points, making it easier to see clusters and patterns in complex datasets. 

PCA (Principal Component Analysis) identifies the main directions where data varies the most. PCA transforms the data to align along these components, reducing the number of features while retaining as much information as possible. By looking at the most significant differences, PCA makes data more manageable for pattern recognition, visualization, and speeding up machine learning models.

UMAP (Uniform Manifold Approximation and Projection) reduces data into two or three dimensions for visualization, focusing on both local and global data structure. It’s faster than t-SNE and retains more of the overall data shape, making it ideal for larger datasets where structure matters.

Autoencoders are neural networks designed to compress and then reconstruct data. By learning to represent data efficiently, autoencoders capture complex, nonlinear relationships and are well-suited for very high-dimensional data.

LDA (Linear Discriminant Analysis) reduces dimensions by finding directions that best separate predefined classes. It’s often used in supervised learning, where the goal is to enhance class separation for better model performance.

When these concepts come together, they help vector databases do their best: find, compare, and retrieve complex information quickly and efficiently – especially compared to traditional databases. 

Vector databases vs traditional relational databases

Traditional relational databases (like MySQL or PostgreSQL) are great when storing and retrieving structured data with clear relationships, such as rows and columns of customer orders or inventory. 

However, when AI-driven applications need to analyze vast amounts of unstructured data (like text, images, or videos), relational databases fall short. They aren’t optimized for tasks requiring comparisons based on patterns or context—essential for AI applications like natural language processing and recommendation systems.

Vector databases, by contrast, are built for these modern AI tasks. They store data as vectors that capture complex relationships, making it easy to search by meaning, similarity, or context rather than exact matches. This makes them a better fit for AI workloads like semantic search, personalized recommendations, and context-driven analytics, where interpreting meaning and nuance is key.

Purpose-built for the complexities of AI/ML a vector databases works by reading between the rows and columns, so to speak. 

How do vector databases work?

Vector databases convert complex data like text, images, or other unstructured information into vectors, essentially lists of numbers. These vectors represent key features of the data in a high-dimensional space.

Vector databases work in essentially two stages. The first is creating embeddings within the database. 

Creating embeddings

When data enters a vector database, it’s passed through a machine-learning model that generates embeddings. These embeddings are vectors, where each dimension captures a particular data feature. 

For example, in natural language processing (NLP), words or sentences are converted into vectors based on their meanings, so similar words like “car” and “vehicle” end up with vectors close to each other in this space. Embeddings  allow the vector database to store relationships and similarities between data points rather than just the data itself.

Storing vectors

Once embeddings are created, they’re stored as vectors in the database, each representing unique data features. 

Unlike traditional databases that organize data in rows and columns, a vector database stores these high-dimensional vectors, capturing relationships between data points. This structure allows quick access to similar items, making the data accessible for tasks that depend on contextual relevance.

Querying vectors

When a query is run, it too is – you guessed it – transformed into a vector that captures the search’s essential features. 

The vector database then uses similarity search algorithms — such as cosine similarity or Euclidean distance — to find vectors closest to the query. This enables the database to retrieve items based on meaning rather than exact matches. This capability is essential for applications like semantic search, where interpreting “closeness” in meaning or appearance is key.

Implementing vector databases

Vector databases are a game-changer for businesses looking to scale their AI and machine learning projects. They’re designed to handle massive amounts of complex data, perfect for powering personalized recommendations, AI-driven search, and more.

When deciding on a vector database, there are several options, including open-source solutions like Milvus, Pinecone, and Weaviate. Each has its strengths. Some databases excel in scalability, and others in ease of integration. The key is to choose one that aligns with your project needs, whether dealing with AI search, recommendations, or managing large-scale data sets. 

As teams integrate vector databases and other innovative environments to support AI/ML capabilities, the next big challenge is to automate and unite data pipeline change management to keep pace with constant structural enhancements and evolutions. 

Share on:

See Liquibase in Action

Accelerate database changes, reduce failures, and enforce governance across your pipelines.

Watch a Demo