Skip to content

feat(index): build and query IVF_RQ through a PCA pre-transform - #9970

Open
beautygua wants to merge 5 commits into
lance-format:mainfrom
beautygua:feat/pca-ivf-rq-build
Open

beautygua wants to merge 5 commits into
lance-format:mainfrom
beautygua:feat/pca-ivf-rq-build

Conversation

@beautygua

@beautygua beautygua commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Base: main

Discussion Link: #9122

@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-deps Dependency updates A-format On-disk format: protos and format spec docs format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). labels Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Important

Format specification vote

This PR modifies the Lance format specification, so it requires 3 binding +1 votes from PMC members (excluding the proposer), at least one of them on the latest commit, and a minimum 72-hour voting period, weekends excluded, before it can merge. Vote by approving this PR (+1) or requesting changes (−1, a veto). See the voting process.

Approvals carry over across pushes, so a rebase or a typo fix does not send everyone back to re-vote. Whoever approves the latest commit is vouching that nothing substantive has changed since the earlier approvals; if something has, ask for fresh votes.

Status: ❌ Blocked — 0 of 3 required approvals

Approvals none (0/3)
Latest commit approved by none — one PMC member must approve the latest commit
Vetoes none
Voting period elapsed — ended Mon 2026-10-19 10:00 UTC (03:00 PDT)

Updated automatically by the format-spec vote gate, which re-checks every 15 minutes — just voted? Re-check now (press Run workflow; leave the input blank to re-check every open format PR). A PMC member may apply the format-waived label to waive the vote for a trivial edit (typo, wording, formatting).

@github-actions github-actions Bot added the enhancement New feature or request label Oct 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 Oct 14, 2026
Comment thread rust/lance/src/index/vector/pca.rs Outdated
}
let mean = sums;

