Embeddings and Vector Databases Explained for Engineers Who Build Things
What embeddings actually are, why vector similarity search is so powerful, and how to choose and architect a vector database for production workloads. No fluff.
Every RAG system, semantic search engine, and recommendation system is built on the same foundation: embeddings. Understanding them deeply — not just using them — separates AI systems that work from ones that frustrate.
What an Embedding Actually Is
An embedding is a vector of floating-point numbers that represents the meaning of content — text, image, audio, or code. The key property: semantically similar content has geometrically similar vectors. “The dog ran across the field” and “A canine sprinted through the grass” produce vectors that are close together in the embedding space, even though they share no words.
Choosing Your Embedding Model
Not all embedding models are equal. OpenAI’s text-embedding-3-large is a strong general-purpose baseline. Cohere’s embed-v3 is competitive with native support for search-optimized embeddings. For code, dedicated code-embedding models will outperform general text embedders.
Choosing Your Vector Database
- Pinecone: Managed service, excellent developer experience, good query latency. Best for teams that want to not think about infrastructure.
- Weaviate: Open source, strong hybrid search (vector + keyword). Best for teams with infrastructure capacity.
- pgvector: PostgreSQL extension, free, performant up to ~1M vectors. Best for teams already on Postgres.
- Qdrant: Open source, excellent performance, strong filtering. Best for high-filter-selectivity workloads.
Production Considerations
Index freshness, recall vs latency tradeoffs (tune HNSW ef parameter), and chunking strategy all significantly affect retrieval quality. Experiment with your specific content before scaling.
Why Chunking Strategy Matters More Than Most Teams Realize
The decision of how to split documents into chunks before embedding them is consistently underweighted relative to its actual impact on retrieval quality. A chunk that’s too large dilutes the specific information a query is looking for among irrelevant surrounding context, reducing the precision of similarity search. A chunk that’s too small loses the surrounding context needed to make the retrieved content useful once it reaches the generation step. The naive approach of splitting by fixed character count, ignoring document structure entirely, is the single most common mistake in early-stage RAG implementations.
A more effective approach respects document structure — splitting at paragraph or section boundaries, keeping related content (a heading and its associated body text, a table and its caption) together rather than splitting them arbitrarily. For technical documentation specifically, chunk boundaries that align with semantic units (a single API endpoint description, one configuration parameter, one troubleshooting step) consistently outperform fixed-size chunking in production retrieval quality testing.
Hybrid Search: Why Vector Similarity Alone Often Isn’t Enough
Pure vector similarity search has a specific, well-documented weakness: it struggles with exact-match queries involving specific identifiers, codes, or technical terms that don’t carry strong semantic meaning on their own. A query for a specific error code, product SKU, or API parameter name often retrieves semantically related but practically useless results from pure vector search, because the embedding model has no strong signal that this specific alphanumeric string is the critical piece of information in the query. Hybrid search — combining vector similarity with traditional keyword-based search (typically BM25) and merging the results through a reranking step — addresses this directly and has become close to standard practice in production RAG systems handling technical content.
Reranking: The Underused Quality Lever
After initial retrieval returns a candidate set of documents, a reranking step that re-scores those candidates using a more computationally expensive but more accurate model can meaningfully improve final retrieval quality. The pattern is to use a fast, cheap method (vector similarity, hybrid search) to narrow a large corpus down to perhaps 50 to 100 candidates, then apply a more expensive cross-encoder reranking model to that smaller set to select the final 5 to 10 documents that actually go into the generation context. This two-stage approach gets the best of both worlds: the speed needed to search large corpora and the precision needed for high-quality final results, and it directly addresses many of the retrieval quality issues discussed in our analysis of fine-tuning versus RAG.
Choosing Embedding Dimensions: A Practical Tradeoff
Higher-dimensional embeddings generally capture more nuanced semantic information, but the relationship between dimension count and retrieval quality has diminishing returns, while storage and compute costs scale linearly with dimension count. For most production applications, the difference in retrieval quality between a 1536-dimension embedding and a 3072-dimension embedding from the same model family is smaller than the difference in storage and query cost would suggest is worthwhile. Benchmark your specific retrieval task before assuming higher dimensionality is automatically better — for many real-world corpora, a well-tuned smaller embedding model with good chunking and hybrid search outperforms a larger embedding model with naive implementation.
This article is part of our ongoing coverage of Artificial Intelligence. For related reading, see fine-tuning versus RAG and mitigating AI hallucinations.
Monitoring Retrieval Quality Over Time
Retrieval quality is not a static property you validate once at launch — it degrades as your underlying document corpus grows, changes, or drifts away from the distribution your embedding model was originally validated against. Building ongoing retrieval quality monitoring, sampling production queries and periodically scoring retrieval relevance against human judgment, catches this degradation before it becomes visible to end users as a noticeable decline in answer quality.