liveBook · Manning

Ivfflat

As explained in Designing AI Systems

IVFFlat is an approximate vector index that partitions vectors into clusters and searches selected clusters to accelerate similarity queries.

IVFFlat is an approximate vector index for PostgreSQL with pgvector. It clusters similar embeddings during index creation, then searches only clusters near the query instead of comparing every stored vector. section 5.4.3

This design trades some recall for substantially faster similarity queries. A relevant vector can be missed when its cluster is not searched, although the practical accuracy loss is described as small. The lists parameter controls the number of clusters: more lists can accelerate searches while increasing the chance of omission. section 5.4.3

Use IVFFlat with these operational constraints:

  • Create the index after ingesting a representative first batch of documents; an empty table cannot provide useful cluster structure. section 5.4.3
  • Start with lists = 100 for collections up to a few million vectors, then evaluate the resulting speed and recall. section 5.4.3
  • Store embeddings alongside chunk text and metadata, and expose ranked results with scores, document IDs, and metadata through a vector-store interface. section 5.7

PostgreSQL index definition

CREATE INDEX idx_chunks_embedding ON chunks USING ivfflat (embedding vector_cosine_ops) WITH (lists = 100); section 5.4.3

Listing 5.18 PostgreSQL schema for vector storage with pgvector
CREATE EXTENSION IF NOT EXISTS vector;    #A
 
CREATE TABLE chunks (
    chunk_id VARCHAR(255) PRIMARY KEY,
    document_id VARCHAR(255) NOT NULL,    #B
    index_name VARCHAR(255) NOT NULL,    #B
    chunk_text TEXT NOT NULL,
    embedding vector(1536),    #C
    metadata JSONB DEFAULT '{}',    #D
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
 
CREATE INDEX idx_chunks_document ON chunks(document_id);
CREATE INDEX idx_chunks_index ON chunks(index_name);
CREATE INDEX idx_chunks_metadata 
➥ON chunks USING gin (metadata);    #E
 
CREATE INDEX idx_chunks_embedding ON chunks
    USING ivfflat (embedding vector_cosine_ops)
    WITH (lists = 100);    #F

Inspect the complete pgvector schema, including the embedding column, metadata fields, supporting indexes, and IVFFlat definition. section 5.4.3

How Designing AI Systems covers it

How deep it goes
Explains clustering, approximate recall, list sizing, and data requirements, but does not detail query-planner internals.
Examples
Uses a pgvector PostgreSQL schema with vector_cosine_ops and lists = 100 as the concrete implementation example.
What it assumes
Assumes embeddings, PostgreSQL, pgvector, and similarity search while explaining clustering and approximate results directly.
What you can do after
Operate/configure a pgvector IVFFlat index and choose an initial cluster count for a growing embedding collection.
How it connects
Contrasts approximate nearest neighbor search with brute force and HNSW, and connects to pgvector, PostgreSQL, embeddings, and vector stores.

Also explained in

Compare how 2 books explain ivfflat →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.