Where should embeddings live, and what does vector search actually cost?
"Find documents like this one" is not an equality or a range. A user asks a question in their own words, and you need the passages that mean the same thing, even if they share no keywords.
An embedding model turns text, images or anything else into a vector: a list of numbers where similar meanings land close together. A vector database stores those vectors and finds the nearest ones fast. pgvector adds this to PostgreSQL, so the vectors live next to your rows.
For your app: meaning-based search, with a speed you trade against how many true neighbors you find (recall).
This page is about storing embeddings and finding the closest ones quickly. I show you what an index like HNSW does, why its answers are approximate, what the memory bill looks like (measured), why filters are the hard part, and when pgvector is enough and when a dedicated vector database earns its place. After it you will be able to size a vector index, trade recall against speed, and choose where your vectors live.
Storage for embeddings, lists of a few hundred to a few thousand numbers, with an index that finds the nearest ones without comparing against every row.
Good at: Semantic search, retrieval for AI answers (RAG), recommendations, finding near-duplicates, agent memory.
Runs as: an extension in a database you already run (pgvector, MongoDB Atlas Vector Search, Cassandra 5, Redis), or a dedicated service (Qdrant, Milvus, Weaviate, Pinecone and others)The first two parts replay what Notebook 8 measured. The third estimates memory for your own numbers.
You have 20 million chunks with 1,536-dimension embeddings in pgvector, under an HNSW index. How much memory does the index want, and what would you do if the server has 128 GB?
Write your answer down first. Then open mine.
The arithmetic: 20 million × 1,536 × 4 bytes is about 123 GB of vectors, and the index adds roughly 512 bytes of links each, about 10 GB more: around 133 GB for the index alone. It does not fit in 128 GB with anything else running.
What I would try, in order: store halfvec (2 bytes a dimension), which halves the index to around 72 GB. Check whether a model or setting with fewer dimensions loses anything on your own test questions. Partition by tenant so the hot part fits. Then consider a disk-based index or a dedicated vector store.
Every step: measure recall against an exact search on a sample before and after. Saving memory is only a win if the answers stay good.
The same mechanism, vector search, elsewhere on the site: in real incidents, in measurements, and in designs.
Pick an answer. You will see whether it is right, and why.
1. What does hnsw.ef_search trade?
A bigger candidate list finds more of the true neighbours and takes a little longer.
2. Why did one tenant's search return 1.3 rows instead of 10 in Notebook 8?
The index does not know about the WHERE clause. Iterative scan, or an exact search inside the tenant, fixes it.
3. You switch to a new embedding model. What must happen to the stored vectors?
Vectors from different models live in different spaces; comparing them gives meaningless distances.
4. Going by Notebook 8, about how big is an HNSW index for 1 million 384-dimension vectors?
About 2,048 bytes per vector, so roughly 2 GB, and the table is as big again.
How do databases actually work? From one row on disk to transactions: the words you need, PostgreSQL, MySQL and MongoDB from the files up, then Redis, Cassandra and vector search, side by side, and the query and concurrency traps.