Skip to content

What is a Vector Database? And Why Are They Used for LLMs?

Vector databases have rapidly grown in popularity due to their ability to provide the long-term memory needed for today‘s powerful large language models (LLMs) like ChatGPT, GPT-3, and Codex. But what exactly are vector databases, and how do they work their magic? This comprehensive guide will dive deep into the vector tech powering the future of AI.

Vectors 101

Let‘s start from the beginning – what are vectors in machine learning and why do they matter?

A vector is simply an ordered array of numbers like [0.2, 0.5, 0.1, 0.9]. On their own, vectors seem trivial. However, some clever math allows these number arrays to represent complex semantic relationships.

Using techniques like word2vec or BERT, vectors can represent words, sentences, documents and more as dense number arrays. For example, a word like "cat" may become [0.2, 0.1, 0.4, 0.2]. The numbers themselves are random, but what matters is similarity in the number patterns.

Words with related meanings will have number arrays clustered closer together. This is thanks to cosine similarity, which measures the angle between two vectors. Small angles mean very aligned vectors, which translates to semantic similarity.

For example, "cat" and "dog" will have vectors near each other, while "cat" and "airplane" will be further apart. Machine learning models leverage these patterns.

Vector Clustering

Visualization of how semantically similar words cluster together in vectorspace.

This numeric representation of meaning is called an embedding. Embeddings are the particular application of vectors for capturing semantics and powering language models.

Why Vectors Matter for LLM Memory

While vectors already enable many machine learning applications, their ability to act as long-term memory is vital for large language models.

LLMs like ChatGPT contain up to 175 billion parameters. This gives them excellent comprehension and generation capacity. However, their memory is fleeting – they cannot recall facts or context beyond their training data.

This is where vector databases come in. Storing knowledge in vectors rather than model parameters maximizes retrieval speed and scalability. With a vector database, an LLM can simply query for related vectors to expand its context and memory.

As a result, vector databases unlock LLMs‘ true potential. Now they can leverage decades or centuries of human knowledge instead of their limited training.

LLM with Vector DB diagram

LLMs supercharged with long-term memory from vector databases

This long-term memory is the difference between a generic LLM and specialized AI assistants that are masterclass experts in specific domains. Vector databases enable the context and reasoning that makes LLMs truly intelligent.

Top Vector Database Options

There are a variety of existing vector databases optimized for machine learning applications. Here are some of the most popular options as of 2024:

Pinecone

Pinecone is one of the most widely used closed-source vector databases. It excels at lifting and shifting vector workloads with auto-scaling. Easy imports and management make it popular for production use.

Weaviate

Weaviate is an open-source vector database built on a modular architecture. It shines for scalability and semantic capabilities. The ability to store both vectors and schemas makes it flexible.

Milvus

Milvus is another highly scalable, open source vector database focused on robustness and performance. It leverages technologies like HNSW for targeted vector searches. Milvus is built in Go.

Qdrant

Qdrant is an ultra-fast open source vector database written fully in Rust. It supports advanced filtering and combines vectors with scalar data. The focus is on speed and reliability.

VexyDB

VexyDB is an SQL-based vector database that allows standard query languages. This simplifies integrations and management for developers used to relational systems.

Database Licence Language Key Characteristics
Pinecone Proprietary Python Managed cloud service, ease of use
Weaviate Open source Go Modular architecture, semantic search
Milvus Open source Go Performance, horizontal scaling
Qdrant Open source Rust Speed, advanced filters
VexyDB Open source C++ SQL integration, ACID compliance

This table compares the top characteristics of each vector database option.

Feeding Data to Vector Databases

Of course, a vector database is only as powerful as the data it contains. Most projects leverage web scraping to populate their vector stores with high-quality data.

Tools like Website Content Crawler provide turnkey web scraping tailored to LLM needs. WCC automatically removes website cruft, extracting only the core article text.

The cleaned text can be vectorized through embeddings and easily loaded into any vector database. This powers sentence searches, recommendations, and other semantic applications.

# Example embedding documents with sentence-transformers
from sentence_transformers import SentenceTransformer

model = SentenceTransformer(‘all-MiniLM-L6-v2‘)

docs = [
   "Jane loves to play football",
   "Football is a popular sport",
   ...
]

embeddings = model.encode(docs)

# Index to vector database
db.index(embeddings) 

This code demonstrates generating embeddings and indexing to the database. WCC and other web scrapers produce the raw docs for embedding.

Apify offers an integration that directly streams scraped data from their platform into Pinecone. With robust pipelines, fresh vectors can fuel LLMs daily.

However, updating vectors that already exist poses challenges. Mathematical similarity ensures new data doesn‘t override existing semantics. Partially rebuilding indices in batches helps absorb new info.

Regular embedding updates capture evolving real-world knowledge – a key advantage over static LLM training. For the best results, aim for a balanced ingest schedule that refreshes vectors but minimizes rebuild costs.

The Future of AI is Vectors

In summary, vector databases provide the long-term contextual memory to make large language models truly intelligent. While LLMs contain the computational power for generation and comprehension, vectors give them the external knowledge binding it all together.

Moving forward, expect vector databases to rapidly expand along with LLMs like GPT-4. An arms race is on to create the largest and highest-quality vector stores.

Pinecone and others are investing heavily in managed cloud infrastructure to support enterprise needs. Open source options like Weaviate aim to democratize access through flexible local deployments.

Vectors also power cardinality estimation, analytics, recommendations, and other data-heavy applications. Their versatility ensures vector adoption will only accelerate – especially as new in-memory databases unlock speed and scale.

The most exciting opportunities combine multiple techniques. For example, vector similarity search could re-rank outputs from a large neural net. Together, vectors and neural networks are greater than the sum of their parts.

Thankfully accessing these tools is increasingly easy with services like Anthropic and Cohere. Soon anyone can tap into vectors‘ potential to understand the world through the lens of an intelligent assistant.

Join the conversation

Your email address will not be published. Required fields are marked *