Architecture
What is a vector database, and does your startup need one?
Every AI feature that "searches by meaning" (support bots, semantic search, recommendations, RAG) eventually hits the same question: where do the vectors go? Vendors would like the answer to be a new database. For most startups, the honest answer is "probably the one you already have".
This post explains what a vector database actually does, how it finds similar items quickly, and how to decide whether you need a dedicated one.
Vectors in one paragraph
An embedding model turns a piece of content (a sentence, a product description, an image) into a list of numbers, typically a few hundred to a few thousand of them. That list is a vector. The useful property is that content with similar meaning ends up with vectors that point in similar directions. "How do I get a refund?" and "Can I return this and get my money back?" share almost no words, but their vectors sit close together.
Once everything is a vector, "find related content" becomes "find the nearest points", which is a maths problem a database can solve.
What a vector database actually does
A vector database stores those vectors alongside the original content and metadata, and answers one core query fast:
Given this query vector, return the k stored vectors closest to it, optionally filtered by metadata.
"Closest" is measured with a distance metric:
| Metric | What it measures | Typical use |
|---|---|---|
| Cosine distance | Angle between vectors, ignoring length | Text embeddings (the usual default) |
| Dot product | Angle and length together | Embeddings normalised to length 1; some recommendation models |
| Euclidean (L2) | Straight-line distance | Image and other non-text embeddings |
Use whatever metric your embedding model's documentation recommends. Mixing them up does not throw an error; it just quietly returns worse results.
How it stays fast: approximate search
Comparing a query against every stored vector is exact but slow once you have millions of rows. So vector databases build an approximate nearest neighbour (ANN) index that trades a little accuracy for a lot of speed. The two you will meet most often:
- HNSW (Hierarchical Navigable Small World): builds a layered graph of neighbours and hops through it towards the query. Fast, accurate queries; uses more memory and takes longer to build.
- IVF (inverted file): groups vectors into clusters and only searches the clusters nearest the query. Lighter to build; accuracy depends on how many clusters you search.
The accuracy measure here is recall: of the true nearest neighbours, how many did the index return? Both index types have settings that trade recall against speed, and the defaults are a reasonable starting point.
You can start in Postgres
If your app already runs on Postgres, the pgvector extension adds a vector column type, distance operators and both HNSW and IVFFlat indexes. Your vectors live next to the rest of your data, in the same transactions and backups:
CREATE EXTENSION IF NOT EXISTS vector;
CREATE TABLE documents (
id bigserial PRIMARY KEY,
account_id bigint NOT NULL,
content text NOT NULL,
embedding vector(1536) NOT NULL -- match your embedding model's dimensions
);
-- Approximate index for cosine distance
CREATE INDEX ON documents USING hnsw (embedding vector_cosine_ops);
-- The 5 closest documents for one customer account ($1 = query vector)
SELECT id, content, embedding <=> $1 AS distance
FROM documents
WHERE account_id = $2
ORDER BY embedding <=> $1
LIMIT 5;
That last query is the whole trick: an ordinary SQL filter combined with "order by distance". No new service, no syncing data between two systems, and the access rules you already enforce in Postgres still apply.
Managed Postgres providers such as Neon, Supabase and AWS RDS support pgvector, so in most cases enabling it is one line.
When a dedicated vector database earns its place
Dedicated engines such as Pinecone, Qdrant, Weaviate and Milvus are built around this one workload. They are worth the extra moving part when you hit problems Postgres makes awkward:
- Scale: very large collections (think hundreds of millions of vectors) or high query volume where you want vector search to scale separately from your main database.
- Heavy filtering: many queries that combine vector search with selective metadata filters. Engines designed for this handle it more predictably than bolting a filter onto an ANN index.
- Built-in extras: hybrid keyword and vector search, multi-tenancy, quantisation to cut memory, or managed scaling you do not want to run yourself.
- Isolation: you do not want a burst of AI traffic competing with your transactional workload.
Search engines you may already run, such as Elasticsearch and OpenSearch, also support vector search, which can be a good middle ground if keyword search is already central to your product.
How to choose
| Your situation | Sensible starting point |
|---|---|
| Already on Postgres, up to a few million vectors | pgvector in your existing database |
| Need strong keyword search too | Postgres full-text search + pgvector, or a search engine with vector support |
| Very large collections or very high query volume | A dedicated vector database |
| Prototype or notebook experiment | Whatever is quickest to run locally; plan to move later |
The cost of starting simple is low. If you keep vector access behind one small module in your code, moving to a dedicated engine later is a contained piece of work, not a rewrite.
Mistakes we see often
- Choosing the database before the use case. Retrieval quality depends far more on clean data, sensible chunking and the right embedding model than on which database stores the vectors.
- Mixing embedding models. Vectors from different models (or different versions of one model) are not comparable. Store the model name with each vector and re-embed everything when you switch.
- Vector search alone for exact terms. Product codes, error messages and names are where keyword search wins. Combining both is usually best; we show a hybrid query in RAG for startups.
- Ignoring filtered results. With some index types, a query with a selective
WHEREclause can return fewer than k results. Test your real filters, not just unfiltered queries. - Not measuring recall. Keep a small set of queries with known correct answers and check them whenever you change the index, the model or the chunking.
The takeaway
A vector database finds things by meaning: embeddings in, nearest neighbours out, made fast by an approximate index. For most startups the right first step is pgvector in the Postgres you already run. Move to a dedicated engine when scale, filtering or operations give you a concrete reason, and keep the switch cheap by hiding vector access behind one module.
Deciding how to store embeddings for an AI feature? Talk to us about the right setup for your data and scale.