Text and image embeddings in Postgres, versus Algolia
On this page
I have put Algolia on more sites than any other search tool: agency Craft sites through the Scout plugin, two Statamic sites through Statamic's own Algolia driver, and a large hospital system's site through a crawler that feeds the index. Earlier this year the team moved one of that site's features, the related-locations block, off Algolia and back onto plain Craft queries, because the index was a second copy of data the CMS could already answer from. That experience plus a week of reading about embeddings has changed what I would reach for next. This is a design post, not a case study. I run MySQL everywhere today and nothing below is in production yet.
What a hosted index actually gives you
Algolia and Meilisearch are keyword engines with very good defaults: typo tolerance, prefix matching as you type, a ranking formula you can tune, facets, and a front-end library that makes an instant search box a one-day job. For a public site with a search box in the header that is a lot of value for not much code.
The cost is structural rather than financial. The index is a copy. Something has to push every create, update and delete into it, and when the push fails silently the search lies. The record is flat, so a hit is whatever you indexed, and any filtering that depends on who is asking has to be encoded into the record or into a secured API key with filters baked in. Index settings live in a dashboard, outside version control unless you script them. And the moment you need a join, a count or a permission check, you are back in the database anyway, with a list of object ids and a second query.
Keyword search without leaving Postgres
Postgres has had full-text search built in for years. A tsvector column, a GIN index on it, and ts_rank gives you stemmed keyword matching and ranking in one query. The pg_trgm extension adds trigram similarity, which covers the typo-tolerance case well enough for a catalog. For a few thousand products or a few hundred pages that is the whole feature, with no sync job and no second copy, and the WHERE clause can carry every other condition the page already needs.
That alone would have done for the related-locations block, and it is roughly what the Craft version ended up being.
Embeddings
The new part is semantic search. An embedding model turns a piece of text into a vector, a list of a few hundred or a few thousand numbers, such that texts with similar meaning land close together. "Something for a newborn" and "infant hygiene kit" share no keywords and sit next to each other in that space. The pgvector extension gives Postgres a vector column type, a cosine distance operator, <=>, and HNSW indexes so the nearest-neighbour query stays fast as the table grows.
SELECT id, title
FROM products
WHERE funding_source_id = :scope
ORDER BY embedding <=> :query_embedding
LIMIT 20;
That WHERE is the line that matters to me. My ordering portal shows each partner only the products their funding allows. With a hosted index that is a filtered secured key per funding source. In Postgres it is the same query scope the catalog page already uses, applied to a vector search. The search cannot leak a product the user is not allowed to see because it never left the table that enforces that.
The PHP side is small. The embedding is one HTTP call to a model provider at write time, stored in the column, and one more call at query time for the search string. The pgvector PHP package has an Eloquent cast so the column reads and writes as an array.
Images in the same space
Text embeddings are half of it. Multimodal models, the CLIP family and its successors, embed images and text into the same vector space. Embed every product photo once and a text query finds images with no alt text and no caption. Embed a query image and you get visually similar images back, which is the "find me more like this" feature every photo library wants and almost none have.
The place I would use this first is not a client site. It is my own footage and photo libraries, where the question is always "do I have a shot of a sunset over water" and the answer today is scrolling. The product-catalog version is the same code with a different table.
Hybrid, in one query
The honest ranking for a search box is neither pure keyword nor pure vector. Keyword search is precise when the user knows the term; vector search is forgiving when they do not. Reciprocal rank fusion combines the two ranked lists with a few lines of SQL, and because both lists come from the same database it is one query with the same joins and the same permission scope. A hosted index cannot do that fusion with your own vector results without you writing the merge in application code against two systems.
Where I would still pay for Algolia
A public marketing site with a header search, a client who wants to tune ranking in a dashboard, and no appetite for running Postgres. Instant typeahead over tens of thousands of records where the front-end library saves real time. Anywhere the search records are not in a database you control. Those are still good reasons, and Meilisearch is a fine self-hosted answer to the same brief.
For the sites I own, and for any app where search has to respect who is asking, the answer is shifting toward the database. Recent MySQL releases have a VECTOR type now too, but its indexing is limited and the tooling around pgvector is far ahead, which is enough to make my next Laravel app a Postgres app.
The short version
A hosted search index buys typo tolerance and a fast front end at the price of a second copy of your data that cannot join or authorise. Postgres with full-text search and pgvector gives keyword, semantic and image search in one query against the real rows, with the same scopes the rest of the app enforces. I have not shipped it yet. It is the next thing I build when a search box comes up.