Skip to content

Filter deferred points in read operations Part 1 (Search, Scroll, Count) - #8283

Merged
JojiiOfficial merged 10 commits into
devfrom
filter-deferred-points-in-read-op
Mar 11, 2026
Merged

JojiiOfficial merged 10 commits into
devfrom
filter-deferred-points-in-read-op

Conversation

@JojiiOfficial

@JojiiOfficial JojiiOfficial commented Mar 3, 2026 •

Copy link
Copy Markdown
Member

Implements deferred point filtering for the following read operations:

  • Search
  • Count
  • Scroll

It also partially implements filtering in other read operations, such as facet, since some operations sometimes use the same functions. Therefore I suggest to wait with merging until the remaining read operations are implemented, which will be done in a separate PR to not make this PR too big.

This PR is best reviewed on per-commit level. However, the unit tests might be best to review at the end.

@JojiiOfficial JojiiOfficial changed the title [WIP] Filter deferred points in read op [WIP] Filter deferred points in read operationss Mar 3, 2026
@JojiiOfficial JojiiOfficial changed the title [WIP] Filter deferred points in read operationss [WIP] Filter deferred points in read operations Mar 3, 2026
@JojiiOfficial JojiiOfficial added this to the deferred updates milestone Mar 3, 2026
@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch from 85dc797 to 4bd14a7 Compare March 3, 2026 14:49
@JojiiOfficial JojiiOfficial changed the title [WIP] Filter deferred points in read operations [WIP] Filter deferred points in read operations Part 1 (Search, Scroll, Count) Mar 3, 2026
@JojiiOfficial JojiiOfficial changed the title [WIP] Filter deferred points in read operations Part 1 (Search, Scroll, Count) Filter deferred points in read operations Part 1 (Search, Scroll, Count) Mar 3, 2026
@JojiiOfficial
JojiiOfficial marked this pull request as ready for review March 3, 2026 18:11
coderabbitai[bot]

This comment was marked as resolved.

@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch from 9f4c85a to d7433a6 Compare March 3, 2026 19:42
coderabbitai[bot]

This comment was marked as resolved.

@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch from d7433a6 to 61c39f0 Compare March 3, 2026 19:58
coderabbitai[bot]

This comment was marked as resolved.

@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch from 61c39f0 to 7f19359 Compare March 4, 2026 08:42
coderabbitai[bot]

This comment was marked as resolved.

@JojiiOfficial
JojiiOfficial marked this pull request as draft March 4, 2026 09:43
@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch 2 times, most recently from c505e95 to fb9a5c6 Compare March 4, 2026 10:43
@agourlay

agourlay commented Mar 4, 2026

Copy link
Copy Markdown
Member

What about adding helper methods on the IdTracker instead of applying the same filters around the codebase?

Something like:

  trait IdTracker {

      fn iter_internal_visible(&self, deferred_from: Option<PointOffsetType>)
          -> Box<dyn Iterator<Item = PointOffsetType> + '_>
      {
          match deferred_from {
              None => self.iter_internal(),
              Some(d) => Box::new(self.iter_internal().take_while(move |&id| id < d)),
          }
      }

      fn iter_from_visible(&self, external_id: Option<PointIdType>, deferred_from: Option<PointOffsetType>)
          -> Box<dyn Iterator<Item = (PointIdType, PointOffsetType)> + '_>
      {
          match deferred_from {
              None => self.iter_from(external_id),
              Some(d) => Box::new(self.iter_from(external_id).filter(move |(_, iid)| *iid < d)),
          }
      }
  }

None => {
let filtered_points = payload_index.query_points(filter, &hw_counter, &is_stopped);
let filtered_points =
payload_index.query_points(filter, &hw_counter, &is_stopped, None);

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.

why are we not applying the deferred_id filter here?

the sparse vectors are always indexed even on an appendable segment

@JojiiOfficial JojiiOfficial Mar 4, 2026 •

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.

If I remember correctly, we decided to not filter sparse vectors since they are always indexed and there is no need to hide them.

I'll tackle sparse vectors in a separate PR 👍🏻

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.

Comment thread lib/segment/src/segment/segment_ops.rs Outdated
Self::is_internal_id_deferred(internal_id, self.deferred_internal_id)
}

pub fn is_internal_id_deferred(

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.

I think it is time to rebase and use the new official function for this :)

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.

I don't see a new function for this. We take internal ID as parameter here, where the new functions from #8279 take the external 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 can remove a duplicate method later because this PR will be merged earlier than #8279

Comment thread lib/segment/src/segment/segment_ops.rs Resolved
@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch 3 times, most recently from 9d45700 to c761a90 Compare March 4, 2026 16:18
@JojiiOfficial
JojiiOfficial marked this pull request as ready for review March 5, 2026 09:14
coderabbitai[bot]

This comment was marked as resolved.

