AI
Two vector stores, one embedding model
Pinecone in one project, pgvector in another, the same embedding model in both. The honest conclusion is not that one wins, it is that they fail in different places, and the filtering story that every comparison gets backwards.
Almost every comparison of vector stores is assembled from feature tables by somebody who has used one of them. The conclusion is always that the managed one is easier and the self hosted one is cheaper, which is true, uninteresting, and available on the vendor's own pricing page.
I have two systems in production using the same embedding model, text-embedding-3-small at 1536 dimensions, storing vectors in completely different places. That coincidence is useful, because it holds the one variable constant that usually muddies these comparisons. What is left is the difference between the stores, and the honest finding is that neither wins. They fail in different places, and one of those places is almost always described backwards.
The two systems
The first is the assistant on this portfolio. A few dozen hand written chunks in Pinecone, describing projects, skills and services. Retrieval is a single nearest-neighbour query over the whole index with no filtering, because there is nothing to filter by: every chunk is potentially relevant to every visitor.
The second retrieves from a large set of rule pages, chunked at the section level, in Postgres with the pgvector extension. Every query is scoped to an allowlist of page ids, because a given interview may only draw on a specific subset of the rules.
That second requirement, scoped retrieval, turns out to be the whole argument.
Filtering is the real difference, and it is buried in every comparison
Here is the query that scopes retrieval in the pgvector system:
SELECT page_id, title, LEFT(content, 4000) AS content
FROM rules_embeddings
WHERE page_id = ANY($2::text[])
ORDER BY embedding <=> $1::vector
LIMIT $3Look at what that single statement does. It restricts the candidate set to an arbitrary list of ids passed as a parameter. It selects only the columns needed. It truncates the content at four thousand characters so the row does not arrive larger than the context window can use. And it orders by cosine distance and takes the top few.
In a dedicated vector database, that same requirement is a product feature. Metadata filtering has its own syntax, its own rules about which types you may filter on, its own limits on how many values a filter may contain, and its own interaction with the approximate index that is doing the searching. It works, and it is a thing you have to learn, budget for and occasionally work around.
In Postgres it is a WHERE clause. It is the same WHERE clause you would write against any table, composable with anything else SQL can express, using indexes you already know how to reason about.
If your retrieval is naturally scoped by tenant, by permission, by category or by date, Postgres is doing natively what a dedicated vector store is working around. That is the single most useful thing I can tell you, and the feature tables consistently present it the other way up.
The corollary is worth stating too: the vectors live next to your real tables. You can join to them, filter on columns that belong to other entities, and write a row and its embedding inside one transaction. There is no window in which the record exists and its vector does not, which in a two-store architecture is a real class of bug and a real reconciliation job.
Things that are trivial in SQL and awkward otherwise
Once the vectors are in a relational database, a set of small problems stop being problems.
Truncating content at query time, as above, rather than fetching whole documents and cutting them in application code. Counting how many chunks exist for a given scope, which is one query rather than a paginated fetch. Ordinary indexes on ordinary columns for the non-vector parts of the predicate.
And a fallback path that would be genuinely annoying to build otherwise. When there is no search text to embed, the same system needs a representative sample of the corpus:
SELECT title, content
FROM rules_embeddings
WHERE page_id = ANY($1::text[])
ORDER BY random()
LIMIT 5Neither project has an ANN index, and that is correct
This is probably the most useful paragraph here, because everybody assumes an approximate index is mandatory and reaches for one before they need it.
The pgvector table has no IVFFlat or HNSW index. Every query is an exact scan: compute the distance to every candidate row, sort, take the top few. At a few thousand rows, restricted further by an allowlist, that is fast and it is always exactly right. There is no recall to tune because nothing is being approximated.
An approximate index trades accuracy for speed. If you add one before you have a speed problem, you have accepted a real cost, occasionally missing the best match, in exchange for nothing. Worse, you have added a structure that needs tuning, needs rebuilding as data changes, and behaves differently under filters than it does without them.
When it does become necessary, the two options differ in ways worth knowing in advance:
- IVFFlat builds quickly and uses little memory. It partitions the space into lists and searches a few of them, so it needs its list count set against your row count and its probe count tuned per query. Under a selective filter it can miss badly, because the rows that survive the filter may not be in the lists it probed.
- HNSW builds slower, uses considerably more memory, and generally gives better recall and better query latency. It has fewer knobs to get wrong at query time.
As a rule of thumb: below roughly ten thousand rows, do not bother. Between ten thousand and a hundred thousand, measure first and only add an index if the exact scan is actually showing up in your latency. Above that, reach for HNSW unless memory is genuinely tight. And whatever you do, measure recall against the exact answer before and after, because the whole point of the index is that it sometimes gets things wrong and you need to know how often.
Two update strategies, both defensible
This is where the projects genuinely diverge, and neither is wrong.
The pgvector system rebuilds. Every run empties the table and re-embeds everything:
await client.query('CREATE EXTENSION IF NOT EXISTS vector')
await client.query(`CREATE TABLE IF NOT EXISTS ${TABLE_NAME} (
...
embedding vector(${EMBEDDING_DIM})
)`)
await client.query(`DELETE FROM ${TABLE_NAME}`) // full rebuild, every timeThat guarantees the index exactly matches the source. Nothing stale can survive, because nothing survives. The cost is that every run pays to re-embed the entire corpus, so it does not scale to a corpus that changes constantly or is large enough for embedding cost to matter.
The Pinecone system upserts by id. Changed entries are cheap, unchanged ones are untouched, and a failed run can be resumed. The cost is an orphan: rename or remove an id and the old vector stays behind, still retrievable, still holding text you have since decided was wrong. It gets handed to the model as fact and there is nothing in your source tree pointing at it.
The decision rule I would use now: rebuild when your corpus is small and changes in batches, because the correctness guarantee is worth more than the embedding cost. Upsert when the corpus is large or changes continuously, and then accept that you owe yourself a reconciliation step that lists what is in the index and diffs it against what should be.
Retrieval is an enhancement, so let it fail
Every vector call in the pgvector project is wrapped so that failure returns nothing rather than throwing:
export async function searchRulesContext(searchText, limit = 10) {
try {
// ...embed, query, return rows
} catch {
return []
}
}A returned empty array means the feature carries on with no retrieved context. The answer is worse. The page still works.
That is the right shape for almost all retrieval. It is an enhancement to a feature, not the feature itself, and a database hiccup or an embedding API timeout should degrade the answer rather than produce a five hundred. The exception is a system where an unsourced answer is actively harmful, in which case failing loudly is correct, but you should have made that choice deliberately rather than by leaving the exception unhandled.
Operations, honestly
The part that does not show up in benchmarks and dominates the decision.
Managed means somebody else is awake at three in the morning, handles upgrades, and owns the capacity planning. You pay a subscription and you do not think about it again. Self hosted means backups, version upgrades, connection limits, disk, and monitoring are all yours, and vector workloads are memory hungry in ways that will surprise you if your Postgres experience is transactional.
But the marginal framing matters more than the absolute one. If you already run Postgres, already back it up, and already monitor it, then pgvector is an extension and a table. The incremental operational burden is close to zero. If you do not, you have just taken on a database to avoid a subscription, and that is a bad trade at almost any scale a subscription would cover.
One concrete detail from the self hosted side, because it is the sort of thing that bites during deployment rather than development: connection handling is yours to get right.
const pool = new Pool({
connectionString: process.env.PG_VECTOR_URL,
ssl: process.env.PG_VECTOR_URL?.includes('sslmode=require')
? { rejectUnauthorized: false }
: false,
})
export async function queryVector(text, params) {
const client = await pool.connect()
try {
return await client.query(text, params)
} finally {
client.release() // the finally is not optional
}
}A pool with a missing release in an error path exhausts itself and takes the feature down in a way that looks like a database problem and is not. The managed vector store has an HTTP client and none of this exists.
A decision rule instead of a winner
Reach for pgvector when the vectors belong beside relational data you already filter and join against, when retrieval is naturally scoped by tenant or permission or category, when you want a row and its embedding written in one transaction, and when you already operate Postgres.
Reach for the managed store when retrieval is a standalone concern with nothing to join to, when you do not want to own a database, when your corpus is large enough that index tuning would become a job, or when you would rather spend the subscription than the attention.
Both of my systems are on the right side of that rule, which is mostly luck rather than foresight. The portfolio assistant has nothing to filter by and nothing to join to, so the managed store costs it nothing. The rules system is scoped on every query and lives beside data it needs to reason about, so Postgres saves it a category of work it would otherwise have had to invent.
- Hold the embedding model constant when comparing stores, or you are measuring the wrong variable.
- Judge on filtering. Scoped retrieval is a WHERE clause in Postgres and a product feature everywhere else.
- Do not add an ANN index before you have a measured latency problem. Exact search is fast and always right at small scale.
- If you do add one, measure recall against the exact answer. That is the cost you are paying.
- Rebuild for small batch-updated corpora, upsert for large continuous ones, and reconcile if you upsert.
- Let retrieval fail quietly. It enhances a feature; it is not the feature.
- Judge the operational cost marginally. Adding an extension to a database you already run is not the same as adopting one.
The version of this article I could have written from documentation would have compared latency numbers and pricing tiers. Having shipped both, the thing I would actually tell someone choosing between them is that the question is not which store is faster. It is whether your retrieval has a WHERE clause in it. The chunking and follow-up handling on the Pinecone side is covered in a separate article.