Vector Flat Index

A flat index is the simplest way to search vectors. It stores every vector in a plain list and compares the query against each one. No shortcuts, no clever structures, no guessing. Many engineers skip this index too fast, yet it plays an important role in real systems.

The Phone Book Analogy

Imagine a phone book with no alphabetical order. To find "Maria Lopez", you read every single entry from page one until you spot the name. You never miss the right entry, but the search takes a long time when the book grows thick.

How Flat Search Works

FLAT INDEX SEARCH

Stored vectors:   V1   V2   V3   V4   V5  ...  Vn
                   |    |    |    |    |        |
Query Q compared   v    v    v    v    v        v
against ALL:     0.42 0.91 0.13 0.77 0.88 ...  0.35

Sort all scores -> return the top K

Comparisons per query = n   (every vector, every time)

The engine calculates a distance or similarity score for every stored vector. It sorts the scores and returns the best matches. Because the engine checks everything, the answer is always exact. Engineers call this property 100% recall.

The Cost of Checking Everything

Flat search cost grows in a straight line with the number of vectors. Double the data and the search time roughly doubles.

Stored VectorsComparisons per QueryFeel for Speed
10,00010,000Instant
100,000100,000Fast
1,000,0001,000,000Noticeable delay
100,000,000100,000,000Too slow for live use

Memory Math

A flat index stores raw vectors. Each number usually takes 4 bytes. You can estimate memory with a simple formula.

Memory = vectors x dimensions x 4 bytes

Example: 1,000,000 vectors with 768 dimensions

1,000,000 x 768 x 4 = 3,072,000,000 bytes
                    = about 3 GB

The flat index adds almost no extra memory beyond the vectors themselves. Graph-based indexes add more on top.

Strengths of Flat Indexing

  • Perfect accuracy: Every search returns the true nearest neighbors.
  • Zero build time: New vectors join the list immediately.
  • No tuning: No parameters require adjustment.
  • Easy deletion: Removing a vector never damages a structure.
  • Simple debugging: Results always make sense because nothing gets skipped.

Weaknesses of Flat Indexing

  • Slow at scale: Search time climbs with every added vector.
  • High compute use: Each query burns processor time on every item.
  • Poor fit for heavy traffic: Many users searching at once multiply the cost.

When to Choose a Flat Index

SituationFlat Index Fit
Under 100,000 vectorsExcellent
Prototype or first demoExcellent
Strict accuracy requirementExcellent
Small filtered subsetsGood
Millions of vectors with fast response goalsPoor

The Flat Index as a Measuring Stick

Smart teams use a flat index even when they run HNSW or IVF in production. The flat index produces the true answer. You compare the approximate index against it and measure recall.

RECALL TEST

1. Pick 100 sample queries
2. Run each on the Flat index      -> true top 10
3. Run each on the HNSW index      -> approximate top 10
4. Count how many true results HNSW found

Example: HNSW found 9.6 of 10 on average
Recall = 96%

This test tells you whether your tuning settings deliver acceptable quality. Without a flat baseline, you cannot know how many good results your fast index misses.

Practical Tips

  1. Start every project with a flat index and measure the speed.
  2. Switch to an approximate index only when latency becomes a real problem.
  3. Keep a small flat index on the side for recall testing.
  4. Normalize vectors before storing them when you plan to use cosine similarity.

The flat index teaches the core truth of vector search: exact answers cost time, and faster indexes trade a small amount of accuracy for large speed gains.