What Is a Vector Database and When Do You Need One?
What a vector database is, how vector search works, and how to tell whether your existing database is enough or a dedicated vector database is worth adding.
A vector database stores embeddings, numeric lists that represent the meaning of text, images or other data, and finds the most similar items quickly. It powers semantic search, recommendations and AI assistants that answer from your documents. If your data is small or you already use Postgres, MongoDB or a search engine, built-in vector search is often enough.
Photo: Unsplash
On this page
Your team wants an AI assistant that answers questions from your help center, contracts or product catalog. Someone says you need a vector database. Someone else says your existing database can do it. A vendor says you need their platform.
All 3 might be right, depending on your data and scale. This guide explains what a vector database is in plain English, how vector search works, and, most usefully, how to tell when a regular database is enough and when adding dedicated vector search is worth the cost and complexity.
A vector database in plain English
Traditional databases are great at exact matches. Find the order with ID 10472. List customers in Texas. Show invoices over $5,000. They also handle keyword search reasonably well.
They struggle with questions about meaning. A customer searches “how do I get my money back” and your help article is titled “Refund policy.” No keywords overlap, so a keyword search may miss it.
A vector database solves this by storing embeddings. An embedding is a list of numbers, often hundreds or thousands long, produced by an AI model to represent the meaning of a piece of content. Content with similar meaning gets similar numbers. “Get my money back” and “refund policy” end up close together, even though the words differ.
A vector database stores these embeddings and answers 1 core question very fast: which stored items are most similar to this one?
How vector search works
Most vector search follows the same steps:
- Create embeddings. Run each document, product description, image or chunk of text through an embedding model, which outputs a vector.
- Store them. Save each vector alongside the original content and useful metadata, such as title, date, department or access level.
- Embed the query. When a user searches, convert their query into a vector with the same model.
- Find the nearest neighbors. Compare the query vector to stored vectors using a distance measure such as cosine distance, and return the closest matches.
Exact vs approximate search
Comparing a query against every stored vector, called exact search, gives perfect results but slows down as your data grows. So most systems use approximate nearest neighbor (ANN) indexes, which trade a little accuracy for big speed gains.
The most widely used ANN method is HNSW, short for Hierarchical Navigable Small World graphs, described by Malkov and Yashunin in a 2016 paper. It organizes vectors in layered graphs so a search can hop quickly toward the closest matches. The pgvector documentation summarizes the trade-off well: without an index you get exact search with perfect recall; with an HNSW or IVFFlat index you get approximate search that is much faster but can return slightly different results.
Vector database vs regular database
| Regular database (SQL or document) | Vector database or vector search | |
|---|---|---|
| Best at | Exact lookups, filters, transactions, reports | Finding similar items by meaning |
| Query style | “Status = open AND region = West” | “Find passages most like this question” |
| Data stored | Rows, columns, documents | Embeddings plus content and metadata |
| Accuracy | Exact | Usually approximate, tunable |
| Typical uses | Orders, billing, inventory, CRM | Semantic search, RAG, recommendations, deduplication |
| Main cost driver | Storage and queries | Embedding generation, memory for indexes, compute |
The 2 are not rivals. Most real systems use both: the regular database holds the source of truth, and vector search helps find the right records by meaning.
When a regular database is enough
You often do not need a separate vector database. A regular database, or one with built-in vector features, is usually enough when:
- Your data is modest. Small and mid-sized document collections can often be handled by an extension or built-in vector search in a database you already run.
- Exact or keyword search already works. If users search by SKU, name, ID or specific terms, a standard index or full-text search may beat semantic search.
- Your database already supports vectors. PostgreSQL has the pgvector extension, MongoDB Atlas has Vector Search and search engines like Elasticsearch and OpenSearch support vector search. Keeping vectors next to your operational data simplifies permissions, backups and syncing.
- You need strict filtering. When results must respect customer, region or access rules, doing it in the same database as the rest of your data is easier to get right.
- You are prototyping. For a first RAG pilot, even exact search over a small set of embeddings can be fast enough.
pgvector, for example, supports cosine, inner product, L1 and L2 distance, offers HNSW and IVFFlat indexes and can combine vector search with Postgres full-text search for hybrid results. Its documentation notes indexing limits, such as up to 2,000 dimensions for the standard vector type, with half-precision vectors indexable up to 4,000.
When dedicated vector search is worth adding
A dedicated vector database, such as Pinecone, Weaviate, Milvus, Qdrant or Chroma, earns its place when:
- Scale is large. Very large vector collections or very high query volume can strain a general-purpose database.
- Latency is critical. Real-time recommendations or search across a large catalog need consistently fast responses.
- Data changes constantly. Heavy, continuous inserts and updates benefit from engines built to keep indexes fresh.
- You need advanced features. Multi-tenant isolation, built-in hybrid search and reranking, quantization to save memory or managed scaling can save engineering time.
- Search is a product in itself. If semantic search or recommendations are central to what you sell, specialized tooling is often worth it.
Key takeaway: Start with the database you already run if it supports vector search. Move to a dedicated vector database when measured scale, speed or feature needs justify another system to secure, sync and pay for.
Your options compared
| Option | Examples | Pros | Cons |
|---|---|---|---|
| Extension to an existing SQL database | pgvector for PostgreSQL | One system, familiar tooling, joins with business data | Tuning needed at large scale; shares resources with your app |
| Built-in vector search in a document database | MongoDB Atlas Vector Search | Vectors stored in the same documents, pre-filtering on fields | Tied to that platform’s limits and pricing |
| Search engine with vector support | Elasticsearch, OpenSearch | Strong keyword plus vector hybrid search, mature filtering | Another cluster to run if you don’t already have one |
| Dedicated vector database | Pinecone, Weaviate, Milvus, Qdrant, Chroma | Built for scale and speed, specialized features | Extra system to sync, secure and budget for |
Pricing varies widely by option and usage. Managed services typically charge based on storage, compute or query volume, while self-hosted options cost you infrastructure and staff time. Remember that generating embeddings is a separate cost, paid to an embedding model provider or in your own compute. Our guide to FinOps and cloud cost optimization covers how to keep these costs visible.
Common mistakes with vector search
- Treating it as a fix for bad content. If your documents are outdated or contradictory, better search just finds the wrong answer faster.
- Skipping keyword search. Product codes, names and exact phrases often work better with keyword search. Hybrid search combines both.
- Ignoring permissions. Filter results by user access before they reach an AI model, or the assistant may reveal documents a user should not see.
- Changing embedding models casually. Vectors from different models are not comparable. Switching models means re-embedding everything.
- Not measuring. Without a test set of real queries and expected results, you cannot tell whether tuning helped.
Where to start
- Define the use case. Semantic search, a document Q&A assistant, recommendations or duplicate detection each need different tuning.
- Check what you already have. If your current database or search engine supports vectors, start there.
- Prepare content. Clean documents, split them into sensible chunks and attach metadata like source, date and access level.
- Pick an embedding model and use the same one for content and queries.
- Build a test set of 30 to 50 real questions with the documents that should come back.
- Measure, then scale. Track result quality and latency. Move to a dedicated vector database only if the numbers say you need to.
If your goal is an AI assistant that answers from your documents, vector search is one piece of a larger pattern. Our explainer on retrieval-augmented generation covers the full picture, and our guide to what generative AI is explains the models on top. Teams building AI agents often use the same retrieval layer.
The bottom line
A vector database finds content by meaning instead of exact words, using embeddings and fast nearest-neighbor search. It is a key building block for semantic search, recommendations and AI assistants grounded in your data. For most businesses starting out, vector search inside a database you already run is enough. Add a dedicated vector database when your scale, speed or feature requirements prove you need one.
Sources
- pgvector on GitHub — distance metrics, HNSW and IVFFlat indexes, exact vs approximate search, dimension limits and hybrid search
- Malkov and Yashunin, HNSW paper (arXiv:1603.09320) — the Hierarchical Navigable Small World approximate nearest neighbor method
- MongoDB Atlas Vector Search overview — vectors stored with operational data, ANN with HNSW, pre-filtering and hybrid search
- Elastic Docs: kNN search — approximate and exact kNN search with filtering in Elasticsearch
Frequently asked questions
What is a vector database used for?
A vector database is used to find items that are similar in meaning. Common uses include semantic search on websites and help centers, AI assistants that answer questions from company documents, product recommendations, image similarity search and detecting duplicate content. It works by storing embeddings, numeric representations of content, and quickly finding the closest matches to a query.
Do I need a vector database for RAG?
Not necessarily a dedicated one. Retrieval-augmented generation needs some form of search, and vector search is common, but many teams use vector features in a database they already run, such as pgvector for PostgreSQL, MongoDB Atlas Vector Search or Elasticsearch. A dedicated vector database makes sense when scale, speed or advanced features require it.
What is the difference between a vector database and a regular database?
A regular database finds exact matches and filters, like an order ID or all customers in one state. A vector database finds items similar in meaning by comparing embeddings, which is useful for natural language questions and recommendations. Most systems use both, with the regular database as the source of truth and vector search to find relevant content.
What is an embedding in AI?
An embedding is a list of numbers that an AI model produces to represent the meaning of content, such as a sentence, document or image. Items with similar meanings get similar numbers, so a computer can measure how related they are. Embeddings are what vector databases store and search, and they power semantic search and many AI assistants.
Can PostgreSQL be used as a vector database?
Yes. With the open-source pgvector extension, PostgreSQL can store embeddings and run vector similarity search, including approximate search with HNSW or IVFFlat indexes. It can also combine vector results with Postgres full-text search. For many business applications, this is enough and avoids running a separate system, though very large workloads may need careful tuning.
How much does a vector database cost?
Costs vary widely. Managed vector databases typically charge based on storage, compute or query volume, while self-hosted options cost infrastructure and engineering time. Adding vector search to a database you already run can be the cheapest path. Remember to budget separately for creating embeddings, which you pay for through a model provider or your own compute.
Is a vector database the same as a search engine?
Not exactly. Traditional search engines rank results by keyword matching, while vector databases rank by similarity in meaning. The line is blurring: search engines such as Elasticsearch and OpenSearch now support vector search, and many vector databases support keyword filtering. Hybrid search, which combines both approaches, often gives the best results.
Was this guide useful
No reviews yet. Share your experience and help other readers.