Skip to content

perf(index): reuse RaBitQ LUTs and share IVF query state - #9190

Merged
Xuanwo merged 4 commits into
lance-format:mainfrom
xiaguanglei:index/perf-index-ivf-search-overhead
Nov 2, 2026
Merged

Xuanwo merged 4 commits into
lance-format:mainfrom
xiaguanglei:index/perf-index-ivf-search-overhead

Conversation

@xiaguanglei

@xiaguanglei xiaguanglei commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

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 Query by Arc across probed partitions and passes
the per-partition centroid distance separately. FlatIndex and HNSW build
their query params directly from that shared query, avoiding a full Query
clone per probe. Batch searches also build one Arc<Query> per query rather
than 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 public
RabitQuantizationMetadata::prepare_raw_query_context, was a six-public-field
record in the released v14.0.2 API. This PR adds private memo fields, makes
dist_table private, and marks the record #[non_exhaustive]. This is a
breaking source change and is labelled breaking-change.

Use the constructor with the same six values, then read the distance table
through its accessor:

let context = RabitRawQueryContext::new(
    code_dim,
    ex_bits,
    rotated_query,
    dist_table,
    ex_query,
    sum_q,
);
let distance_table = context.dist_table();

Performance

Measured on one Apple M1 host with release-with-debug, against main
2134b5dfc045877a00c9cfd36f187b5243a2a279 and tested source
349c4091d89bad0bc1379a8a824733014d97cbbf. A documentation-only commit
followed the measurement.

The harness used one deterministic 100,000 x 128 f32 fixture with 256 IVF
partitions 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.

Index nprobes main candidate delta
IVF_PQ 1 907 us 910 us +0.33%
IVF_PQ 32 972 us 970 us -0.21%
IVF_RQ 8 821 us 818 us -0.37%
IVF_RQ 32 860 us 848 us -1.40%

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 to
PQ, so the overall difference is not attributed to the LUT alone. This does not
claim results across backends, ISA targets, or a broader nlist matrix.

@github-actions github-actions Bot added A-index Vector index, linalg, tokenizer performance labels Sep 14, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 14, 2026
@xiaguanglei
xiaguanglei force-pushed the index/perf-index-ivf-search-overhead branch from ed799ad to 26e6491 Compare September 14, 2026 07:11
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 14, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 14, 2026
@xiaguanglei
xiaguanglei force-pushed the index/perf-index-ivf-search-overhead branch from 26e6491 to d9ef2c5 Compare September 14, 2026 07:30
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 14, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 14, 2026
@xiaguanglei
xiaguanglei force-pushed the index/perf-index-ivf-search-overhead branch from d9ef2c5 to 46d8405 Compare September 14, 2026 08:08
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 14, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 14, 2026
@xiaguanglei
xiaguanglei force-pushed the index/perf-index-ivf-search-overhead branch from 46d8405 to 7016446 Compare September 23, 2026 03:39
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Sep 23, 2026
@xiaguanglei
xiaguanglei force-pushed the index/perf-index-ivf-search-overhead branch from 7016446 to a0976c1 Compare September 23, 2026 05:08
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Sep 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 23, 2026
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.
@xiaguanglei
xiaguanglei force-pushed the index/perf-index-ivf-search-overhead branch from a0976c1 to e5ce309 Compare September 23, 2026 10:10
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 23, 2026
lance-gatekeeper[bot]

This comment was marked as outdated.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Sep 23, 2026
xiaguanglei pushed a commit to xiaguanglei/lance that referenced this pull request Oct 15, 2026
…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
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.
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 2, 2026
@Xuanwo Xuanwo changed the title perf(index): cut fixed and per-partition overhead of IVF search perf(index): reuse RaBitQ LUTs and share IVF query state Nov 2, 2026

@lance-gatekeeper lance-gatekeeper Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 2, 2026

@Xuanwo Xuanwo left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-index Vector index, linalg, tokenizer breaking-change K-approved Latest Gatekeeper recommendation permits acceptance. performance

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants