Skill 2.2.3
Implement indexing strategies, including optimizing query latency and reducing pgvector compute overhead
Key Concepts
HNSW builds a layered graph; its build parameters are m (default 16) and ef_construction (default 64), and its query parameter hnsw.ef_search (default 40) raises recall at the cost of latency. IVFFlat clusters vectors into lists and searches ivfflat.probes of them; it builds faster and uses less memory but must be built after the data is loaded. DiskANN, through the pg_diskann extension on flexible server, combines high recall with fast builds. The operator class, such as vector_cosine_ops, must match the query operator.
Compute overhead falls when there is less to compare. Storing or indexing embeddings as halfvec halves their size, an embedding model with fewer dimensions shrinks every vector, and partial indexes or partitions limit the rows searched. Raising maintenance_work_mem lets an index build in memory, and max_parallel_maintenance_workers speeds builds. Index builds and searches above 2,000 dimensions need halfvec or dimension reduction.