Skip to content

Correct calculation of deferred point counts - #8366

Merged
JojiiOfficial merged 16 commits into
devfrom
correct-point-count-usage-deferred-points
Mar 19, 2026
Merged

JojiiOfficial merged 16 commits into
devfrom
correct-point-count-usage-deferred-points

Conversation

@JojiiOfficial

@JojiiOfficial JojiiOfficial commented Mar 11, 2026 •

Copy link
Copy Markdown
Member

Since we now exclude some points from read operations, we have to adjust the determination of point-counts in some places. Additionally we'd like to differentiate between visible and deferred points in telemetry / SegmentInfo.
This PR implements those changes.


Specifically this PR implements/changes the following:

  1. Correct calculation of available, non-deferred points
  2. Exclude deferred points from point count in some places where they are treated as hidden
  3. Adjust point counts in ProxySegment (including deletions from proxy segments)
  4. Revert SegmentInfo changes from previous PRs.
  5. Changes e2e tests to use telemetry instead of CollectionInfo to make them pass after change in 4.

Comment thread lib/edge/src/scroll.rs Resolved
@JojiiOfficial JojiiOfficial added this to the deferred updates milestone Mar 12, 2026
@JojiiOfficial
JojiiOfficial marked this pull request as ready for review March 12, 2026 14:10

@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: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
lib/collection/src/collection_manager/segments_searcher.rs (1)

687-700: ⚠️ Potential issue | 🟠 Major

Don't let a zero estimate suppress the segment search.

available_point_count_without_deferred_estimated() is only an estimate. If it drops to 0 here, sampling_limit() returns 0 and this segment is never searched, which can hide valid visible points. Please fall back to the unsampled path when the estimate is zero/uncertain instead of sampling with a zero-sized segment.

One safe fallback
-    let segment_points = read_segment.available_point_count_without_deferred_estimated();
+    let estimated_segment_points =
+        read_segment.available_point_count_without_deferred_estimated();
+    let disable_sampling_for_segment =
+        estimated_segment_points == 0 && read_segment.available_point_count() > 0;
     let segment_config = read_segment.config();
 
