AI
Vector databases explained
Vector databases explained for founders: embeddings, similarity search, when pgvector inside PostgreSQL is enough, and when to reach for a dedicated store.
TL;DR
Similarity search over vectors is the engine behind AI-powered search and RAG. For most products, pgvector inside PostgreSQL handles it without adding a second system.

Similarity search over vectors is the mechanism behind AI-powered search. An embedding model converts text into a list of numbers, and retrieval means finding the stored numbers closest to your query's numbers. For most products, you do not need a dedicated vector database to do this well.
From text to vectors
An embedding is a list of numbers that encodes the meaning of a piece of text (or an image, or audio). An embedding model turns "cancel my subscription" and "how do I stop being billed" into vectors that land close together in high-dimensional space, even though the two phrases share almost no words.
That closeness is the whole mechanism. Meaning becomes geometry: similar concepts cluster near each other, and "find related content" becomes "find nearby vectors."
How similarity search works
Once your content is stored as vectors, retrieval follows a fixed sequence:
- Embed the user's query into a vector.
- Find the stored vectors closest to it, typically by cosine similarity.
- Return the content those nearest vectors belong to.
The challenge is doing step 2 fast at scale. Comparing a query vector against every stored vector is too slow for millions of records, so vector indexes use approximate nearest neighbor (ANN) algorithms that trade a small amount of accuracy for large speed gains. That trade-off is almost always acceptable in practice.
Start with pgvector
pgvector is a PostgreSQL extension that adds vector columns and ANN indexing inside your existing database. For most products with up to a few million vectors, it removes the need for a second system entirely.
If you already run Postgres (and with Supabase you do), that means:
- Joins between vectors and relational data in a single query, so you can filter by tenant, date, or category alongside similarity.
- One system to back up, secure, and operate.
- No sync layer between a separate vector store and your application database, which is a failure point you do not need.
The overhead of adding a dedicated vector service rarely pays off at early scale. pgvector is not a compromise here; it is the pragmatic right answer for the vast majority of products being built today.
When a dedicated vector store makes sense
Purpose-built vector databases earn their place under specific conditions:
- Tens or hundreds of millions of vectors where dedicated sharding and indexing architecture matter.
- Query throughput high enough to compete with your transactional workload on the same Postgres instance.
- Retrieval features (sophisticated hybrid search, complex payload filtering at scale) that a dedicated engine handles more naturally.
Even at that scale, keep your metadata in Postgres. Let the vector store handle similarity lookups, then join results back to your relational data for anything requiring business logic.
Retrieval quality matters more than the engine
The database choice is rarely what determines how good your RAG feature feels to users. A few factors move quality more than your infrastructure decision:
Embedding model fit. Use a model trained on content similar to yours, and use the same model for both indexing and querying. A mismatch here hurts more than any database choice.
Hybrid search. Combining vector similarity with keyword search (BM25 or full-text) means exact terms like product codes or proper nouns still surface even when semantic distance is high.
Pre-filtering. Apply tenant and permission filters before or alongside the similarity search. Post-filtering on access control is unreliable and should not be your enforcement layer.
Re-ranking. The top-k ANN results are candidates, not answers. A re-ranker pushes the most relevant context to the front before it reaches the LLM.
Start with pgvector, measure retrieval quality against real queries from your actual users, and revisit the infrastructure only when load or scale demands it. If you're building AI search or RAG and want accurate results without over-engineering the stack, let's talk.
Frequently asked questions
What is a vector database?
A vector database stores embeddings (lists of numbers that represent text or other content) and is optimised for similarity search: finding the stored vectors closest to a query vector. PostgreSQL with the pgvector extension can serve this role for most products without adding a dedicated system.
pgvector vs dedicated vector database: which should I use?
For most products with up to a few million vectors, pgvector inside PostgreSQL is sufficient and far simpler to operate. Dedicated vector databases are worth the added complexity at tens of millions of vectors or when similarity query throughput competes with your transactional workload.
How does vector similarity search work?
You embed a query into a vector, then find stored vectors closest to it by cosine similarity or dot product. At scale, approximate nearest neighbor (ANN) algorithms make this fast by accepting a small accuracy trade-off for large speed gains.
Do I need a vector database for RAG?
Not necessarily. pgvector inside PostgreSQL handles RAG retrieval well at typical product scales. A dedicated vector database is worth adding only if you have tens of millions of vectors, very high query throughput, or retrieval features that exceed what pgvector supports.
How Pykero can help
Services related to this article.
Building something like this?
Pykero Agency designs and ships production web, mobile, SaaS, and AI products.
Talk to us


