Expand description
§Vector Storage Hot-Path Layout (Task 16)
Optimized memory layout for vector storage focused on hot-path performance:
- Contiguous embedding storage for cache efficiency
- SIMD-aligned vectors ┌─────────────────────────────────────────────────────────────────┐ │ Embedding Block (64KB aligned) │ ├─────────────────────────────────────────────────────────────────┤ │ Header (64B) │ Padding │ Vectors (contiguous, 32B aligned) │ │ - magic │ │ Vec[0]: [f32; D] │ │ - version │ │ Vec[1]: [f32; D] │ │ - count │ │ … │ │ - dim │ │ Vec[N-1]: [f32; D] │ │ - checksum │ │ │ └─────────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────────┐ │ Neighbor Block (64KB aligned) │ ├─────────────────────────────────────────────────────────────────┤
§Design Principles
- SIMD Alignment: All vectors 32-byte aligned for AVX2
- Cache Lines: Hot data packed into 64-byte cache lines
- Prefetching: Neighbor lookups prefetch next block
- Contiguous: Avoid pointer chasing in hot path
Structs§
- Batch
Distance Computer - Batch distance computation with prefetching
- Embedding
Block Header - Header for an embedding block
- Embedding
Storage - Contiguous, SIMD-aligned embedding storage
- HotPath
Vector Store - Combined embedding and neighbor storage optimized for HNSW traversal
- Neighbor
Block Header - Header for a neighbor block
- Neighbor
Storage - Contiguous neighbor list storage for graph traversal
Constants§
- BLOCK_
ALIGNMENT - Block alignment (page size)
- CACHE_
LINE_ SIZE - Cache line size
- EMBEDDING_
MAGIC - Magic number for embedding blocks
- NEIGHBOR_
MAGIC - Magic number for neighbor blocks
- SIMD_
ALIGNMENT - SIMD alignment for vectors (AVX2 = 32 bytes, AVX-512 = 64 bytes)
Functions§
- align_
down - Align a value down to the given alignment
- align_
up - Align a value up to the given alignment
- alloc_
aligned - Allocate aligned memory
- free_
aligned ⚠ - Free aligned memory