The Short Answer
What is a vector database?
A vector database stores embeddings: lists of numbers that represent the meaning of a piece of text, an image or another item. It finds the stored items whose numbers are closest to a query’s, which returns results that mean something similar even when they share no words. AI products use it to find the right passages to give a language model before it answers.
If you already run PostgreSQL and have fewer than a few million items, the pgvector extension is usually the simplest choice. A dedicated service such as Pinecone, Weaviate or Qdrant earns its place at larger scale or when search is the core of the product.
Read the transcript
Search for "cancel my plan" in most help centres. The article called "Ending your subscription" never appears. It shares no words with what you typed. A vector database fixes that. It stores meaning as lists of numbers, and finds the closest match. So do you need a special one? Here’s how it works. Split your content into chunks. Turn each into numbers. Turn the question into numbers too. Then return the nearest chunks. If you already run PostgreSQL, the pgvector extension is usually enough. A dedicated service earns its place at very large scale, or when search is the whole product. And the database is rarely why answers are poor. Chunking, clean content and permissions matter more. Start with the database you already run. Fix the content before the engine. The full guide is free at loomstrat.com.
How Semantic Search Works
- 1
Split the content
Documents are cut into chunks, often a few paragraphs each.
- 2
Create embeddings
An embedding model turns each chunk into a vector, typically several hundred to a few thousand numbers.
- 3
Store them
The vectors are saved with the original text and metadata such as source, date and permissions.
- 4
Embed the query
A user’s question is turned into a vector with the same model.
- 5
Find the nearest
The database returns the chunks whose vectors are closest to the question’s.
- 6
Use the results
The chunks are shown as search results or passed to a language model to write an answer.
Comparing a query with every stored vector is slow at scale, so databases use approximate indexes. The most common is HNSW, a graph-based method described in a 2016 paper by Malkov and Yashunin. It trades a small amount of accuracy for very large gains in speed.
The Main Options
| Option | What it is | Best for |
|---|---|---|
| pgvector | An open-source extension that adds vector columns and indexes to PostgreSQL | Teams already on PostgreSQL; keeping vectors next to the rest of the data |
| Pinecone | A fully managed, hosted vector database | Teams that want no infrastructure to run and expect large scale |
| Weaviate | An open-source vector database, self-hosted or managed | Built-in hybrid search and modules for embedding |
| Qdrant | An open-source vector database written in Rust, self-hosted or managed | Strong filtering and performance with self-hosting options |
| Search engines with vectors | Elasticsearch and OpenSearch with vector fields | Teams already running them for keyword search |
Product documentation: Pinecone, Weaviate, Qdrant.
How to Choose
- Start with what you run. One database is easier to back up, secure and keep consistent than two. pgvector lets you join vectors with users, permissions and records in a single query.
- Check your scale honestly. Most business products store thousands to low millions of chunks. That is well within what PostgreSQL handles.
- Filtering matters more than raw speed. Real queries are “similar documents this customer is allowed to see, from the last year”. Check how each option combines filters with vector search.
- Hybrid search usually wins. Combining keyword and vector search catches exact terms such as product codes that pure semantic search misses.
- Consider who operates it. A managed service costs more per month and saves engineering time. Self-hosting is cheaper to run and needs someone to look after it.
What Actually Determines Quality
The database is rarely why AI search gives poor answers. These matter more:
- Chunking. Chunks that cut a table in half or mix unrelated topics retrieve badly.
- Clean source content. Out-of-date or duplicated documents produce confident wrong answers.
- The embedding model. A model suited to your language and domain retrieves better. Changing it means re-embedding everything.
- Reranking. A second step that re-scores the top results with a more accurate model often gives a large improvement.
- Permissions. Filtering by what the user may see must happen in the query, not after it, or private content can leak into answers.
Measure retrieval with a fixed set of real questions and the passages that should come back; see our guide to LLM evaluation.
Costs
| Cost | Driver |
|---|---|
| Embedding | Charged per token when content is first embedded and when it changes |
| Storage | Number of vectors multiplied by their dimensions; larger models store more numbers per chunk |
| Queries | Managed services may charge per read and write; self-hosted cost is server capacity |
| Re-indexing | Changing the embedding model or chunking means embedding everything again |
Frequently Asked Questions
Do I need a vector database for RAG?
You need somewhere to store and search embeddings. For many projects that is a PostgreSQL table with pgvector rather than a separate product.
Is pgvector good enough for production?
For most business applications, yes. It supports approximate indexes and keeps vectors alongside your other data. Very large or search-centric products may benefit from a dedicated engine.
What is an embedding?
A list of numbers produced by a model to represent meaning. Items with similar meaning have similar numbers.
What is hybrid search?
Combining traditional keyword search with vector search, so results match both exact terms and meaning.
Can I switch vector databases later?
Yes, if you keep the original text. You re-embed or export vectors and load them into the new store. Keep your retrieval code behind a simple interface to make this easier.