Skip to content

feat(index): support SQ8 quantized refinement - #11126

Merged
Xuanwo merged 3 commits into
lance-format:mainfrom
kamronis:feat/sq8-quantized-refinement
Nov 30, 2026
Merged

Xuanwo merged 3 commits into
lance-format:mainfrom
kamronis:feat/sq8-quantized-refinement

Conversation

@kamronis

@kamronis kamronis commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

feat(index): support SQ8 quantized refinement

quantized_refine_factor supports current-format IVF_SQ and IVF_HNSW_SQ
alongside flat IVF_RQ. Flat SQ8 uses its native bounded scan. HNSW expands
the graph candidate pool and reuses distances computed during graph search
at the native eight-bit precision. An explicit ef must cover
k * refine_factor * quantized_refine_factor. The default grows with the
candidate budget. Flat RQ uses Fast discovery and Accurate scoring for
unbounded queries, and searches directly in Accurate mode for bounded queries.

HNSW loads compact, realigned partitions through the existing IVF loader
from #11141. Deferred
compaction, explicit remapping, and prewarming use that same storage and
graph alignment. Candidate discovery and final selection apply segment
ownership and distance bounds.

Fully indexed row-ID and distance queries can run from stored index data.
Optional exact refinement, unindexed fragments, and stale overlays can
read original vectors. Completed partition results use the existing snapshot
identity and session cache budget. Batch queries use the existing per-query
path. Python and Java use the same options and Rust validation.

Validation

The cache-disabled regression searches two SQ8 partitions with ef=64
and compares native k=32 with k=8, quantized_refine_factor=4.
It checks the first eight ordered row IDs and distance bits, recall against
exact search, partition loads, and comparison counts. The bounded case
also verifies an inclusive lower bound and exclusive upper bound against
native SQ8 search with the same candidate budget.

On the reviewed head (da48673e9), the results matched before the
regression failed on partition loads. Native search loaded two partitions
and recorded 147 comparisons. Quantized refinement loaded four and
recorded 211 comparisons.

On 9ef9f9cd9, both queries loaded two partitions and recorded equal
comparison counts. The bounded and unbounded results matched native
search bit for bit, and recall@8 against exact search met the 0.5 threshold.

The persisted-remap regression inspects the replacement files directly
after deleting one row from a 400-row fixture, compacting with deferred
remapping, and explicitly remapping the index. It checks for 399 physical
rows, zero tombstones, exact live membership, and matching graph coverage.
Lifecycle cases exercise cold and prewarmed loads after compaction.

Rust validation passed on 9ef9f9cd9 with the pinned toolchain and the
ci profile. The focused score-reuse regression passed, along with 183
refinement tests (including the focused regression), 60 segment tests,
four batch segment-ownership tests, and two persisted-remap tests.
cargo fmt --all -- --check and workspace Clippy with
--all --tests --benches -- -D warnings passed.

The rebuilt Python extension passed all 32 focused vector-index tests.
uv run make lint passed with 18 Pyright warnings and zero errors.

The Java Maven run passed Spotless, all 19 VectorSearchTest cases,
and all 39 JNI Rust tests. JNI formatting and Clippy passed.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@github-actions github-actions Bot added A-python Python bindings A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-docs Documentation enhancement New feature or request labels Nov 16, 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 Nov 16, 2026
@kamronis
kamronis force-pushed the feat/sq8-quantized-refinement branch from 63e6df6 to da48673 Compare November 27, 2026 11:41
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 27, 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 Nov 27, 2026
Xuanwo
Xuanwo previously requested changes Nov 27, 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.

Please reuse the HNSW SQ8 distances in candidates.batch when selecting the final top K. The graph search has already scored those candidates with the same SQ8 calculator. Keep the larger candidate budget, segment filtering and distance bounds, and retain the separate scoring pass for RQ, where the scores differ.

With nprobes=2 and ef=64, I compared the first eight rows of native k=32 with k=8, quantized_refine=4. The ordered row IDs and distance bits matched in all 24 combinations of metric, bounds, SQL prefilter and cache setting. On cold unbounded queries the second pass added 64 comparisons. With the index cache disabled, partition loads doubled from two to four. Please add a focused regression that checks the returned scores and catches the duplicate partition load. Scoring path

The persisted remap and snapshot tests passed with the compact storage from #11141. Please update the PR description to reflect that layout and remove the references to retained tombstone routing slots and the deleted doctests.

@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 28, 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 duplicate HNSW SQ8 scoring pass identified in the maintainer review is removed. Graph-search distances now feed final selection directly, preserving the larger candidate budget, segment ownership filtering, and distance bounds. RQ retains its separate Accurate scoring pass. The compact-storage remap fix from merged #11141 remains intact. I found no remaining merge blocker.

@lance-gatekeeper lance-gatekeeper Bot added the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 28, 2026
@Xuanwo
Xuanwo dismissed their stale review November 28, 2026 09:22

AI-assisted verification on 9ef9f9cd: both Linux architectures passed the SQ8 score-reuse regression with two partition loads and equal comparison counts on both cache-disabled paths. The PR now documents the compact layout. CI

@kamronis
kamronis force-pushed the feat/sq8-quantized-refinement branch from 9ef9f9c to 3240f06 Compare November 30, 2026 03:55
@lance-gatekeeper lance-gatekeeper Bot removed the K-approved Latest Gatekeeper recommendation permits acceptance. label Nov 30, 2026
@kamronis
kamronis force-pushed the feat/sq8-quantized-refinement branch from dc121d0 to fdde5c4 Compare November 30, 2026 13:07
@codecov

codecov Bot commented Nov 30, 2026

Copy link
Copy Markdown

❌ 1 Tests Failed:

Tests completed Failed Passed Skipped
11940 1 11939 0
View the full list of 1 ❄️ flaky test(s)
lance::hybrid_udtf::hybrid_field_path_payload::case_2_backtick

Flake rate in main: 100.00% (Passed 0 times, Failed 2 times)

Stack Traces | 0.632s run time
thread 'hybrid_field_path_payload::case_2_backtick' (98090) panicked at .../lance/tests/hybrid_udtf.rs:1059:9:
assertion `left == right` failed: hybrid projection="a`b": RecordBatch { schema: Schema { fields: [Field { name: "a`b", data_type: Int32, nullable: true }], metadata: {} }, columns: [PrimitiveArray<Int32>
[
  null,
  null,
  null,
]], row_count: 3 }
  left: 3
 right: 0
stack backtrace:
   0: __rustc::rust_begin_unwind
             at .../std/src/panicking.rs:679:5
   1: core::panicking::panic_fmt
             at .../core/src/panicking.rs:80:14
   2: core::panicking::assert_failed_inner
             at .../core/src/panicking.rs:434:23
   3: core::panicking::assert_failed::<usize, usize>
             at .../core/src/panicking.rs:394:5
   4: {async_fn#0}
             at ./tests/hybrid_udtf.rs:1059:9
   5: {async_block#0}
             at ./tests/hybrid_udtf.rs:1029:1
   6: poll<&mut dyn core::future::future::Future<Output=()>>
             at .../src/future/future.rs:133:9
   7: {closure#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:830:70
   8: with_budget<core::task::poll::Poll<()>, tokio::runtime::scheduler::current_thread::{impl#9}::block_on::{closure#0}::{closure#0}::{closure_env#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../task/coop/mod.rs:167:5
   9: budget<core::task::poll::Poll<()>, tokio::runtime::scheduler::current_thread::{impl#9}::block_on::{closure#0}::{closure#0}::{closure_env#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../task/coop/mod.rs:133:5
  10: {closure#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:830:25
  11: <tokio::runtime::scheduler::current_thread::Context>::enter::<core::task::poll::Poll<()>, <tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}::{closure#0}>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:486:19
  12: <tokio::runtime::scheduler::current_thread::CoreGuard>::block_on::<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:829:44
  13: <tokio::runtime::scheduler::current_thread::CoreGuard>::enter::<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:906:68
  14: <tokio::runtime::context::scoped::Scoped<tokio::runtime::scheduler::Context>>::set::<<tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}, (alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>)>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../runtime/context/scoped.rs:40:9
  15: tokio::runtime::context::set_scheduler::<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>), <tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}>::{closure#0}
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/context.rs:186:38
  16: try_with<tokio::runtime::context::Context, tokio::runtime::context::set_scheduler::{closure_env#0}<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core, alloc::alloc::Global>, core::option::Option<()>), tokio::runtime::scheduler::current_thread::{impl#9}::enter::{closure_env#0}<tokio::runtime::scheduler::current_thread::{impl#9}::block_on::{closure_env#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>, core::option::Option<()>>>, (alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core, alloc::alloc::Global>, core::option::Option<()>)>
             at .../src/thread/local.rs:463:12
  17: <std::thread::local::LocalKey<tokio::runtime::context::Context>>::with::<tokio::runtime::context::set_scheduler<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>), <tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}>::{closure#0}, (alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>)>
             at .../src/thread/local.rs:427:20
  18: tokio::runtime::context::set_scheduler::<(alloc::boxed::Box<tokio::runtime::scheduler::current_thread::Core>, core::option::Option<()>), <tokio::runtime::scheduler::current_thread::CoreGuard>::enter<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>::{closure#0}>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/context.rs:186:17
  19: <tokio::runtime::scheduler::current_thread::CoreGuard>::enter::<<tokio::runtime::scheduler::current_thread::CoreGuard>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, core::option::Option<()>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:906:27
  20: <tokio::runtime::scheduler::current_thread::CoreGuard>::block_on::<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:819:24
  21: {closure#0}<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:216:33
  22: tokio::runtime::context::runtime::enter_runtime::<<tokio::runtime::scheduler::current_thread::CurrentThread>::block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>::{closure#0}, ()>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../runtime/context/runtime.rs:65:16
  23: block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../scheduler/current_thread/mod.rs:204:9
  24: <tokio::runtime::runtime::Runtime>::block_on_inner::<core::pin::Pin<&mut dyn core::future::future::Future<Output = ()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/runtime.rs:379:52
  25: block_on<core::pin::Pin<&mut dyn core::future::future::Future<Output=()>>>
             at .................................................../home/runner/.cargo.................................................../registry/src/index.crates.io-1949cf8c6b5b557f/tokio-1.54..../src/runtime/runtime.rs:348:18
  26: case_2_backtick
             at ./tests/hybrid_udtf.rs:1029:1
  27: hybrid_udtf::hybrid_field_path_payload::case_2_backtick::{closure#0}
             at ./tests/hybrid_udtf.rs:1029:10
  28: <hybrid_udtf::hybrid_field_path_payload::case_2_backtick::{closure#0} as core::ops::function::FnOnce<()>>::call_once
             at .../src/ops/function.rs:250:5
  29: <fn() -> core::result::Result<(), alloc::string::String> as core::ops::function::FnOnce<()>>::call_once
             at .../src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

To view more test analytics, go to the Test Analytics Dashboard
📋 Got 3 mins? Take this short survey to help us improve Test Analytics.

@kamronis
kamronis force-pushed the feat/sq8-quantized-refinement branch from fdde5c4 to 3184048 Compare November 30, 2026 14:04
@Xuanwo
Xuanwo merged commit 2689331 into lance-format:main Nov 30, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-docs Documentation A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-python Python bindings enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants