Repository navigation
Conversation
xuanyu-z
marked this pull request as ready for review
November 4, 2026 15:04
Contributor
There was a problem hiding this comment.
consolidate_selected makes the caller responsible for total rewrite work: the full selection is processed without an aggregate row cap.
The documented recall risk remains when older distributions are encoded with the newest model. Prefer sources sharing that model, or check representative ANN recall before consolidating across models.
Contributor
|
@claude review |
`OptimizeOptions::consolidate_segments` names the segments of one vector index to consolidate, instead of the newest ones that fit the row budget. Any segments may be chosen, so older segments that have lost most of their rows to deletes can be rewritten. Each selected segment is re-encoded from its current fragments with the model of the index's newest segment, which drops deleted rows. Selected segments are packed whole, in index order, into outputs of at most `max_rows_per_segment` live rows. A selection must name one index and carry a row budget; reading more than the budget is an error rather than a shorter selection. Selected segments the index no longer has are skipped with a warning. Commit validation is the same per-source check bounded consolidation already uses.
Drop the separate planner and multi-output packing: a selection is the same consolidation with explicit sources, re-encoded into one segment.
Also note the recall trade-off of re-encoding sources under another model.
… segment size A selection whose segments share one model keeps it. Otherwise a model is trained on the selected rows, since encoding data under a model trained on other data loses recall. max_rows_per_segment now packs a selection's output into several segments, so a single large segment can be split.
A segment's output holds only live rows, so packing by physical rows left outputs far below the limit when their fragments carry deletions, and a second pass packed them the same way again. Tasks still bound physical rows. The limits are now checked before a model is trained, so a request that can't be satisfied trains and writes nothing.
xuanyu-z
force-pushed
the
feat/consolidate-selected-vector-segments
branch
from
November 9, 2026 18:46
9e05200 to
bd72d08
Compare
A selection rejected any fragment larger than its task or segment limit, so a caller whose segment size was below a fragment's rows failed on every attempt. Such a fragment now gets a task and an output of its own; bounded consolidation still rejects a fragment larger than its task limit. Also names consolidate::is_consolidation and train_model_segment's segment.
Xuanwo
approved these changes
Nov 10, 2026
Xuanwo
added a commit
to kamronis/lance
that referenced
this pull request
Nov 14, 2026
Brings the result-cache branch onto main e602c45, preserving the merged cross-column refinement (lance-format#9127), query-listing generation token (lance-format#10619), segment-contract rejection (lance-format#10761) and manifest/index replacement semantics (lance-format#10698).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Bounded consolidation (
OptimizeOptions::consolidate(max_rows)) only merges the newest segments of a vector index. When rows are rewritten, their old copies stay as deleted rows in older segments, which keep their entries. Nothing ever rewrites those segments, so on a table whose rows churn, both the segment count and the share of dead entries keep growing.OptimizeOptions::consolidate_selected(index_name, Vec<Uuid>)lets the caller name the segments of one index to consolidate, wherever they sit. It reuses bounded consolidation's planning, execution and commit, with these differences:max_rows_per_segment, the output is packed from whole fragments into segments of at most that many live rows, so a single large segment can be split. Deleted rows don't count, since the output doesn't hold them.max_rows_per_taskstill bounds the physical rows a task reads. Fragments are never split, so a fragment larger than either limit gets a task and an output of its own instead of failing the request. Bounded consolidation rejects a fragment larger than its task limit.max_rows_to_consolidatewith a selection is rejected rather than quietly shortening it.flowchart TD A["consolidate_selected(index, segments)"] --> B{Selected segments<br/>share one model?} B -- yes --> C[Re-encode with that model<br/>lossless, drops deleted rows] B -- no --> D["Train a model on the selected rows<br/>(written outside the manifest)"] D --> E[Encode the selected rows with it] C --> F{max_rows_per_segment set?} E --> F F -- no --> G[One output segment] F -- yes --> H[Pack whole fragments into outputs<br/>of at most that many rows] G --> I["Commit: outputs cover every surviving<br/>source fragment exactly once"] H --> IWhy never borrow another segment's model. In a benchmark with 1.5M rows, IVF_PQ and strongly drifted data (recall@10 at nprobes 10), keeping each segment's own model gave 0.50. Retraining on all rows gave 0.46–0.48. Re-encoding the older rows with the newest model gave 0.36, and only 0.20 for queries on the older data. With no drift, all three gave 0.48. So a selection uses either its own shared model or one trained on its own rows.
Several outputs replace their sources together, so the commit check now works per index: the outputs must cover every surviving source fragment exactly once between them, and none may overlap.
A selection must be non-empty, have no duplicates and name exactly one index (the constructor sets it). It can't be combined with retrain, partition rebalancing or
num_indices_to_merge.max_rows_per_taskstill bounds the re-encoding tasks.max_rows_per_segmentis accepted only with a selection; bounded consolidation still rejects it.Other changes:
uuidmoves from a dev-dependency to a dependency oflance-index.OptimizeOptionsis#[non_exhaustive], so the new field is not a breaking change.Tests
selected_segments_with_different_models_are_retrained(stable and non-stable row IDs): selects the two older of three separately trained segments after deletes. It checks that:a_shared_model_selection_keeps_its_model: a segment and an append encoded under its model are consolidated under that same model.a_retrained_rq_selection_keeps_the_shared_rotation: IVF_RQ segments that share one rotation but train their own centroids are consolidated. The output has new centroids under that same rotation, and queries match brute force.a_selection_packs_its_output_and_splits_a_segment: two fragments are consolidated into one segment, which is then split back into two outputs of one fragment each under its own model.deleted_rows_do_not_count_toward_the_segment_limit: two half-deleted fragments fit one output at a limit equal to one fragment's physical rows.a_fragment_larger_than_the_limits_is_an_output_of_its_own: with both limits at half a fragment, each selected fragment becomes its own output, and queries match brute force.a_selected_segment_already_removed_is_skipped: when a selected segment has been removed, the rest is still rewritten. A selection with nothing left plans nothing.a_selection_commits_over_concurrent_deletes_and_appends: a delete in a selected source and a new appended segment land between plan and commit. The commit still succeeds.incomplete_or_duplicate_results_cannot_replace_sources: now also covers overlapping outputs.invalid_selections_are_rejected: covers each of these:test_fragment_limited_sample_spans_every_fragment(vector columns with and without nulls): training on a listed subset of fragments samples each in proportion to its rows, whatever order the fragments are listed in.cargo nextest run -p lance --lib 'index::optimize'and the sampling test pass, and clippy (-D warnings) and fmt are clean. I broke each new branch in turn, and every change fails a test:Limitations
Not covered by a test: clearing the partition count when a segment's parameters are derived from its index rather than its stored details (the test index stores details that leave the count unset already).