Skip to content

perf(hnsw,lvq,vec0): dense-ID slab HNSW, mean-centered LVQ, and opt-in RaBitQ vec0 - #3

Merged
trvon merged 1 commit into
masterfrom
perf/flat-slab-hnsw-and-quantized-vec0
Nov 24, 2026
Merged

trvon merged 1 commit into
masterfrom
perf/flat-slab-hnsw-and-quantized-vec0

Conversation

@trvon

@trvon trvon commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Dense-ID Contiguous Node Table in HNSW (hnsw.hpp, hnsw_node.hpp): Maintains a contiguous dense_nodes_ pointer table and parallel dense_edges adjacency lists updated on insert, single-threaded insert, parallel build, soft-delete isolation, compaction, clear, and persistence load. Hot-path greedy_search_layer_*, beam_search_layer_*, and beam_search_layer_quantized index dense_nodes_[dense_id] directly with zero std::unordered_map lookups per hop (including for sparse 64-bit external IDs).
  • Mean-Centered Asymmetric LVQ (lvq.hpp, store.hpp, x86_dispatch.hpp, hnsw_quantized.hpp): Adds optional dataset mean-centering (centroid_, fit_centroid(), set_centroid(), build(snap, center_mean), and backward-compatible add()) plus query-side prepare_query() and 3-op fused FMA inner loops (((q - offset) - c * scale)^2) across NEON, AVX2, x86-64 runtime dispatch, and scalar fallbacks.
  • Opt-in RaBitQ Quantized vec0 & Bounded-Heap Exact Fast-Path (vec0_module.hpp): Adds opt-in quantization=rabitq|lvq8|lvq4|none and rerank_factor=N schema options (plus vec0_set_quantization()) keeping FP32 HNSW as the default. Replaces l2_distance + full std::sort in vec0_run_exact_query with l2_squared_distance + bounded max-heap (only taking std::sqrt on the final top-k) and adds small-filter WHERE rowid IN (...) SQL pushdown.
  • Tests (tests/test_invariants.cpp): Adds tests for dense-ID HNSW sparse-ID search/delete/isolate/compact/persistence parity, mean-centered LVQ8/LVQ4 accuracy on shifted/anisotropic clusters + SIMD-vs-scalar parity, and opt-in RaBitQ vec0 + bounded-heap exact query parity.

Verification

  • Native ARM64 (NEON + DotProd): meson test -C build-round2 — 12/12 passed
  • Cross-target x86-64 (SQLITE_VEC_X86_RUNTIME_DISPATCH): xcrun clang++ -std=c++20 -arch x86_64 -fsyntax-only — PASS
  • Cross-target x86-64 (-mavx -mavx2 -mfma): xcrun clang++ -std=c++20 -arch x86_64 -mavx -mavx2 -mfma -fsyntax-only — PASS

…n RaBitQ vec0

- Maintain contiguous dense_nodes_ table and parallel dense_edges in HNSWIndex/HNSWNode so greedy/beam/quantized search hops index flat std::vector without unordered_map lookups, preserving persistence, soft-deletion, compaction, and thread safety.
- Add optional dataset mean-centering (centroid_) and QueryState pre-centering to LVQ8Store/LVQ4Store (Aguerrebere et al. 2023) with 3-op fused FMA inner loops across NEON, AVX2, x86 runtime dispatch, and scalar paths.
- Add opt-in RaBitQ/LVQ quantized HNSW mode to vec0 (schema option + C++ helper, FP32 default preserved) and optimize vec0_run_exact_query with l2_squared_distance, bounded max-heap top-k, and small-filter SQL IN pushdown.
- Add unit tests in tests/test_invariants.cpp covering dense-ID HNSW parity, mean-centered LVQ accuracy + SIMD parity, and RaBitQ/bounded-heap vec0 parity.
@trvon
trvon merged commit 9879bf0 into master Nov 24, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant