Repository navigation
perf(index): reuse RaBitQ LUTs and share IVF query state - #9190
Conversation
ed799ad to
26e6491
Compare
26e6491 to
d9ef2c5
Compare
d9ef2c5 to
46d8405
Compare
46d8405 to
7016446
Compare
7016446 to
a0976c1
Compare
Reuse per-query RaBitQ FastScan state and memoize partition-cache work so the fixed cost of an IVF query drops by ~15-23% (x86 5M synth, recall-neutral, result hashes unchanged): - Reuse the raw-query context across probed partitions: memoize the FastScan LUTs (normal_lut / accurate_lut) on RabitRawQueryContext, since the raw-query dist_table is centroid-independent and was being re-quantized per partition. - Precompute namespace-tagged BLAKE3 digests for partition cache keys, skipping a digest computation per probe; resolve() rejects cross-namespace digests. - Memoize IVF partition reconstruction in its own capacity-accounted cache entry (CachedReconstructedIndex), keyed by object store + fragment reuse index identity, so identical reopens reuse the built index without growing the already-inserted IvfIndexState past the cache's eviction weight. - Share Query via Arc across probed partitions (PreparedPartitionSearch.query) and add a parallel per-partition dist_q_c field, stopping a full Query clone per partition. IvfSubIndex::query_params keeps a default impl (no forced API break); FlatIndex / HNSW override it to avoid the clone. - Harden partition_cache_key with a debug_assert! bounds guard, and close the internal RabitRawQueryContext type with #[doc(hidden)] #[non_exhaustive] + new() (beta-period internal-plumbing closure, not a public API change). No on-disk format change; partition_cache_keys is runtime-only and excluded from the CacheCodec wire format. The reconstructed index is a separate in-memory cache entry (no codec), so it is never serialized.
a0976c1 to
e5ce309
Compare
…ndices Reverts 900480b. An A/B on the AMS recall workload (200k memories, hot and small tenants, two interleaved rounds) measured no difference in vector, keyword, candidate-load or graph latency or gateway CPU beyond run-to-run noise. Upstream's open lance-format#9190 caches the same state in the session cache with capacity accounting; follow that instead of a handle-local map. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_0185J8JmcwuobFgtj5GWKfxS
…r-9190-merge-20261101
Reuse RaBitQ FastScan LUTs for the lifetime of a raw-query context and share one Query across probed partitions while passing dist_q_c separately. Keep main's context-sensitive reconstruction path. Remove the stale whole-index memo and eager partition-key precomputation: warm scans reconstruct from cached state, so precomputing every partition key on each scan regresses the real query path.
Use a 64-dimension example so an empty ex_query correctly reflects the already-aligned padding contract.
There was a problem hiding this comment.
✅ Gate recommendation: approve.
The narrowed solution removes repeated query-only LUT work without adding persistent cache state. Partition-specific distances and processed keys are preserved, with focused RaBitQ tests and multi-fragment batch/single-query checks passing.
Xuanwo
left a comment
There was a problem hiding this comment.
Reviewed the final head against fresh main. The change reuses per-query RaBitQ LUTs, shares IVF query state across partitions, preserves partition-specific keys and distances, and leaves main's context-sensitive reconstruction and cache accounting unchanged. The public record break is documented with constructor and read-only accessor migration.
All applicable checks and the Gatekeeper verdict pass for aa9b09d6bd5508e5595bfd760798d123255fb878. Focused regression and same-fixture benchmark evidence are recorded in the PR description.
Summary
An IVF_RQ query prepares one raw-query context and then probes multiple
partitions. The FastScan LUT derived from that context depends only on the
query, but main quantizes it again for every partition. This PR builds each LUT
once per raw-query context and reuses it across probes.
The same change shares one
QuerybyArcacross probed partitions and passesthe per-partition centroid distance separately.
FlatIndexandHNSWbuildtheir query params directly from that shared query, avoiding a full
Queryclone per probe. Batch searches also build one
Arc<Query>per query ratherthan cloning the full query for every partition assignment.
Main's context-sensitive reconstruction remains unchanged. No live
reconstructed index and no partition cache keys are retained, and there is no
on-disk format change.
API note
RabitRawQueryContext, returned by the publicRabitQuantizationMetadata::prepare_raw_query_context, was a six-public-fieldrecord in the released v14.0.2 API. This PR adds private memo fields, makes
dist_tableprivate, and marks the record#[non_exhaustive]. This is abreaking source change and is labelled
breaking-change.Use the constructor with the same six values, then read the distance table
through its accessor:
Performance
Measured on one Apple M1 host with
release-with-debug, against main2134b5dfc045877a00c9cfd36f187b5243a2a279and tested source349c4091d89bad0bc1379a8a824733014d97cbbf. A documentation-only commitfollowed the measurement.
The harness used one deterministic 100,000 x 128
f32fixture with 256 IVFpartitions and one fixed query. Each process ran 200 timed
k=10,refine(2)queries; main and candidate binaries alternated for nine rounds. The table is
the median of the nine per-process p50s. Timing includes collecting exactly 10
result rows and computing a result-identity fingerprint per query, so these are
end-to-end in-process collector timings rather than pure kernel latency.
IVF_PQ is neutral, as expected because it does not use the RaBitQ LUT. IVF_RQ
shows a small local improvement; the shared
Arc<Query>path also applies toPQ, so the overall difference is not attributed to the LUT alone. This does not
claim results across backends, ISA targets, or a broader
nlistmatrix.