Skip to content

perf(simd,quantization,vec0): x86 runtime dispatch, fused RaBitQ popcount, incremental vec0 ANN, SearchStats & invariants - #2

Merged
trvon merged 3 commits into
masterfrom
feat/x86-simd-dispatch-rabitq-vec0-incremental
Nov 24, 2026
Merged

trvon merged 3 commits into
masterfrom
feat/x86-simd-dispatch-rabitq-vec0-incremental

Conversation

@trvon

@trvon trvon commented Nov 24, 2026

Copy link
Copy Markdown
Owner

Summary

  1. x86-64 runtime SIMD dispatch & RaBitQ popcount

    • Added missing SQLITE_VEC_X86_RUNTIME_DISPATCH (x86::l2_squared_avx2) branch to distances::l2_squared_distance().
    • Stored precomputed inv_scales on LVQ8Store and LVQ4Store, added compile-time AVX2 and runtime-dispatched AVX2+FMA kernels, and switched quantized beam search (HNSWQuantizedSearch) to compare squared distances directly (eliminating per-hop std::sqrt).
    • Replaced byte-wise 256-entry LUT popcount in RaBitQ with uint64_t std::popcount, added a fused single-pass 4-plane kernel (and_popcount_4planes for both NEON and uint64_t), and precomputed uint16_t code_popcount at encode time.
    • Fixed a signed int16_t overflow bug in l2_distance_int8_neon (caught by the new invariant test suite) by using widening vsubl_s8 + vmlal_s16.
    • Added simd/x86_dispatch.hpp to install_headers in meson.build.
  2. Incremental vec0 ANN maintenance & cached prepared statements

    • Updated vec0Update to maintain ann_index incrementally on INSERT/UPDATE/DELETE when ann_ready is true, triggering compact() only when needs_compaction() (or when replacing an existing/soft-deleted node ID), with fallback invalidation on error.
    • Cached prepared statements on Vec0Table for xUpdate and xColumn, resetting/clearing bindings per call and finalizing on xDisconnect/xDestroy.
  3. Optional HNSW SearchStats telemetry & invariant test suite

    • Added optional SearchStats* stats = nullptr out-parameter (hops, distance_evals, rerank_evals, filter_rejections) to HNSW and quantized search APIs (zero overhead when nullptr).
    • Added tests/test_invariants.cpp wired into tests/meson.build covering L2/Hamming symmetry & triangle inequality, unaligned float*/int8_t* spans, odd dimensions (1, 7, 15, 17, 31, 33, 385, 769), SIMD-vs-scalar parity for l2_squared_distance, LVQ8Store, LVQ4Store, and RaBitQStore, SearchStats telemetry, and incremental vec0 insert/update/delete recall parity.

Verification

  • meson setup build-hillclimb -Denable_tests=true -Denable_examples=false -Denable_benchmarks=false && meson compile -C build-hillclimb -j4 && meson test -C build-hillclimb --print-errorlogs: 12/12 tests passed (arm64 NEON + DotProd).
  • Cross-target clang++ -std=c++20 -target x86_64-apple-macos13 -fsyntax-only verified clean compilation of both SQLITE_VEC_X86_RUNTIME_DISPATCH and compile-time -mavx -mavx2 -mfma paths.

…itQ popcount

- Wire SQLITE_VEC_X86_RUNTIME_DISPATCH (x86::l2_squared_avx2) in distances::l2_squared_distance()
- Store inv_scales on LVQ8Store/LVQ4Store, add AVX2/runtime-dispatch kernels, and compare squared distances in quantized beam search (no per-hop sqrt)
- Replace 256-entry LUT popcount in RaBitQ with uint64 std::popcount + fused 4-plane kernel and precomputed uint16_t code_popcount
- Fix signed int16 overflow in l2_distance_int8_neon using widening vsubl_s8 + vmlal_s16
- Install simd/x86_dispatch.hpp in meson.build
- Maintain ann_index incrementally on INSERT/UPDATE/DELETE when ann_ready is true (compact only on needs_compaction() or node ID reuse, with invalidation fallback on error)
- Cache prepared statements on Vec0Table for xUpdate and xColumn fallback, resetting/clearing bindings per call and finalizing on xDisconnect/xDestroy
…rity test suite

- Add optional SearchStats* out-parameter (hops, distance_evals, rerank_evals, filter_rejections) to HNSW and quantized search methods with zero overhead when nullptr
- Add tests/test_invariants.cpp covering L2/Hamming symmetry & triangle inequality, unaligned float/int8 spans, odd dimensions (1..769), SIMD-vs-scalar parity for L2/LVQ8/LVQ4/RaBitQ, SearchStats telemetry, and incremental vec0 insert/update/delete recall parity
@trvon
trvon merged commit 02352bf 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