Skip to content

Deferred threshold integration - #8246

Merged
agourlay merged 11 commits into
devfrom
Deferred-threshold-integration
Mar 2, 2026
Merged

agourlay merged 11 commits into
devfrom
Deferred-threshold-integration

Conversation

@IvanPleshkov

@IvanPleshkov IvanPleshkov commented Feb 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a deferred threshold for segments with a deferred internal id.

Part of the deferred points feature, described here:
https://www.notion.so/qdrant/Deferred-points-in-appendable-segments-311674779d33808a9e97f9449267b2f6

Changes list

This PR adds two new fields into Segment struct:

deferred_points_threshold_bytes: Option<NonZeroUsize>,
deferred_internal_id: Option<PointOffsetType>,

deferred_points_threshold_bytes is presented in each segment, including indexed ones; it's just a propagation data from the collection - the value is Some if prevent_unoptimized = true and indexing_threshold > 0.

Segment owns the logic of deferred points and decided himself if he has deferred points inside.
On the segment level, we disable the deferred points feature in case when:

  • Segment is non-appendable
  • There are no dense vector storages

The segment decides that he has deferred points, he sets Some for deferred_internal_id, which describes the start internal ID to filter in read operations (including deferred_internal_id).

PR has a function update_deferred_internal_id(). It computes the deferred ID from vector storage layout sizes, taking the minimum across all non-multivector data. Called on segment creation/load and after each point insertion (put_all_vectors, upsert_vector, insert).

has_deferred_points() — quick check used by the indexing optimizer to trigger optimization on segments that have deferred points, ensuring they get indexed promptly.

Threshold derived from config — get_deferred_points_threshold_bytes() on OptimizersConfig returns Some(indexing_threshold_kb * 1024) when prevent_unoptimized == true, None otherwise.

All callers updated — every call site for build_segment, load_segment, SegmentBuilder::build, proxy_all_segments, and snapshot_all_segments now passes the threshold (mostly None in tests/edge).

Future work

