Dev tools
What Is a Vector Database? A Simple Guide
What is a vector database? A plain-language guide to vector embeddings, how vector search works, when you need one, and how to pick the right option.
A vector database is a database built to find things by meaning instead of by exact words. It stores information as lists of numbers that capture what text, images, or other data are about. Then it can instantly find the items most similar to a question, even when they share no keywords.
That makes vector databases a core part of many AI tools, from "chat with your documents" apps to smarter search and recommendations. This guide explains how they work in plain language, when you actually need one, and how to choose.
What Is a Vector Database in Simple Terms?
Imagine a library where books aren't sorted alphabetically but by what they're about. Cookbooks sit near other cookbooks. Books about baking bread sit closest of all to each other. A book on sourdough would be shelved right next to one on bread starters, even if their titles share no words.
Now imagine you walk in with a question, and the librarian instantly points to the five books closest to it in meaning.
That's what a vector database does. It places every piece of data at a position based on its meaning. When you search, it finds the nearest neighbors to your query.
A normal database is great at exact questions, like "find order number 1042" or "show customers in Berlin." A vector database answers fuzzy questions, like "find documents about refund problems," and returns results even if they say "money back" instead of "refund."
Vector Embeddings: The Numbers Behind Meaning
To place data by meaning, you first need to turn it into numbers. That's the job of vector embeddings.
An embedding is a long list of numbers, called a vector, produced by an AI model. The model reads a sentence, a paragraph, or an image, and outputs a vector that represents its meaning. Real embeddings often have hundreds or thousands of numbers each.
The useful property is this: things with similar meanings get similar vectors. "How do I reset my password?" and "I forgot my login details" end up close together. "Best pizza in Rome" ends up far away from both.
You can picture embeddings as points on a map. A real map has two dimensions, but embeddings have hundreds, which is impossible to draw but works the same way: distance means difference in meaning.
The vector database doesn't create the embeddings itself in most cases. You use an embedding model to create them, then store them in the database. Some tools, like Chroma, can handle that step for you.
How a Vector Database Works
A vector database does four main jobs.
1. Store vectors alongside your data
Each record holds the vector plus the original content, like the text chunk or a link to the image, and extra details called metadata. Metadata might include the author, date, category, or which customer the data belongs to.
2. Index them for speed
Comparing your query to every stored vector one by one is accurate, but slow once you have millions of items. So vector databases build an index that lets them jump straight to the right neighborhood.
Most use approximate nearest neighbor (ANN) search. Instead of guaranteeing the perfect top results, ANN finds results that are almost always the right ones, much faster.
A popular index type is HNSW (Hierarchical Navigable Small World). It builds layers of connections between vectors. A search starts on a sparse top layer to get close quickly, then drops down to denser layers to zero in on the nearest matches. It works much like zooming in on a map: country, then city, then street.
Another common type is IVF (inverted file index), which groups vectors into clusters and only searches the clusters closest to your query.
3. Search by similarity
When you search, your query is turned into an embedding with the same model. The database then measures how close it is to the stored vectors, using a distance measure such as:
- Cosine similarity: compares the direction of two vectors. It's the most common choice for text.
- Dot product (inner product): related to cosine, and popular with some embedding models.
- Euclidean (L2) distance: the straight-line distance between two points.
It returns the closest matches, usually the top handful.
4. Filter the results
Good vector databases let you combine meaning with rules. For example, you can find documents similar to this question, but only from the last year and only from the support team. This metadata filtering is essential in real apps, especially to keep each user's data separate.
What Is Vector Search Used For?
Vector search shows up in more places than you might think:
- RAG (retrieval-augmented generation): finding the most relevant document chunks to hand to an AI model before it answers. This is the most common reason people adopt a vector database today. Our guide to what RAG is explains the full process.
- Semantic search: search boxes that understand what you mean, not just what you typed.
- Recommendations: "similar products," "more like this," and related articles.
- Image and audio search: finding visually similar photos or matching songs.
- Duplicate detection: spotting near-identical support tickets, listings, or documents.
- Memory for AI assistants: recalling relevant past conversations or notes.
Why not just give the AI everything at once? Models can only read a limited amount of text per request, and sending more costs more and can make answers worse. Our guide to what a context window is explains that limit, including the "lost in the middle" problem. A vector database lets you send only the few pieces that matter.
Vector Database vs Traditional Database
| Traditional database | Vector database | |
|---|---|---|
| Finds | Exact matches | Similar meanings |
| Typical question | "Orders from customer 42" | "Tickets like this complaint" |
| Data shape | Rows and columns | Vectors plus metadata |
| Search style | Filters, keywords, joins | Nearest-neighbor similarity |
| Results | Exactly right or not at all | Ranked by closeness |
They're not rivals. Most real systems use both: a traditional database for accounts, orders, and records, and vector search for meaning-based lookups.
Keyword search still matters too. It's better at exact names, product codes, and rare terms. That's why many systems use hybrid search, combining keyword and vector results.
Do You Need a Dedicated Vector Database?
Not always. Here's a simple way to decide.
You might not need one if:
- You have a small amount of data, like a few hundred documents. A simple library or an in-memory index can be enough.
- You already use PostgreSQL. The pgvector extension adds vector storage and similarity search directly to Postgres. It supports exact search by default and approximate search with HNSW or IVFFlat indexes. You keep everything in one database.
- Your existing search engine or database already offers vector search. Elasticsearch, OpenSearch, MongoDB Atlas, and Redis all have vector features.
A dedicated vector database makes sense when:
- You have millions of vectors or more, and need fast search at that scale.
- Vector search is central to your product.
- You need advanced features like strong metadata filtering, hybrid search, or multi-tenant separation built in.
The Best Vector Database Options
There's no single best vector database. The right choice depends on your scale, your existing stack, and whether you want to run it yourself. Here are the main options.
Open-source vector databases
- Chroma: simple and developer-friendly, great for prototypes and small to mid-size projects. Licensed under Apache 2.0.
- Qdrant: fast and feature-rich, with strong filtering. Licensed under Apache 2.0.
- Milvus: built for very large scale. Licensed under Apache 2.0.
- Weaviate: includes built-in hybrid search and integrations with embedding models. Licensed mainly under BSD-3-Clause.
Most of these also offer paid managed cloud versions if you'd rather not run servers yourself.
Inside a database you already use
- pgvector: adds vectors to PostgreSQL, released under the PostgreSQL license. A strong default if you already use Postgres.
- Search engines and other databases: Elasticsearch, OpenSearch, MongoDB Atlas, and Redis offer vector search alongside their usual features.
Fully managed services
- Pinecone: a popular cloud-only vector database. There are no servers to manage, but it isn't open source.
Libraries, not databases
- FAISS: a library from Meta for fast similarity search, released under the MIT license. It's an engine, not a full database. You handle storage, updates, and filtering yourself.
Try It: A Tiny Example
Here's the quickest way to see vector search in action, using Chroma in Python. Install it with pip install chromadb, then run:
import chromadb
client = chromadb.Client() # in-memory, for experimenting
collection = client.create_collection("notes")
collection.add(
documents=[
"How to reset your password",
"Our refund and returns policy",
"Shipping times for international orders",
],
ids=["doc1", "doc2", "doc3"],
)
results = collection.query(
query_texts=["I want my money back"],
n_results=1,
)
print(results["documents"])Even though the query doesn't contain the word "refund," it should match the refund policy. Chroma creates the embeddings automatically with a default embedding model.
If you prefer to stay in PostgreSQL, the pgvector equivalent starts like this:
CREATE EXTENSION vector;
CREATE TABLE items (id bigserial PRIMARY KEY, embedding vector(3));A real table would use the vector size of your embedding model rather than 3.
Everything above can run on your own machine, without sending data to the cloud. Pair it with a local AI model for a fully private setup. Our guide to running an LLM locally shows how to set one up with Ollama or LM Studio.
FAQ
Do I need a vector database for RAG?
Not necessarily. Small projects can use a simple in-memory index or pgvector in an existing Postgres database. A dedicated vector database becomes useful as your documents grow into the millions or search speed becomes critical.
Is pgvector a vector database?
pgvector is an extension that turns PostgreSQL into a database that can store vectors and run similarity search. It isn't a separate product, but for many projects it does the same job as a dedicated vector database.
What is the best free vector database?
Chroma, Qdrant, Milvus, and Weaviate are all open source and free to run yourself, and pgvector is free for PostgreSQL users. Chroma is often the easiest place to start; Qdrant and Milvus suit larger production workloads.
What is the difference between a vector database and a graph database?
A vector database finds items with similar meaning based on their embeddings. A graph database stores explicit relationships between items, like "person A works at company B," and follows those connections. Some AI systems use both.
Can vector search work with images and audio?
Yes. Any data that an embedding model can turn into a vector can be searched this way, including images, audio, and video. Some models even put text and images on the same map, so you can search photos with a written description.