let statistics = if sample_count >= input_dimension {

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.

Please use streaming scatter/covariance unconditionally here, matching the removal of Gram in #9967. This removes the centered sample buffer, PcaStatistics branching and train_from_centered call. N < D should still be supported when the sample's effective rank is sufficient for the requested output dimension.

Comment thread rust/lance/src/index/vector/utils.rs Outdated
///
/// Candidates are unique, invalid vectors are replaced from the same RNG
/// stream, and the returned offsets are sorted into the training order.
pub async fn sample_valid_vector_offsets_seeded(

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.

Please share candidate-row reading and the NULL/NaN/Inf predicate with the existing IVF sampler instead of maintaining a separate sampler and is_valid_pca_vector. Keep PCA's seeded RNG, returned row offsets and replenishment to a valid-sample target, so both streaming passes read the same sample without collecting the whole vector array. IVF currently filters finite values after sampling, so preserve that semantic difference when sharing the machinery.

@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Oct 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 Oct 16, 2026
@lance-gatekeeper lance-gatekeeper Bot added K-changes Latest Gatekeeper recommendation requests changes. and removed K-changes Latest Gatekeeper recommendation requests changes. labels Oct 19, 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 Oct 19, 2026
Train the model from the dataset and store it in index.idx under lance:pca, then project indexed and query vectors before IVF and quantization. PCA indexes record metadata version 4. Training parameters stay out of the manifest.
@beautygua
beautygua force-pushed the feat/pca-ivf-rq-build branch from 56262db to 5f7fb12 Compare November 3, 2026 08:29
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 3, 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: request changes.

The specification split is satisfied by merged #9968. Several independent implementation issues remain. Keep the PCA approach, restore the core build, and align the version-4 writer and reader with the merged row-address contract before merging.

Please mark this PR with the breaking-change label: lance::index::vector::VectorIndexParams::pre_transform adds a required field to public struct literals, so Rust callers constructing VectorIndexParams directly must initialize it.

Comment thread rust/lance/src/index/vector/builder.rs Outdated
quantizer,
quantizer.into(),
None,
self.ivf_pre_transformer(),

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.

PartitionAdjuster has no ivf_pre_transformer method, so this change prevents the core lance crate from compiling, including builds that do not use PCA. The helper exists only on IvfIndexBuilder; this adjuster has no PCA model. Preserve its existing no-pre-transform path unless model support is explicitly wired through.

Reproduced on this head with the pinned Rust 1.98.1 toolchain: cargo check -p lance --tests reports E0599 here: “no method named ivf_pre_transformer found for reference &PartitionAdjuster<'_>”.

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.

Fixed in 94a23f3: PartitionAdjuster again uses new_ivf_transformer_with_quantizer, preserving its existing no-pre-transform path and removing the unavailable builder-only helper call.

Comment thread rust/lance/src/index/vector/utils.rs Outdated
let piece = if take_n == finite.len() {
finite
} else {
finite.slice(0, take_n).as_fixed_size_list().clone()

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.

This expression prevents the core crate from compiling: finite is a concrete FixedSizeListArray, and its inherent slice already returns a FixedSizeListArray, which has no as_fixed_size_list method. Return finite.slice(0, take_n) directly; no downcast or clone is needed.

Reproduced on this head with the pinned Rust 1.98.1 toolchain: cargo check -p lance --tests reports E0599 at this line: “no method named as_fixed_size_list found for struct FixedSizeListArray”. This is an unconditional compile failure, rather than a failure limited to invoking the sampler.

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.

Fixed in 94a23f3: the sampler returns the concrete FixedSizeListArray slice directly, removing the invalid downcast call and redundant clone.

Comment thread rust/lance/src/io/exec/knn.rs Outdated
query = normalize_query_for_index(raw_index.as_ref(), query)?;
let policy = AutoProbePolicy::from_env(&query, raw_index.as_ref())?;
policy.apply(&mut query, q_c_dists.values(), raw_index.metric_type());
let (search_index, query) = raw_index

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.

The new tuple binding shadows the mutable query with an immutable one, but policy.apply(&mut query, ...) below still needs mutable access. This prevents the core lance crate from compiling for ordinary ANN queries as well as PCA queries. Bind the returned query as mut query so the existing probe policy can update it.

Reproduced on this head with the pinned Rust 1.98.1 toolchain: cargo check -p lance --tests reports E0596 at line 2680: “cannot borrow query as mutable, as it is not declared as mutable”, and points to this binding.

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.

Fixed in 029d292: the prepared query is now bound as mut query, allowing AutoProbePolicy::apply to borrow it mutably. This addresses the mutable-borrow error on the ANN query path.

/// of its [`IndexType`], including IVF_RQ without PCA.
pub fn compatibility_version(&self) -> u32 {
match (self.pre_transform.is_some(), self.index_type()) {
(true, IndexType::IvfRq) => VECTOR_PCA_INDEX_VERSION,

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.

This advertises version 4 without implementing its row-address domain. The merged PCA specification explicitly says version 4 retains physical row addresses from version 3, but IvfIndexBuilder::shuffle_dataset still uses .with_row_id() and merge_partitions writes ROW_ID_FIELD to auxiliary.idx. Neither path converts those logical IDs to physical addresses. This matters on stable-row-ID datasets, where the two values differ; an interoperable version-4 reader cannot interpret that identifier stream according to the advertised format.

Implement the version-4 identifier domain end to end before selecting this version, including its read/filter behavior and a multi-fragment stable-row-ID fixture that checks the persisted addresses. Merely renaming the column does not convert the values. The merged row-domain proposal #10299 is documentation-only and does not supply that implementation.

This finding is a mismatch between the selected version and the writer's source path. A runtime file round trip could not be run because cargo check -p lance --tests fails on the compile errors in this revision; incorrect runtime query results have not been reproduced.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 3, 2026
AutoProbePolicy::apply updates nprobes on the query returned by prepare_partition_query. The shadowed binding was immutable, so the lance crate failed to compile.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 3, 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 3, 2026
PartitionAdjuster has no PCA model, so it keeps the quantizer-only IVF transform. FixedSizeListArray::slice already returns that type, so the sampler no longer downcasts it.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 3, 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 3, 2026
The trainer and index.idx helpers sit in modules that are not public, so pub(crate) is redundant under the workspace Clippy deny.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 3, 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 3, 2026
Clippy denies an assertion whose condition is a comparison of two consts.
@lance-gatekeeper lance-gatekeeper Bot removed the K-changes Latest Gatekeeper recommendation requests changes. label Nov 9, 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: request changes.

The version-4 storage-contract finding remains: the writer and reader must honor the physical-row-address domain specified by merged #9968. Keep the PCA approach and satisfy that persisted-format contract before emitting version 4. The earlier compilation findings remain fixed.

Please mark this PR with the breaking-change label: lance::index::vector::VectorIndexParams::pre_transform adds a required field to public struct literals, so Rust callers constructing VectorIndexParams directly must initialize it.

@lance-gatekeeper lance-gatekeeper Bot added the K-changes Latest Gatekeeper recommendation requests changes. label Nov 9, 2026

This branch has not been deployed

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

Labels

A-deps Dependency updates A-format On-disk format: protos and format spec docs A-index Vector index, linalg, tokenizer A-java Java bindings + JNI A-python Python bindings enhancement New feature or request format-change A change to the format spec, which requires a vote. Remove if minor (e.g. fixing typo). K-changes Latest Gatekeeper recommendation requests changes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants