CtrlK
BlogDocsLog inGet started
Tessl Logo

g14wxz/pgvector-hnsw-index-selection

Enforces HNSW index selection over IVFFlat and correct distance operator usage for pgvector.

100

Quality

100%

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

SecuritybySnyk

Passed

No known issues

Overview
Quality
Evals
Security
Files

index.mddocs/

Pgvector HNSW Index Selection

Enforces HNSW index selection over IVFFlat and correct distance operator usage for pgvector.

Overview

This tile mandates HNSW as the only vector index type and enforces the correct distance operator based on embedding normalization. Normalized embeddings MUST use Inner Product (<#>), which is mathematically equivalent to cosine similarity but faster. IVFFlat indexes are explicitly forbidden.

Reference

Distance Operator Selection

Embedding TypeOperatorOperator ClassNotes
Normalized<#>vector_ip_opsEquivalent to cosine, faster
Unnormalized<=>vector_cosine_opsHandles variable magnitudes
Euclidean (rare)<->vector_l2_opsOnly with explicit approval

HNSW Parameter Guidelines

Table Sizemef_construction
< 1M rows1664
>= 1M rows24128

Index Creation Template

CREATE INDEX idx_{table}_embedding_hnsw
ON {table}
USING hnsw (embedding vector_ip_ops)
WITH (m = 16, ef_construction = 64);

Normalization Check

SELECT vector_norm(embedding) FROM {table} LIMIT 5;
-- All values ~1.0 = normalized

Dependencies

  • supabase-mcp-verification -- root prerequisite.
  • pgvector (vector) extension MUST be enabled.

Composition Position

  • Stage: database-schema
  • Priority: HIGH
  • Incompatibilities: supabase/ivfflat-index -- MUST NOT be installed alongside this tile.
  • Executes after table creation tiles and before any application-layer vector search integration.

docs

index.md

tile.json