@JojiiOfficial
JojiiOfficial force-pushed the filter-deferred-points-in-read-op branch from c761a90 to b1f3f8b Compare March 6, 2026 11:27
pub fn get_vector_context(
&self,
vector_name: &VectorName,
deferred_internal_id: Option<PointOffsetType>,

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 propose to remove ' deferred_internal_id ' here and move it to the higher level as a new VectorQueryContext::deferred_internal_id field. The motivation of the suggestion is to do like another help params: deleted points, hardware_counter ect

fn iter_random(&self) -> Box<dyn Iterator<Item = (PointIdType, PointOffsetType)> + '_>;

/// Iterate over all internal IDs. Optionally filter all deferred points.
fn iter_internal_visible(

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.

What if we move this filtering inside iter_internal? We will store a deferred id also as a field in the ID tracker by this proposal.
It's a question to discuss. I see pros and cons about it

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.

Motivation of such proposal:
There are new methods such as iter_random_visible and iter_from_visible. It would be nice if we can skip creation of this methods and use existing ones

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.

To be honest I don't think that adding this field to IdTracker makes it much cleaner. Also in my opinion, the caller should decide when to filter and when not, to prevent filtering at places where we must not.

What exactly is the issue with adding those helper functions?

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.

My concern is that we don't use iter_random anymore, a lot of glue and public api of ID tracker, which is unused.

My proposal about keeping deferred_point_id inside ID tracker is about keeping the public API of ID tracker unchanged (except for get-set methods). But it's a proposal, maybe it's enough just provide deferred id as an argument to old functions

pub fn peek_top_all(
self,
is_stopped: &AtomicBool,
deferred_internal_id: Option<PointOffsetType>,

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.

Can we provide this argument during scorer construction? Currently, we have peek_top_all and peek_top_iter with different usage - one requires parameters, the second one requires external filtering. I find it important to keep consistency between these methods

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.

I agree with your concerns about consistency. We already provide deferred_internal_id in the constructor of BatchFilteredSearcher but we can't apply it in peek_top_iter as the passed iterator can be of any order.

As an alternative approach, I'd suggest to pass it to both functions instead and remove it from the constructor/struct itself. Let me know which approach you prefer!

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 preferred to have deferred id inside the scorer.
My arguments about such an approach.
Deferred ID is a special kind of filter. We keep all the other filters inside the scorer (like the payload filter, point deleted, and vector deleted filter).
Maybe it's enough to use it in BatchFilteredSearcher only and modify the filter from BatchFilteredSearcher into this call

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.

Let me ask if we can keep deferred id in BatchFilteredSearcher and modify the filter inside BatchFilteredSearcher to filter deferred points if they are presented

self.id_tracker
.borrow()
.available_point_count()
.saturating_sub(self.deferred_point_count_estimated())

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.

Inside deferred_point_count_estimated you define deferred points amount as internal_id value. Why do we perform more complicated estimation here instead of just taking internal_id?

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

After discussion with @JojiiOfficial I decided to place an approval with the promise that my concerns will be refactored while chaos testing (or right after the release)

@qdrant qdrant deleted a comment from coderabbitai Bot Mar 10, 2026
@agourlay

Copy link
Copy Markdown
Member

please rebase :)

@IvanPleshkov
IvanPleshkov force-pushed the filter-deferred-points-in-read-op branch from b1f3f8b to 097c0b8 Compare March 10, 2026 11:01
Comment thread lib/segment/src/segment/tests.rs Resolved
@qdrant qdrant deleted a comment from coderabbitai Bot Mar 10, 2026
@JojiiOfficial
JojiiOfficial merged commit 6c2e5ad into dev Mar 11, 2026
16 checks passed
@JojiiOfficial
JojiiOfficial deleted the filter-deferred-points-in-read-op branch March 11, 2026 08:19
generall pushed a commit that referenced this pull request Mar 26, 2026
…nt) (#8283)

* Implement filtering: Search

* Add tests for search and read_filtered

* Implement filtering: read_ordered_filtered + Tests

* Codespell + Clippy

* Reduce code duplication in tests

* Use helper methods of Id tracker

* Implement filtering: Random Scroll

* fixes after rebase

* [Unittest] Only set deferred ID if deferred points exist

* [Unit test] Reduce combinations in segment creation test

---------

Co-authored-by: Ivan Pleshkov <[email protected]>
KShivendu pushed a commit that referenced this pull request Mar 30, 2026
…nt) (#8283)

* Implement filtering: Search

* Add tests for search and read_filtered

* Implement filtering: read_ordered_filtered + Tests

* Codespell + Clippy

* Reduce code duplication in tests

* Use helper methods of Id tracker

* Implement filtering: Random Scroll

* fixes after rebase

* [Unittest] Only set deferred ID if deferred points exist

* [Unit test] Reduce combinations in segment creation test

---------

Co-authored-by: Ivan Pleshkov <[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.

3 participants