Home›Learn›Vector databases 2: how it stores your data
Vector databases · Chapter 2

How vector search stores your data

How does "find similar" work without reading every row?

Vectors, a distance, and an index that trades a little accuracy for a lot of speed. Then one search, end to end.

The architecture: a model, an index, and the data behind it

The vectors come from an embedding model. The index decides how fast and how accurately you can search them. The source data and its rules live somewhere you already trust.

The same layers as a still diagram, with every part named:

Vector search: architecture

From question to answer

Embedding modelturns text or images into a vector of, say, 384, 768 or 1,536 numbers · the same model must embed both the stored data and the questions
→
Index, in memoryHNSW: a layered graph of neighbours, fast and accurate, hungry for memory · IVF: clusters of vectors, cheaper to build, needs tuning · quantized copies to save space
→
Storagethe vectors and their metadata, plus the source documents · in pgvector, an ordinary table and an index
Who does what: An exact search compares the question with every vector: always right, slow at scale. An approximate index checks a small part of the data and is usually right; how often is called recall, and you trade it against speed with settings like ef_search.
Where the data lives

What takes the space, and where it goes

PlaceWhat it holdsWhat to watch
The vectorsdimensions × 4 bytes each, as 32-bit floats: 384 dimensions is 1,536 bytesNotebook 8: 1,641 bytes per row in the table, with its text and row header.
An HNSW indexa copy of every vector plus links to about 2 × m neighboursNotebook 8: 2,048 bytes per vector at m = 16. Table plus index: 3,689 bytes, 2.4 times the raw floats. Fast only while it fits in memory.
An IVF index (ivfflat)vectors grouped around centroids learned from the dataBuild it after the data is loaded. lists and probes trade speed and recall. Recall drops if new data drifts from the centroids.
Quantized vectorshalfvec (2 bytes a dimension), or one bit a dimension with binary_quantize. Some dedicated stores also offer int82 to 32 times smaller. Re-rank the top results with the full vectors to win back recall.
Metadata for filterstenant, permissions, datesFiltering after the index can return too few rows. Notebook 8: 1.3 rows out of 10.
Follow it

Follow one search, and one filter

100,000 memories for 100 tenants, as in Notebook 8. Step through a search, then tick the box to filter by tenant.

An HNSW index over 100,000 vectors returns its 10 nearest in under a millisecond. At the default settings, what share of the true 10 nearest does it find?

About 95% in Notebook 8, with ef_search at 40. Approximate means it usually finds them, not always. Raising ef_search to 160 found all of them for a little more time.

Next · chapter 3High availabilityIt fails over with your PostgreSQL← Chapter 1: Why vector search
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