- Create indexes for fast approximate nearest neighbor search
- Configure index build-time parameters for optimal performance
- Enable label-based filtering for precise vector search
- Choose storage layouts for memory optimization or plain storage
-
The index build process can be memory-intensive. Consider increasing
maintenance_work_mem: -
Label values must be within
smallintrange (-32768 to 32767) - Creating indexes on UNLOGGED tables is not currently supported
- Null vectors are not indexed; null labels are treated as empty arrays
Samples
Basic index creation
With custom parameters
With label-based filtering
With storage layout
Syntax
Distance operators
| Operator | Description | Use with |
|---|---|---|
vector_cosine_ops | Cosine distance (<=>) | Normalized embeddings |
vector_l2_ops | L2 distance (<->) | Euclidean distance |
vector_ip_ops | Inner product (<#>) | Dot product (not compatible with plain storage) |
Build-time parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
storage_layout | text | memory_optimized | memory_optimized uses Statistical Binary Quantization; plain stores uncompressed data |
num_neighbors | int | 50 | Maximum number of neighbors per node. Higher values increase accuracy but slow graph traversal |
search_list_size | int | 100 | Search parameter during construction. Higher values improve graph quality but slow index builds |
max_alpha | float | 1.2 | Alpha parameter in the algorithm. Higher values improve graph quality but slow index builds |
num_dimensions | int | 0 (all dimensions) | Number of dimensions to index. Useful for Matryoshka embeddings |
num_bits_per_dimension | int | 2 (if less than 900 dims), 1 otherwise | Bits per dimension when using Statistical Binary Quantization |