-    let top = if use_sampling {
+    let top = if use_sampling && !disable_sampling_for_segment {
         let ef_limit = search_params
             .params
             .and_then(|p| p.hnsw_ef)
             .or_else(|| get_hnsw_ef_construct(segment_config, search_params.vector_name));
         sampling_limit(
             search_params.top,
             ef_limit,
-            segment_points,
+            estimated_segment_points,
             segment_query_context.available_point_count(),
         )
     } else {
         search_params.top
     };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/collection/src/collection_manager/segments_searcher.rs` around lines 687
- 700, The estimate from
read_segment.available_point_count_without_deferred_estimated() can be zero and
should not force sampling to produce top=0; modify the logic in the branch that
uses use_sampling so that if segment_points == 0 (or otherwise uncertain) you
skip sampling and fall back to the unsampled path: detect segment_points == 0
after calling available_point_count_without_deferred_estimated(), and in that
case avoid calling sampling_limit(...) (or set use_sampling=false / compute top
from search_params.top and segment_query_context.available_point_count()
instead) so the segment is still searched; update the code around use_sampling,
sampling_limit(...), and related variables (read_segment, segment_config,
search_params, get_hnsw_ef_construct,
segment_query_context.available_point_count()) to implement this fallback.
docs/redoc/master/openapi.json (1)

12752-12785: ⚠️ Potential issue | 🟡 Minor

Add docs for the new public counter.

Line 12752 makes num_deferred_points part of the required API contract, but Lines 12782-12785 still leave it undocumented. Please describe how it relates to num_points—for example, whether num_points already excludes deferred points and what invariant clients can rely on. Based on learnings: docs/redoc/master/openapi.json is auto-generated from the REST schemas; update the Rust schema/doc comments rather than this JSON directly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/redoc/master/openapi.json` around lines 12752 - 12785, The OpenAPI JSON
added num_deferred_points to the required contract but lacks documentation and
invariants; update the Rust REST schema comments (not the generated JSON) for
the struct that defines these fields—add a doc comment on the
num_deferred_points field explaining what it counts, how it relates to
num_points (e.g., whether num_points excludes deferred points or includes them),
and any invariants clients can rely on (e.g., num_points = indexed points +
num_deferred_points or num_points excludes deferred points and num_vectors
represents indexed vectors). Edit the Rust struct field comments for
num_deferred_points and, if needed, clarify num_points in the same struct
(referencing the fields num_deferred_points and num_points and the schema that
references SegmentType) so the OpenAPI generator will emit the descriptive JSON.
Ensure comments are precise and update any serialization/serde attributes if
they affect the generated docs.
♻️ Duplicate comments (2)
lib/collection/src/shards/local_shard/scroll.rs (1)

372-380: ⚠️ Potential issue | 🟠 Major

Avoid zero-weighting segments that already returned random candidates.

This weight is now derived from an estimated non-deferred count. If that estimate hits 0 while read_random_filtered() still produced visible points, the segment gets starved by WeightedIndex and random scroll becomes biased. At minimum, use the returned candidate count as a floor for the weight until an exact non-deferred count exists.

Minimal guard against starvation
-                (
-                    read_segment.available_point_count_without_deferred_estimated(),
-                    read_segment.read_random_filtered(
-                        limit,
-                        filter.as_ref(),
-                        &is_stopped,
-                        &hw_counter,
-                    ),
-                )
+                let point_ids = read_segment.read_random_filtered(
+                    limit,
+                    filter.as_ref(),
+                    &is_stopped,
+                    &hw_counter,
+                );
+                let point_count = read_segment
+                    .available_point_count_without_deferred_estimated()
+                    .max(point_ids.len());
+
+                (point_count, point_ids)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/collection/src/shards/local_shard/scroll.rs` around lines 372 - 380, The
segment weight is being set from
read_segment.available_point_count_without_deferred_estimated() which can be
zero while read_segment.read_random_filtered(...) still returned candidates,
causing WeightedIndex starvation; change the logic that constructs the tuple
(weight, candidates) to compute weight = max(estimated_non_deferred_count,
returned_candidates_count) (i.e., call read_random_filtered first, get the
number of returned candidates, then use that count as a floor for the estimated
weight) so the returned candidate count from read_random_filtered() prevents
zero-weighting until an exact count exists; update any variables or tuple
ordering around read_segment.available_point_count_without_deferred_estimated()
and read_random_filtered() accordingly.
lib/edge/src/scroll.rs (1)

264-272: ⚠️ Potential issue | 🟠 Major

Keep segments with returned candidates eligible for random selection.

This uses the same estimated non-deferred count as the random-scroll weight. If the estimate underflows to 0, a segment that already returned visible candidates here can never be picked in the weighted phase. Please floor the weight by the candidate count, or otherwise avoid zero-weighting non-empty candidate lists.

Minimal starvation guard
-                let point_count = segment.available_point_count_without_deferred_estimated();
                 let point_ids = segment.read_random_filtered(
                     limit,
                     filter,
                     &AtomicBool::new(false),
                     &hw_counter,
                 );
+                let point_count = segment
+                    .available_point_count_without_deferred_estimated()
+                    .max(point_ids.len());
 
                 (point_count, point_ids)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/edge/src/scroll.rs` around lines 264 - 272, The segment weight uses
available_point_count_without_deferred_estimated() which can underflow to 0 and
starve segments that just returned candidates; after calling
segment.read_random_filtered(...) capture the actual returned candidate count
from point_ids.len() and floor the estimated point_count with that value (e.g.
set point_count = max(point_count, point_ids.len() as _)) so non-empty point_ids
never produce a zero weight; update references around point_count, point_ids,
available_point_count_without_deferred_estimated, and read_random_filtered
accordingly.
🤖 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/entry/entry_point.rs`:
- Around line 200-201: The new required trait method
available_point_count_without_deferred_estimated breaks external implementors
and the suggested default self.available_point_count() loses deferred-aware
semantics; instead add a new trait method deferred_point_count_estimated(&self)
-> usize with a sensible default (0) and implement
available_point_count_without_deferred_estimated(&self) -> usize as
self.available_point_count().saturating_sub(self.deferred_point_count_estimated()),
so existing implementors keep current behavior and types that track deferred
points (e.g., Segment implementations) can override
deferred_point_count_estimated(), while ProxySegment can either rely on the
default or explicitly override if needed.

In `@lib/segment/src/segment/entry.rs`:
- Around line 510-514: vectors_size_bytes is computed from only visible points
(num_points) but deferred vectors still consume storage; change the calculation
to include deferred points by using both
available_point_count_without_deferred_estimated() and
deferred_point_count_estimated() (e.g., compute total_points = num_points +
num_deferred_points) and multiply total_average_vectors_size_bytes by that total
when setting vectors_size_bytes so deferred vectors are accounted for.
- Around line 943-948: The helper
available_point_count_without_deferred_estimated() is estimate-based but is
being used by exact/reporting call sites (size_info() and filterless
CardinalityEstimation); add a new exact live counter and keep the existing
heuristic for heuristic paths only: introduce a new method (e.g.,
available_point_count_non_deferred_exact()) that computes the exact non-deferred
count by using id_tracker.borrow().available_point_count() and subtracting a
live deferred count (implement deferred_point_count_live() that derives deferred
points from current live mappings, not the estimated boundary), update
size_info() and the filterless CardinalityEstimation fast path to call
available_point_count_non_deferred_exact(), and leave
available_point_count_without_deferred_estimated() for heuristic/estimated
usages only.

In `@lib/shard/src/proxy_segment/segment_entry.rs`:
- Around line 735-738: The method
available_point_count_without_deferred_estimated() currently returns
self.available_point_count(), which ends up including deferred points; change it
to read the wrapped segment's corresponding method instead: obtain the
wrapped_segment guard (wrapped_segment.get().read() or the same guard pattern
used elsewhere) and call
wrapped_segment_guard.available_point_count_without_deferred_estimated() so it
excludes deferred points consistently (see the existing correct usage at the
earlier call site that invokes
wrapped_segment_guard.available_point_count_without_deferred_estimated()).

---

Outside diff comments:
In `@docs/redoc/master/openapi.json`:
- Around line 12752-12785: The OpenAPI JSON added num_deferred_points to the
required contract but lacks documentation and invariants; update the Rust REST
schema comments (not the generated JSON) for the struct that defines these
fields—add a doc comment on the num_deferred_points field explaining what it
counts, how it relates to num_points (e.g., whether num_points excludes deferred
points or includes them), and any invariants clients can rely on (e.g.,
num_points = indexed points + num_deferred_points or num_points excludes
deferred points and num_vectors represents indexed vectors). Edit the Rust
struct field comments for num_deferred_points and, if needed, clarify num_points
in the same struct (referencing the fields num_deferred_points and num_points
and the schema that references SegmentType) so the OpenAPI generator will emit
the descriptive JSON. Ensure comments are precise and update any
serialization/serde attributes if they affect the generated docs.

In `@lib/collection/src/collection_manager/segments_searcher.rs`:
- Around line 687-700: The estimate from
read_segment.available_point_count_without_deferred_estimated() can be zero and
should not force sampling to produce top=0; modify the logic in the branch that
uses use_sampling so that if segment_points == 0 (or otherwise uncertain) you
skip sampling and fall back to the unsampled path: detect segment_points == 0
after calling available_point_count_without_deferred_estimated(), and in that
case avoid calling sampling_limit(...) (or set use_sampling=false / compute top
from search_params.top and segment_query_context.available_point_count()
instead) so the segment is still searched; update the code around use_sampling,
sampling_limit(...), and related variables (read_segment, segment_config,
search_params, get_hnsw_ef_construct,
segment_query_context.available_point_count()) to implement this fallback.

---

Duplicate comments:
In `@lib/collection/src/shards/local_shard/scroll.rs`:
- Around line 372-380: The segment weight is being set from
read_segment.available_point_count_without_deferred_estimated() which can be
zero while read_segment.read_random_filtered(...) still returned candidates,
causing WeightedIndex starvation; change the logic that constructs the tuple
(weight, candidates) to compute weight = max(estimated_non_deferred_count,
returned_candidates_count) (i.e., call read_random_filtered first, get the
number of returned candidates, then use that count as a floor for the estimated
weight) so the returned candidate count from read_random_filtered() prevents
zero-weighting until an exact count exists; update any variables or tuple
ordering around read_segment.available_point_count_without_deferred_estimated()
and read_random_filtered() accordingly.

In `@lib/edge/src/scroll.rs`:
- Around line 264-272: The segment weight uses
available_point_count_without_deferred_estimated() which can underflow to 0 and
starve segments that just returned candidates; after calling
segment.read_random_filtered(...) capture the actual returned candidate count
from point_ids.len() and floor the estimated point_count with that value (e.g.
set point_count = max(point_count, point_ids.len() as _)) so non-empty point_ids
never produce a zero weight; update references around point_count, point_ids,
available_point_count_without_deferred_estimated, and read_random_filtered
accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2411d95f-5777-4604-b71c-1e9d9068ac78

📥 Commits

Reviewing files that changed from the base of the PR and between e7e5f4c and ab94a13.

📒 Files selected for processing (12)
  • docs/redoc/master/openapi.json
  • lib/collection/src/collection_manager/segments_searcher.rs
  • lib/collection/src/shards/local_shard/indexed_only.rs
  • lib/collection/src/shards/local_shard/scroll.rs
  • lib/edge/src/scroll.rs
  • lib/segment/src/data_types/query_context.rs
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/src/types.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
💤 Files with no reviewable changes (1)
  • lib/segment/src/segment/segment_ops.rs

Comment thread lib/segment/src/entry/entry_point.rs Resolved
Comment thread lib/segment/src/segment/entry.rs Resolved
Comment thread lib/segment/src/segment/entry.rs Resolved
@qdrant qdrant deleted a comment from coderabbitai Bot Mar 12, 2026
coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Mar 12, 2026
@JojiiOfficial
JojiiOfficial force-pushed the correct-point-count-usage-deferred-points branch from 5f98348 to a4181df Compare March 13, 2026 09:41

@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: 1

🧹 Nitpick comments (1)
docs/redoc/master/openapi.json (1)

12782-12786: Add a field description for API clarity.

Line 12782 introduces num_deferred_points without a description; please document what “deferred” means for API consumers in the source REST schema, then regenerate this file.

Based on learnings, docs/redoc/master/openapi.json is auto-generated from REST schemas, so field docs should be added in lib/api/src/rest/schema.rs.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/redoc/master/openapi.json` around lines 12782 - 12786, The OpenAPI
output lacks a description for the field num_deferred_points; update the REST
schema source by adding a descriptive docstring/attribute for the
num_deferred_points field in lib/api/src/rest/schema.rs (on the struct or field
definition that defines num_deferred_points) explaining what “deferred” means
for consumers and any constraints, then rebuild/regenerate the OpenAPI JSON so
docs/redoc/master/openapi.json includes the new description.
🤖 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/shard/src/proxy_segment/segment_entry.rs`:
- Line 447: The subtraction currently uses self.deleted_points.len() (which
includes deferred deletions) against
wrapped_segment_guard.available_point_count_without_deferred_estimated(),
double-counting deferred deletions; change the logic in the estimate_point_count
and num_points code paths to subtract only deleted points that are
visible/non-deferred. Specifically, replace using self.deleted_points.len() with
a computed deleted_visible_count (filtering self.deleted_points to exclude
deferred deletions—e.g., using whatever deferred tracking structure exists—or
otherwise count only deleted IDs that are considered in the “available” set)
before subtracting from
wrapped_segment_guard.available_point_count_without_deferred_estimated(); update
the same logic around lines referencing
wrapped_segment_guard.available_point_count_without_deferred_estimated(),
estimate_point_count, and num_points.

---

Nitpick comments:
In `@docs/redoc/master/openapi.json`:
- Around line 12782-12786: The OpenAPI output lacks a description for the field
num_deferred_points; update the REST schema source by adding a descriptive
docstring/attribute for the num_deferred_points field in
lib/api/src/rest/schema.rs (on the struct or field definition that defines
num_deferred_points) explaining what “deferred” means for consumers and any
constraints, then rebuild/regenerate the OpenAPI JSON so
docs/redoc/master/openapi.json includes the new description.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 69f484a6-e71e-45e4-8b2f-392e1861aa8a

📥 Commits

Reviewing files that changed from the base of the PR and between 01a56ef and a4181df.

📒 Files selected for processing (12)
  • docs/redoc/master/openapi.json
  • lib/collection/src/collection_manager/segments_searcher.rs
  • lib/collection/src/shards/local_shard/indexed_only.rs
  • lib/collection/src/shards/local_shard/scroll.rs
  • lib/edge/src/scroll.rs
  • lib/segment/src/data_types/query_context.rs
  • lib/segment/src/entry/entry_point.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests.rs
  • lib/segment/src/types.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
💤 Files with no reviewable changes (1)
  • lib/segment/src/segment/segment_ops.rs

@coderabbitai

coderabbitai Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change adds explicit tracking and exclusion of deferred (hidden) points across segments and proxy segments. It introduces two new SegmentInfo fields (num_deferred_points, num_deleted_deferred_points), adds trait methods has_deferred_points and available_point_count_without_deferred, and removes older deferred-count APIs. The code replaces usages of available-point counting with the excluding-deferred variant in search/scroll/indexing paths, tracks deleted-deferred counts on Segment and ProxySegment (with constructor and delete logic updates), and updates tests to use the new APIs.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

Suggested reviewers

  • agourlay
  • timvisee
  • IvanPleshkov
🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Correct calculation of deferred point counts' directly summarizes the main change: fixing how deferred point counts are calculated and reported throughout the codebase.
Description check ✅ Passed The description is highly relevant, explaining the rationale for point-count adjustments, listing specific implementation details (5 numbered items), and matching the actual changeset across OpenAPI schema, segment operations, and test updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch correct-point-count-usage-deferred-points
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Tip

You can make CodeRabbit's review stricter and more nitpicky using the `assertive` profile, if that's what you prefer.

Change the reviews.profile setting to assertive to make CodeRabbit's nitpick more issues in your PRs.

@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: 2

🧹 Nitpick comments (1)
lib/shard/src/proxy_segment/tests.rs (1)

524-599: Please cover the reload path in this regression.

The new deferred accounting is also reconstructed during segment creation/loading, but this test only exercises a freshly built segment. A round-trip through load_segment() after deleting a deferred point would catch restart regressions in num_deferred_points and available_point_count_without_deferred().

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/shard/src/proxy_segment/tests.rs` around lines 524 - 599, Update the
test_proxy_deferred test to exercise the reload path: after deleting the
deferred points (the two delete_point calls that reduce num_deferred_points) and
the assertions that follow, persist and reload the segment via load_segment()
(i.e., create a new Wrapped/LockedSegment by calling the segment load API) and
re-create a new ProxySegment::new(LockedSegment::new(...)) and re-assert that
size_info().num_deferred_points and available_point_count_without_deferred()
still match the expected values and that estimate_point_count(None, &hw_counter)
is unchanged; place this round-trip check before you "Touch normal points" (the
delete of point 6) so reload covers only the deferred-deletion state.
🤖 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 694-706: The calculate_deferred_point_count function currently
counts deferred IDs that still have external mappings; change it to count
deleted deferred IDs instead by iterating from deferred_internal_id_if_any() and
counting internal_id entries where id_tracker.external_id(internal_id) is None;
make sure to call deferred_internal_id_if_any(), use id_tracker.borrow() once
(or otherwise avoid double-borrow inside the closure), and return that count so
Segment.deferred_deleted_count is initialized from deleted deferred IDs rather
than live mappings.

In `@lib/shard/src/proxy_segment/segment_entry.rs`:
- Around line 717-720: The deferred-delete counter deleted_deferred_count gets
incremented in SegmentEntry but is never reset when the pending delete queue is
cleared, causing num_deferred_points and
available_point_count_without_deferred() to go out of sync; update the code path
that clears deleted_points (e.g., in ProxySegment::propagate_to_wrapped() or the
method that empties the queue) to also reset self.deleted_deferred_count = 0 so
the counter stays consistent with deleted_points.len(), and keep the existing
increment logic where was_deleted && was_deferred_point is handled.

---

Nitpick comments:
In `@lib/shard/src/proxy_segment/tests.rs`:
- Around line 524-599: Update the test_proxy_deferred test to exercise the
reload path: after deleting the deferred points (the two delete_point calls that
reduce num_deferred_points) and the assertions that follow, persist and reload
the segment via load_segment() (i.e., create a new Wrapped/LockedSegment by
calling the segment load API) and re-create a new
ProxySegment::new(LockedSegment::new(...)) and re-assert that
size_info().num_deferred_points and available_point_count_without_deferred()
still match the expected values and that estimate_point_count(None, &hw_counter)
is unchanged; place this round-trip check before you "Touch normal points" (the
delete of point 6) so reload covers only the deferred-deletion state.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 405f8f9c-29a6-4031-85d8-2efd3a60d76f

📥 Commits

Reviewing files that changed from the base of the PR and between a4181df and e041666.

📒 Files selected for processing (14)
  • lib/collection/src/collection_manager/segments_searcher.rs
  • lib/collection/src/shards/local_shard/indexed_only.rs
  • lib/collection/src/shards/local_shard/scroll.rs
  • lib/edge/src/scroll.rs
  • lib/segment/src/data_types/query_context.rs
  • lib/segment/src/entry/entry_point.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_constructor_base.rs
  • lib/shard/src/proxy_segment/mod.rs
  • lib/shard/src/proxy_segment/segment_entry.rs
  • lib/shard/src/proxy_segment/tests.rs
🚧 Files skipped from review as they are similar to previous changes (5)
  • lib/edge/src/scroll.rs
  • lib/collection/src/shards/local_shard/scroll.rs
  • lib/segment/src/data_types/query_context.rs
  • lib/collection/src/collection_manager/segments_searcher.rs
  • lib/segment/src/segment/tests.rs

Comment thread lib/segment/src/segment/segment_ops.rs Resolved
@JojiiOfficial
JojiiOfficial force-pushed the correct-point-count-usage-deferred-points branch from e041666 to 9b251e8 Compare March 13, 2026 16:44
@JojiiOfficial
JojiiOfficial marked this pull request as draft March 13, 2026 16:44
@JojiiOfficial
JojiiOfficial marked this pull request as draft March 13, 2026 16:44
num_vectors,
num_indexed_vectors,
num_points: self.non_deferred_point_count_estimated(),
num_points: self.available_point_count(),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Reverting this change as discussed.
To get the amount of available points without deferred, one can subtract num_deferred_points from num_points. We can also add a field for that later if desired.

@JojiiOfficial
JojiiOfficial force-pushed the correct-point-count-usage-deferred-points branch from 85ab971 to 4521b8d Compare March 16, 2026 13:52
return response.json()['result']


def get_point_count_excluding_deferred():

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since this PR reverts previous changes to SegmentInfo, we have to use the new fields from telemetry for now.

@JojiiOfficial JojiiOfficial changed the title Don't account for deferred points in some places Correct calculation of deferred points Mar 16, 2026
@JojiiOfficial JojiiOfficial changed the title Correct calculation of deferred points Correct calculation of deferred point counts Mar 16, 2026
Comment thread lib/segment/src/segment/mod.rs Outdated
pub(crate) deferred_internal_id: Option<PointOffsetType>,
/// Amount of deleted deferred points. Must kept track of properly to be able
/// to calculate the amount of available deferred and visible points.
pub(crate) deferred_deleted_count: Option<usize>,

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the most important change in this PR.

We increase a Segment-level counter for each deletion of a deferred point. This way we can correctly calculate how much of the deleted points are deferred. This then allows us to correctly calculate the amount of non-deleted deferred and visible (non-deferred) points.

For correctness, we iterate over all deferred points once at segment load and count how many deferred points are deleted. With the result of this value we initialize the segments deferred_deleted_count.

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.

Because Some state is shared between deferred_internal_id and deferred_deleted_count (when one is some, a second one should be also some), I propose to create a struct like

pub struct DeferredPointStatus {
deferred_internal_id: Option<PointOffsetType>,
deferred_deleted_count: Option<usize>,
}

And use in segment:

deferred_points: Option<DeferredPointStatus >

We reduce the number of unnecessary checks/asserts in the PR

@JojiiOfficial
JojiiOfficial marked this pull request as ready for review March 16, 2026 14:38
@JojiiOfficial
JojiiOfficial requested review from agourlay and removed request for IvanPleshkov, agourlay and timvisee March 16, 2026 14:38
@JojiiOfficial
JojiiOfficial force-pushed the correct-point-count-usage-deferred-points branch from 6964a86 to 3df439e Compare March 19, 2026 08:43

let is_point_already_deleted = id_tracker.is_deleted_point(internal_id);

id_tracker.drop_internal(internal_id)?;

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.

We may upgrade drop_internal and return if the ID was deleted. Not for now, maybe in the future

Comment thread lib/segment/src/segment/mod.rs Outdated
pub(crate) deferred_internal_id: Option<PointOffsetType>,
/// Amount of deleted deferred points. Must kept track of properly to be able
/// to calculate the amount of available deferred and visible points.
pub(crate) deferred_deleted_count: Option<usize>,

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.

Because Some state is shared between deferred_internal_id and deferred_deleted_count (when one is some, a second one should be also some), I propose to create a struct like

pub struct DeferredPointStatus {
deferred_internal_id: Option<PointOffsetType>,
deferred_deleted_count: Option<usize>,
}

And use in segment:

deferred_points: Option<DeferredPointStatus >

We reduce the number of unnecessary checks/asserts in the PR

Comment thread lib/segment/src/segment/segment_ops.rs Resolved
Comment thread lib/segment/src/segment/entry.rs Resolved
Comment thread lib/shard/src/proxy_segment/mod.rs Resolved

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

I didnt found some critical points, all concerns are optional.
I like that this pr covers py tests and proxy segments, great job!

@JojiiOfficial
JojiiOfficial merged commit 3560403 into dev Mar 19, 2026
15 checks passed
@JojiiOfficial
JojiiOfficial deleted the correct-point-count-usage-deferred-points branch March 19, 2026 10:33
balaji-g42 added a commit to balaji-g42/qdrant that referenced this pull request Mar 19, 2026
Correct calculation of deferred point counts (qdrant#8366)
@coderabbitai coderabbitai Bot mentioned this pull request Mar 19, 2026
9 tasks done
generall added a commit that referenced this pull request Mar 26, 2026
* Don't account for deferred points in some places

# Conflicts:
#	lib/collection/src/shards/local_shard/scroll.rs

* Add in QueryContext

* Cover more places

* Coderabbit review remarks

* Properly count amount of deleted deferred points (#8386)

* Properly count amount of deleted deferred points

* Prevent double-counting of the same point

* Remove hints to estimations

* Properly handle counts in ProxySegment

* Add tests and fix deleted point count issue

* Adjusts tests + fix issues

* Separte fields for deferred points in telemetry (SegmentInfo)

* Remove deferred_points_count()

* openapi

* Fix test by manually calculating visible points

* Adjust ProxySegment test to revertion of SegmentInfo

* Throw error if collection was not found in telemetry (e2e Test)

* Update lib/segment/src/segment/segment_ops.rs

Co-authored-by: Andrey Vasnetsov <[email protected]>

* Make new fields in API optional

* Don't take range if no deferred point exist

* Review remarks

---------

Co-authored-by: Andrey Vasnetsov <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
* Don't account for deferred points in some places

# Conflicts:
#	lib/collection/src/shards/local_shard/scroll.rs

* Add in QueryContext

* Cover more places

* Coderabbit review remarks

* Properly count amount of deleted deferred points (#8386)

* Properly count amount of deleted deferred points

* Prevent double-counting of the same point

* Remove hints to estimations

* Properly handle counts in ProxySegment

* Add tests and fix deleted point count issue

* Adjusts tests + fix issues

* Separte fields for deferred points in telemetry (SegmentInfo)

* Remove deferred_points_count()

* openapi

* Fix test by manually calculating visible points

* Adjust ProxySegment test to revertion of SegmentInfo

* Throw error if collection was not found in telemetry (e2e Test)

* Update lib/segment/src/segment/segment_ops.rs

Co-authored-by: Andrey Vasnetsov <[email protected]>

* Make new fields in API optional

* Don't take range if no deferred point exist

* Review remarks

---------

Co-authored-by: Andrey Vasnetsov <[email protected]>
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