Semantic search without a new database
ToolGo Team Jun 17, 2025 5 min read
Before adopting a dedicated vector database, check whether the PostgreSQL you already run is enough.
The gap keyword search leaves
Keyword search fails when customers do not use your words. Someone types "shirt that does not wrinkle" and your catalogue says "easy care". Nothing matches, and the customer concludes you do not sell it.
Semantic search closes that gap by comparing meaning rather than characters. The instinct, on discovering this, is to add a dedicated vector database. For most product catalogues and document sets, that is a step you do not need, and skipping it buys you something specific.
Why pgvector rather than a separate store
Your vectors live in the same transaction as your data. When a product goes out of stock, one transaction updates the row and its embedding together. With a separate vector store you now own a sync problem, and stale vectors surface as a customer complaint rather than an error in a log.
One thing to operate. One backup, one set of credentials, one failover story, one place where access control already works.
You can already query it. Filtering, joining, ordering and paginating are things your team knows how to do in SQL. In a separate store, each of those is a new API and a new set of limitations.
Two decisions, made once
Which embedding model. This sets the dimension of your vectors and, more importantly, locks you in: changing the model means re-embedding every row, because vectors from different models are not comparable.
Store the model name and version next to the vector. This is the field everyone forgets and the one that saves you later. Without it, a half-finished re-embedding leaves you with two incompatible vector populations in one column and no way to tell them apart.
Indexing, and the thing people get wrong
Exact nearest-neighbour search β scanning every row β is fine at a surprisingly large size. Measure before you index, because an index you did not need is a rebuild you have to maintain.
When you do need one, the two choices behave differently. HNSW generally gives better recall at a given speed and costs more memory and build time. IVFFlat builds faster and uses less memory, and needs its list count tuned to your row count.
The point that matters more than the choice: approximate search is approximate. Recall is a parameter you are setting, often without realising. If you index and your results quietly get worse, that is not a bug, it is the setting. Measure recall against exact search on a sample before and after.
Hybrid search is not optional
Vector similarity is bad at exact tokens. A product code, a part number, an order reference, a surname β these are precisely the queries where the customer knows exactly what they want, and a pure vector search will return things that are merely similar.
Postgres has full-text search built in, so the keyword half costs you nothing extra. Run both, then merge the two ranked lists β a weighted score, or reciprocal rank fusion, which needs no tuning and is hard to beat as a starting point.
Any team that ships vector search alone will eventually get the bug report "I searched for the exact product code and it did not come up first".
Filtering before ranking
This is the single biggest practical advantage of keeping vectors in your database.
Language, product line, date range, tenant, permission β all of it is in the same table or one join away, so the filter is a WHERE clause applied before ranking. In a separate store you are either duplicating metadata into it and keeping that in sync, or retrieving broadly and filtering afterwards, which quietly breaks your result count.
Permissions deserve emphasis. Filtering by who is asking is a correctness requirement, not an optimisation. Doing it in SQL, next to the data, is how it stays correct.
Chunking matters more than the model
Split by meaning, not by character count. A chunk that ends mid-clause hands the model half a rule, and no amount of retrieval quality recovers from that.
Keep a little overlap so a sentence spanning a boundary is retrievable from both sides, and store the source document and position with every chunk so an answer can cite where it came from.
Keeping embeddings fresh
Decide where re-embedding is triggered and make it impossible to forget. A database trigger, or an explicit step in the same transaction that writes the row.
The failure to design for is silent staleness: the text changed, the vector did not, and search now returns results based on wording that no longer exists. Nothing errors. The symptom is a customer being told something that was true last month.
Measure retrieval on its own
When grounded answers are poor, teams blame the model. Usually it is the search.
Build a small labelled set β thirty queries with the documents that should come back β and measure whether the right passage is in the top five, independently of what any model then wrote. Teams that only measure the final answer cannot tell which half is broken.
A note on Vietnamese
Two things interact here. Postgres full-text search benefits from unaccenting, so that a query typed without diacritics still matches accented text β which matters because people type without diacritics constantly.
Vector search is more forgiving of this by nature, which is another argument for hybrid: the keyword half handles exact codes, the vector half handles the accentless, approximate, conversational query.
When you genuinely outgrow it
At large scale, with heavy concurrent writes to the index, or with specialised filtering a general database does not express well. You will know, because a specific query will be measurably slow and you will have the measurement to prove it.
Until then, the extra system is cost without benefit. EC Chatbot runs its document library on PostgreSQL with pgvector for exactly these reasons. On whether retrieval is the right approach at all, see RAG or fine-tuning. If you want it built, the AI service does that.
The short version
Keep vectors in Postgres so they update in the same transaction as the data and can be filtered by permission before ranking. Store the embedding model and version next to every vector. Do not index until you measure, and when you do, check recall against exact search. Run keyword and vector search together, because pure vector search fails on product codes. Chunk by meaning, keep the source position, and measure retrieval separately from generation.
Frequently asked questions
Do I need a dedicated vector database for semantic search?
Why does pure vector search fail on product codes?
Should I add an index to my pgvector table straight away?
What is the field people forget to store with an embedding?
Why does filtering before ranking matter so much?
ToolGo Team
Product & Engineering
We build practical SaaS tools and write about what we learn β from product decisions to technical deep-dives.