For simpler review, multivectors and sparse vectors will be applied in the next changes of this milestone (it's marked in the design document plan).

@coderabbitai coderabbitai 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.

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@lib/segment/src/segment/segment_ops.rs`:
- Around line 665-689: The current logic bails out early if
self.deferred_internal_id.is_none(), preventing recomputation when new writes
push vectors past deferred_threshold; change the condition to only skip when
!self.is_appendable() || self.config().vector_data.is_empty() so the code always
recomputes from deferred_threshold when possible. In the deferred_threshold
branch, compute deferred_id by iterating self.vector_data.values() and calling
vector_data.vector_storage.borrow().get_deferred_id(deferred_threshold), then if
a valid min deferred_id exists and (deferred_id as usize) <
self.total_point_count() set self.deferred_internal_id = Some(deferred_id) else
set self.deferred_internal_id = None to clear stale cache values.

In `@lib/segment/src/vector_storage/vector_storage_base.rs`:
- Around line 214-221: The get_deferred_id implementation currently uses floor
division (deferred_threshold / size_per_vector) which underestimates the first
crossing offset for non-multiples; change to ceiling division so any leftover
bytes push to the next vector. Replace the computation of deferred_id in
get_deferred_id to use ceil(div) logic (e.g. (deferred_threshold +
size_per_vector - 1) / size_per_vector or equivalent safe integer math), then
clamp the result with .min(self.total_vector_count()) and cast to
PointOffsetType as before; reference get_deferred_id, deferred_threshold,
size_per_vector, deferred_id, and total_vector_count.
- Around line 268-287: The early-return is using an off-by-one index and thus
short-circuits incorrectly: change the precheck call from
self.inner_vectors_count_up_to(total as PointOffsetType - 1) to
self.inner_vectors_count_up_to(total as PointOffsetType) so the cumulative bytes
are computed for the full range, and keep the comparison against
deferred_threshold (>=) to return total when the total cumulative bytes meet or
exceed the threshold; ensure the rest of the binary search still searches [0,
total) using inner_vectors_count_up_to(mid as PointOffsetType) and returns
Some(lo as PointOffsetType) as before.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7084b5d and 081e457.

📒 Files selected for processing (43)
  • lib/collection/src/collection_manager/fixtures.rs
  • lib/collection/src/collection_manager/optimizers/config_mismatch_optimizer.rs
  • lib/collection/src/collection_manager/optimizers/indexing_optimizer.rs
  • lib/collection/src/collection_manager/optimizers/merge_optimizer.rs
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/collection/src/optimizers_builder.rs
  • lib/collection/src/shards/local_shard/mod.rs
  • lib/collection/src/shards/local_shard/snapshot.rs
  • lib/collection/src/shards/local_shard/snapshot_tests.rs
  • lib/collection/src/tests/mod.rs
  • lib/collection/src/update_workers/optimization_worker.rs
  • lib/edge/src/lib.rs
  • lib/segment/benches/multi_vector_search.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/mod.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/src/segment_constructor/segment_builder.rs
  • lib/segment/src/segment_constructor/segment_constructor_base.rs
  • lib/segment/src/segment_constructor/simple_segment_constructor.rs
  • lib/segment/src/vector_storage/multi_dense/appendable_mmap_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/multi_dense/simple_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/multi_dense/volatile_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/vector_storage_base.rs
  • lib/segment/tests/integration/byte_storage_hnsw_test.rs
  • lib/segment/tests/integration/byte_storage_quantization_test.rs
  • lib/segment/tests/integration/fixtures/segment.rs
  • lib/segment/tests/integration/multivector_filtrable_hnsw_test.rs
  • lib/segment/tests/integration/multivector_quantization_test.rs
  • lib/segment/tests/integration/payload_index_test.rs
  • lib/segment/tests/integration/segment_builder_test.rs
  • lib/segment/tests/integration/segment_on_disk_snapshot.rs
  • lib/segment/tests/integration/segment_tests.rs
  • lib/segment/tests/integration/sparse_discover_test.rs
  • lib/segment/tests/integration/sparse_vector_index_search_tests.rs
  • lib/shard/src/operations/optimization.rs
  • lib/shard/src/optimize.rs
  • lib/shard/src/optimizers/indexing_optimizer.rs
  • lib/shard/src/optimizers/segment_optimizer.rs
  • lib/shard/src/segment_holder/mod.rs
  • lib/shard/src/segment_holder/snapshot.rs
  • lib/shard/src/segment_holder/tests.rs

Comment thread lib/segment/src/segment/segment_ops.rs Resolved
Comment thread lib/segment/src/segment/segment_ops.rs Resolved
@qdrant qdrant deleted a comment from coderabbitai Bot Feb 27, 2026
Comment thread lib/segment/src/segment/segment_ops.rs Resolved
@IvanPleshkov
IvanPleshkov marked this pull request as draft February 27, 2026 10:47
@agourlay agourlay modified the milestone: deferred updates Feb 27, 2026
@IvanPleshkov
IvanPleshkov marked this pull request as ready for review February 27, 2026 16:45
coderabbitai[bot]

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

@generall
generall self-requested a review February 27, 2026 18:32
@agourlay
agourlay merged commit 30cf433 into dev Mar 2, 2026
16 checks passed
@agourlay
agourlay deleted the Deferred-threshold-integration branch March 2, 2026 08:57
@qdrant qdrant deleted a comment from coderabbitai Bot Mar 2, 2026
generall pushed a commit that referenced this pull request Mar 26, 2026
* Deferred threshold integration

* update deferred id

* apply update_deferred_internal_id

* fix segment inspector

* use avaliable bytes count

* renamings

* review remarks

* review remarks

* move has_deferred_points

* remove todo

* update comments
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* Deferred threshold integration

* update deferred id

* apply update_deferred_internal_id

* fix segment inspector

* use avaliable bytes count

* renamings

* review remarks

* review remarks

* move has_deferred_points

* remove todo

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants