Course contentsShow
← AI Engineering
Lesson 253 of 1,8867. Vector Databases - FundamentalsFree lesson

Flat (Brute-Force) Indexing

Understand exact nearest neighbor search and when linear scan is acceptable for small datasets.

Flat (Brute-Force) Indexing

What You'll Learn

You'll understand the simplest vector search approach: comparing every vector directly, and when this "check everything" method is actually the right choice.

The Core Idea

Flat indexing (also called brute-force or exhaustive search) means computing the similarity between your query vector and every single vector in your database, one by one. No clever shortcuts, no approximations—just pure mathematical comparison across your entire collection.

Think of it like finding the tallest person in a room by measuring everyone individually. You can't miss the right answer because you literally checked everyone, but it takes longer as the room gets crowded.

How It Works

When you search with flat indexing:

  1. Your query vector arrives (e.g., embedding of "best pizza in Chicago")
  2. The system calculates cosine similarity (or dot product) between your query and vector #1, then #2, then #3... all the way to the last one
  3. It sorts all results by similarity score
  4. Returns the top-K matches

This guarantees exact nearest neighbor search—you get the mathematically perfect matches, not approximations.

When Linear Scan Is Acceptable

Flat indexing works perfectly fine when:

  • Small datasets: Under ~10,000-100,000 vectors (depending on dimensionality and latency requirements)
  • Development and testing: Getting accurate baselines before optimizing
  • High accuracy requirements: When you cannot tolerate any approximation errors
  • Infrequent queries: If you only search occasionally, speed matters less

Key Takeaway: Flat indexing trades speed for perfect accuracy—ideal for small datasets where checking every vector is fast enough, but it becomes impractical as your collection grows into millions of vectors.