Embeddings explained for app teams: search by meaning, not keywords
Embedding models turn text into vectors so apps can search, dedupe and recommend by meaning. How similarity works and how to store vectors in PostgreSQL with pgvector.
Keyword search fails exactly where users are least precise: they describe what they mean, not the words your content uses. Embeddings are the standard fix - they turn text (or images) into vectors of numbers positioned so that similar meanings land near each other, which lets an app search, cluster and recommend by meaning instead of by matching strings.
This guide explains what an embedding is, how similarity is measured, where embeddings earn their keep in real apps, and how to store and query them in PostgreSQL with pgvector. It follows OpenAI's embeddings guide and the pgvector documentation, checked on 19 November 2026.
What an embedding is
An embedding model converts an input - a sentence, a product description, a support ticket - into a fixed-length list of numbers. OpenAI's documentation describes its text embeddings as measuring the relatedness of text strings: inputs with similar meaning produce vectors that are close together, and unrelated inputs produce distant vectors. The model is trained for this property, so "how do I cancel" and "stop my subscription" end up near each other even though they share almost no words.
How similarity is measured
Once everything is a vector, "find the most relevant documents" becomes geometry. OpenAI's guide uses cosine similarity between the query vector and each document vector, returning the highest-scored documents; the distance between two vectors measures relatedness, with small distances suggesting high relatedness. In practice: embed your documents once, embed the user's query at request time, then ask the database for the nearest document vectors.
Where embeddings earn their keep
- Semantic search. The flagship use: search that answers "refund for a double charge" with the billing-policy page even if the word "refund" never appears in the query.
- Deduplication and clustering. Group near-identical tickets, reviews or listings before a human or a model processes them.
- Recommendations. Items whose descriptions embed near a user's history are candidate recommendations without a hand-built tagging system.
- Retrieval for AI features. Embeddings are the retrieval layer in most RAG designs - the model answers from documents your search pulled. See RAG explained for founders for the full pattern.
Storing vectors in PostgreSQL with pgvector
You do not need a separate vector database to start. pgvector adds a vector column type and similarity search to PostgreSQL, alongside your existing tables. The README documents two index types, and the trade-off is explicit:
- HNSW builds a multilayer graph. It has better query performance in the speed-recall trade-off, but slower build times and higher memory use. It can also be created on an empty table, since it has no training step.
- IVFFlat has faster build times and lower memory use, but lower query performance in the speed-recall trade-off, and it works best when built after the table has data, because its lists are trained from the existing vectors.
That choice is a tuning decision, not a permanent one: the same query syntax works with either, so you can benchmark with your real data and rebuild the index. Keep the measurement habit from database indexes explained - an index that looks right can still disappoint under your actual query mix.
Practical notes before you ship
- Embeddings are model-specific. Vectors from different models (or different versions) are not comparable. Re-embed the corpus when you change models.
- Chunking is a design decision. Whole documents embed poorly when they cover several topics; tiny fragments lose context. Test retrieval quality with real user questions.
- Stale vectors are silent. When content changes, its embedding must change too, or search results quietly rot.
- Embeddings can leak meaning. A vector is derived from its source text; store and scope embedding tables with the same care as the content itself.
Sources
- OpenAI platform documentation, vector embeddings guide: https://platform.openai.com/docs/guides/embeddings
- pgvector README, index types and trade-offs: https://github.com/pgvector/pgvector
Drafted with AI assistance from these sources. Embedding quality depends on your corpus and queries; evaluate retrieval on real examples before committing to a model, chunking strategy or index type.