Skip to content
Y
YAS.SH
AI Infrastructure

Vector Databases Explained: Embeddings, Indexes, and Retrieval

How vector databases work — embeddings, ANN indexes (HNSW, IVF), similarity search, and when you need one vs a simple index.

yas-team3 min readvector databaseembeddingsrag-architecture-patterns
Vector Databases Explained: Embeddings, Indexes, and Retrieval
Featured imageVector Databases Explained: Embeddings, Indexes, and Retrieval

Semantic search is the retrieval engine of the AI era — and it runs on vectors. This guide explains the stack honestly: what embeddings are, how approximate nearest-neighbor indexes work, and the decision of when you actually need a vector database at all.

Embeddings: text as coordinates

An embedding model converts text into a vector — typically 384 to 3,072 numbers — where semantic similarity maps to geometric proximity:

"cat"     → [0.12, -0.45, 0.88, ...]   (768 dims)
"kitten"  → [0.11, -0.44, 0.87, ...]   (close to "cat")
"invoice" → [-0.70, 0.21, 0.05, ...]   (far from both)

Similarity is measured as cosine distance (or dot product). The embeddings guide covers choosing and evaluating models; here the point is that vectors make "find things like this" a geometry problem.

The search problem

Naive search scans every vector and computes distance — fine for 10k chunks (~50ms), hopeless at 10M (~minutes). Vector databases solve this with approximate nearest neighbor (ANN) indexes, trading a tiny amount of recall for enormous speed.

HNSW: the default choice

HNSW (Hierarchical Navigable Small World) builds a multi-layer graph:

layer 3 (coarse):  few nodes, long jumps
layer 2:           more nodes, shorter jumps
layer 1 (fine):    all nodes, local hops

query: start at top, greedily descend — logarithmic search

The properties: millisecond searches at millions of vectors, high recall (95–99%), no training phase (insert-anytime), but memory-hungry (the graph lives in RAM). For most RAG systems, HNSW is the right default.

IVF: the memory-conscious alternative

IVF (Inverted File) clusters vectors at index time:

1. K-means over the corpus → K centroids
2. Each vector assigned to nearest centroid
3. Query: check nearest centroids first, then exact scan within them

IVF uses far less memory and scales to billions with quantization (PQ), at the cost of a training step and slightly lower recall. The choice: HNSW for accuracy-first systems, IVF-PQ for corpus-scale economics.

The real bottleneck: chunking and embeddings

A vector index makes retrieval fast; it can't make it good. Retrieval quality is decided upstream:

  1. Chunking — how documents are split (size, overlap, semantic boundaries) determines what "nearest" means. The RAG patterns guide covers chunk strategies.
  2. Embedding model — domain mismatch (general model on medical text) silently degrades everything.
  3. Hybrid retrieval — vector + keyword (BM25) fusion beats pure vector on exact terms, IDs, and product names.

The search index on yas.sh is a reminder that classic keyword search still wins for exact-match needs — vector search is an addition, not a replacement.

Do you need one?

Corpus size Recommendation
< 10k chunks No — brute-force in memory
10k–100k Maybe — evaluate first
100k+ Yes — HNSW, tune recall
Multi-tenant / huge Yes — partitioned indexes, IVF

Conclusion

Vector databases are fast similarity-search engines: embeddings turn meaning into geometry, ANN indexes (HNSW by default) make the search fast, and chunking/embedding quality decides whether the results are worth fetching. Start brute-force, add an index when the corpus earns it, and never let the index distract from the data quality upstream. The embeddings guide covers the input half of the equation.

Frequently asked questions

What is a vector database?

A store optimized for similarity search: it indexes high-dimensional vectors (embedding outputs) so you can find "closest" vectors to a query in milliseconds, even across millions of entries.

HNSW or IVF?

HNSW for accuracy and speed at moderate scale (millions) with higher memory use; IVF for very large corpora where memory matters and slight recall loss is acceptable. Most teams start with HNSW.

Do I need a vector database for RAG?

For small corpora (a few thousand chunks), brute-force similarity in memory is fine. Vector databases earn their keep at hundreds of thousands of chunks and beyond.

What makes vector search wrong?

Embedding quality and chunking, not the index. Garbage embeddings produce confident garbage results — the index just finds it fast.

Was this helpful? Share
🍪 Cookies & privacy. yas.sh uses only essential cookies to keep you signed in and remember your preferences. We do not run third-party trackers. See our cookie policy and privacy policy.
Settings