Home›Learn›Vector databases 1: why vector search

Vector databases

Where should embeddings live, and what does vector search actually cost?

Explained clearly

What a vector database is, and why it exists

1

The problem

"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.

2

What it is

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.

3

Follow one search

  1. The question is turned into a vector by the same model.
  2. Comparing it with every stored vector would be exact but slow, so an approximate index (HNSW or IVFFlat) narrows the search to likely neighbors.
  3. The closest vectors come back, with the rows they belong to.
  4. The app passes those rows to a language model, or shows them as results.

For your app: meaning-based search, with a speed you trade against how many true neighbors you find (recall).

4

What to watch

  • Recall versus speed. Index settings decide both; measure them on your own data.
  • Filters. Filtering by tenant after an approximate search can return too few results.
  • Memory. HNSW indexes are fast when they fit in memory and slow when they do not.

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.

Vector search: in one line

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)
Where it fits in a design

Start with the database you have

Use it for

  • pgvector, when the index fits in one machine's memory and you want filters, joins, permissions and deletes in one transaction: Search and AI retrieval, Agent memory
  • The vector search in the database you already run, MongoDB, Redis or Cassandra 5, before adding a new system
  • A dedicated vector database when the index is far larger than one machine, query rates are very high, or you need its hybrid search and multi-tenancy at scale

Not for

  • The source of truth for documents, permissions or deletes
  • Exact lookups by id or keyword: a normal index is faster and exact
  • A search nobody has measured recall for
Try it

Trade recall for speed, filter a tenant, size an index

The first two parts replay what Notebook 8 measured. The third estimates memory for your own numbers.

Your turn

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.

Show my answer

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.

Next · chapter 2How it stores your dataVectors, distance and the index
Connected

Where this shows up

The same mechanism, vector search, elsewhere on the site: in real incidents, in measurements, and in designs.

Check yourself · 4 questions

Check yourself

Pick an answer. You will see whether it is right, and why.

1. What does hnsw.ef_search trade?

2. Why did one tenant's search return 1.3 rows instead of 10 in Notebook 8?

3. You switch to a new embedding model. What must happen to the stored vectors?

4. Going by Notebook 8, about how big is an HNSW index for 1 million 384-dimension vectors?

Part 1 of 4 · Learn · 56 pagesAll pages

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.

Start 1: the basicsStart 2: ten conceptsStart 3: how a query travelsStart 4: napkin mathThe courseShort videosPostgreSQL 1: why PostgreSQLPostgreSQL 2: how it stores your dataPostgreSQL 3: what happens on every writePostgreSQL 4: high availability with PatroniPostgreSQL 5: running it as a DBREPostgreSQL 6: when it breaksPostgreSQL on Kubernetes: CloudNativePGMySQL 1: why MySQLMySQL 2: how it stores your dataMySQL 3: what happens on every writeMySQL 4: high availability with InnoDB ClusterMySQL 5: running it as a DBREMySQL 6: when it breaksMySQL failover with OrchestratorMySQL on Kubernetes: the Percona operatorsMongoDB 1: why MongoDBMongoDB 2: how it stores your dataMongoDB 3: what happens on every writeMongoDB 4: high availability with replica setsMongoDB 5: running it as a DBREMongoDB 6: when it breaksMongoDB on Kubernetes: the Percona operatorB-tree and LSM treeRedis 1: why RedisRedis 2: how it stores your dataRedis 3: high availabilityRedis 4: running it as a DBRERedis 5: when it breaksCassandra 1: why CassandraCassandra 2: how it stores your dataCassandra 3: high availabilityCassandra 4: running it as a DBRECassandra 5: when it breaksVector databases 1: why vector searchVector databases 2: how it stores your dataVector databases 3: high availabilityVector databases 4: running it as a DBREVector databases 5: when it breaksDatabase familiesEngines side by sideQueries that look fine and are notLost updates and write skewMany servers 1: keep a copy runningMany servers 2: who is the leaderMany servers 3: CAP as settingsMany servers 4: unique IDsMany servers 5: split the dataMany servers 6: across servicesMany servers 7: a thousand databasesStaff path, zero to architect