Where should full-text search and vector search for AI features go?
Applications like this: site search, document search, semantic search, retrieval for a chat assistant. This page is written the way I write a database design doc: the workload first, then where each kind of data goes and why, then how it grows, what breaks, and what I rejected.
| Dimension | This application |
|---|---|
| Writes | Documents added and updated, each needing an embedding. |
| Reads | Queries by text and by similarity, often combined with filters. |
| Read to write | High. |
| Consistency | Loose. A new document can take seconds to become searchable. |
| Latency | Under a few hundred milliseconds, including the embedding of the query. |
| Growth | Moderate to large. Embeddings are big: hundreds to thousands of numbers per item. |
These incidents are why the choices below matter. Each one is written up with its numbers and sources.
Solid arrows: the application writes there. Dashed arrows: a copy fed from the source of truth (change data capture, an outbox, or a cache fill), which can be rebuilt from it.
| Data | Where it goes | Why |
|---|---|---|
| Documents and metadata | PostgreSQL | The record, permissions, and filters. |
| Embeddings, small to medium scale | pgvector in the same database | No second system, and filters and permissions are just SQL. |
| Large scale or advanced ranking | Elasticsearch or OpenSearch, or a vector database | Distributed indexes, hybrid text and vector ranking, more tuning knobs. |
How each family of store behaves under traffic: Database families.
CREATE EXTENSION IF NOT EXISTS vector; CREATE TABLE chunks ( id bigint PRIMARY KEY, doc_id bigint NOT NULL, tenant_id bigint NOT NULL, body text NOT NULL, embedding vector(1024) ); CREATE INDEX ON chunks USING hnsw (embedding vector_cosine_ops); SELECT id, body FROM chunks WHERE tenant_id = $1 ORDER BY embedding <=> $2 LIMIT 10;
Pick a stage, then throw something at it. The numbers are a model to show the shape of each change, not a measurement; the measured numbers are in the lab notebooks.
| What happens | What you see | What I do |
|---|---|---|
| HNSW index larger than memory | Latency jumps as the index pages come from disk | Size memory to the index, or reduce dimensions, or quantize. |
| Embeddings from mixed model versions | Results that quietly get worse | Record the model per row and re-embed in one pass. |
| Permission filters applied after search | Users see snippets of documents they cannot open | Filter inside the query. |
Cost. Embeddings are large. Count vectors times dimensions times bytes per number, then add the index, before picking a server.
| Stage | Where it runs |
|---|---|
| Where I would start | Managed PostgreSQL with pgvector |
| When it grows | A managed search or vector service once the index outgrows memory |
For a team without a dedicated database team. Who does which job in each option, and the full-cost comparison: Where to run the database.
The back-of-the-envelope numbers I would want before choosing anything. Move the assumptions to match your application. The link keeps your numbers, so a colleague sees the same ones.
Which database does my application need? What kind of application data goes in which database, and why, as design docs, plus the anti-patterns and the decisions behind them.