Embeddings & Vector Search
The mathematical trick that lets a computer judge whether two pieces of text mean similar things.
6.4.1Definition
An embedding is a numerical vector representation of a piece of text (or image, or audio), positioned in a high-dimensional space such that semantically similar content ends up near each other. Vector search finds the nearest embeddings to a query's embedding, surfacing content that means something similar — not just content that shares the same keywords.
6.4.2Why It Exists
Keyword search (5.12) fails when a query and a relevant document use different words for the same concept — "car" and "automobile" share no characters but mean nearly the same thing. Embeddings exist to capture meaning rather than exact word overlap, which is precisely what RAG's retrieval step (6.3) needs to find genuinely relevant chunks regardless of exact phrasing.
6.4.3Vector Database Options
| Option | Pattern | Best fit |
|---|---|---|
| Dedicated vector DB (Pinecone, Weaviate) | Purpose-built for large-scale similarity search | High-volume, production RAG systems |
| Postgres + pgvector | Vector search added to an existing relational database | Products already on Postgres (5.1) wanting to avoid a second system |
| In-memory / small-scale | Vectors held directly in application memory | Small, fixed document sets, prototypes |
6.4.4Common Mistakes
- Adopting a dedicated vector database for a small, fixed document set that an existing Postgres instance with pgvector would handle without adding a new system to operate.
- Mixing embedding models across an index — re-embedding new content with a different model than was used for existing entries, producing vectors that aren't comparable to each other.
- Ignoring embedding model versioning, so an upgrade to a newer embedding model silently breaks similarity comparisons against the old index.
6.4.5Best Practices
- Start with pgvector on an existing Postgres instance before adopting a dedicated vector database.
- Use a single, consistent embedding model across an entire index; re-embed everything on model upgrade rather than mixing versions.
- Combine vector search with traditional keyword filtering (hybrid search) where exact-match precision also matters.