Skip to content

Immutable storage for mmap numeric index - #8594

Merged
agourlay merged 9 commits into
devfrom
immutable-payload-index-storage-1-bis
Apr 27, 2026
Merged

agourlay merged 9 commits into
devfrom
immutable-payload-index-storage-1-bis

Conversation

@monoid

@monoid monoid commented Apr 2, 2026 •

Copy link
Copy Markdown
Contributor

Do not use a deleted mmap-ed storage, instead, reconstruct a bitmask from the index and segment-level deleted mask. It effectively makes the mmap numeric index storage immutable, and immutable numeric index storage too as it delegates to mmap numeric index.

It would reduce IO at Qdrant serverless instances.

All Submissions:

  • Contributions should target the dev branch. Did you create your branch from dev?
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@monoid
monoid requested a review from timvisee April 2, 2026 11:06
@monoid monoid self-assigned this Apr 2, 2026
@monoid
monoid requested a review from ffuugoo April 2, 2026 11:07
@monoid
monoid force-pushed the immutable-payload-index-storage-1-bis branch from b900efe to 2a8df87 Compare April 2, 2026 12:11
@monoid
monoid marked this pull request as ready for review April 2, 2026 12:25
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 2, 2026
@timvisee
timvisee self-requested a review April 9, 2026 09:07
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 9, 2026
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 9, 2026
@monoid monoid changed the title Immutable storage for mmap numeric index [DO NOT MERGE] Immutable storage for mmap numeric index Apr 10, 2026
@timvisee timvisee added the do not merge Pull requests blocked on an external event label Apr 10, 2026
@qdrant qdrant deleted a comment from coderabbitai Bot Apr 10, 2026
let hw_counter = HardwareCounterCell::new();
// No deletions in this test — sized to comfortably exceed the
// stored deletion bitslice for the few points added below.
let deleted_points = BitVec::repeat(false, 64);

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.

Can we also test with a bitset that is too small? I don't see it here, at least not in the diff.

@timvisee
timvisee force-pushed the immutable-payload-index-storage-1-bis branch from 9676ac8 to 8c369a8 Compare April 21, 2026 15:33

@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

🤖 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/index/field_index/numeric_index/mmap_numeric_index.rs`:
- Line 2: The code currently resizes the in-memory deleted_points mask using
true which incorrectly treats missing external bits as deleted; change the
resize call on deleted_points to use false so missing bits default to live, then
OR the persisted deleted.bin mask into deleted_points (i.e., keep the existing
OR logic but ensure absent external bits are false before ORing). Update the
logic around deleted_points and the external/persisted deleted mask handling so
you first ensure deleted_points.resize(..., false) and only then bitwise-OR the
persisted deleted.bin mask into deleted_points.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f189d5b0-4b7a-40f3-a354-9392c1125044

📥 Commits

Reviewing files that changed from the base of the PR and between 9676ac8 and 8c369a8.

📒 Files selected for processing (7)
  • lib/segment/benches/numeric_index_check_values.rs
  • lib/segment/src/index/field_index/index_selector.rs
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/tests.rs
  • lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs
  • lib/segment/src/index/struct_payload_index.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/segment/benches/numeric_index_check_values.rs
  • lib/segment/src/index/field_index/index_selector.rs

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 22, 2026
@timvisee timvisee assigned timvisee and unassigned monoid Apr 22, 2026
@timvisee timvisee changed the title [DO NOT MERGE] Immutable storage for mmap numeric index Immutable storage for mmap numeric index Apr 22, 2026
@timvisee
timvisee force-pushed the immutable-payload-index-storage-1-bis branch from 63c2a5d to b311b43 Compare April 23, 2026 12:57
@coderabbitai

coderabbitai Bot commented Apr 23, 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

Threads an explicit deletion mask (deleted_points: &BitSlice) through numeric mmap index APIs and their call sites (builders, openers, selector). MmapNumericIndex moves from a buffered-update wrapper to an owned in-memory BitVec for runtime deletions; open clones/resizes the provided mask, ORs persisted deleted.bin into it, and recomputes deleted_count. Runtime deletions update only the in-memory mask and flusher() is now a no-op for deletions. Persistence and cache logic include deleted.bin. Multiple ram_usage_bytes methods were added. Tests and a benchmark were updated to construct and pass deletion bitsets.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ffuugoo
  • JojiiOfficial
  • coszio
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Immutable storage for mmap numeric index' directly describes the main change: making mmap numeric index storage immutable by reconstructing deletion bitmasks instead of using mmap-ed storage.
Description check ✅ Passed The description explains the core change (making mmap storage immutable via bitmask reconstruction), the benefit (reducing IO at serverless instances), and includes the contributor checklist items, all related to the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ 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 immutable-payload-index-storage-1-bis

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.

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

🧹 Nitpick comments (1)
lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs (1)

204-217: Worth a brief doc note: deleted.bin is build-time only.

After this PR, deleted.bin is only written during build() (capturing points whose values are empty) and is never updated by remove_point or a flusher. Listing it in immutable_files() and making flusher() a no-op is correct for that model, but it's a non-obvious semantic shift from the previous writable deletion bitmap. A one-line comment above flusher (or on Storage.deleted) documenting that runtime deletions live only in the in-memory deleted: BitVec (authoritative source on reopen is the external &BitSlice) would prevent future surprises.

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

In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs` around
lines 204 - 217, The review notes that deleted.bin is now build-time only and
runtime deletions live in the in-memory deleted BitVec (authoritative on reopen
is the external &BitSlice), so add a one-line doc comment explaining this
semantic shift: above the flusher() method (function flusher) or on the
Storage.deleted field, state that deleted.bin is written only during build() and
not updated at runtime, that remove_point updates the in-memory deleted: BitVec
only, and that immutable_files() intentionally lists deleted.bin while flusher()
is a no-op; include references to deleted.bin, flusher(), immutable_files(),
Storage.deleted, BitVec and &BitSlice to make the behavior explicit for future
maintainers.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs`:
- Around line 204-217: The review notes that deleted.bin is now build-time only
and runtime deletions live in the in-memory deleted BitVec (authoritative on
reopen is the external &BitSlice), so add a one-line doc comment explaining this
semantic shift: above the flusher() method (function flusher) or on the
Storage.deleted field, state that deleted.bin is written only during build() and
not updated at runtime, that remove_point updates the in-memory deleted: BitVec
only, and that immutable_files() intentionally lists deleted.bin while flusher()
is a no-op; include references to deleted.bin, flusher(), immutable_files(),
Storage.deleted, BitVec and &BitSlice to make the behavior explicit for future
maintainers.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d500bf4f-cacb-4a2b-bf40-cb6292a4e4f4

📥 Commits

Reviewing files that changed from the base of the PR and between 9676ac8 and b311b43.

📒 Files selected for processing (7)
  • lib/segment/benches/numeric_index_check_values.rs
  • lib/segment/src/index/field_index/index_selector.rs
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/tests.rs
  • lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs
  • lib/segment/src/index/struct_payload_index.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/segment/benches/numeric_index_check_values.rs
  • lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs

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

♻️ Duplicate comments (1)
lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs (1)

173-181: ⚠️ Potential issue | 🔴 Critical

Default missing external deletion bits to live.

Line 180 still resizes a shorter deleted_points mask with true, so any point beyond the external mask length is treated as deleted before deleted.bin is ORed in. Missing id-tracker bits should default to false; otherwise live points can disappear after reload.

🐛 Proposed fix
-        deleted.resize(point_to_values.len(), true);
+        deleted.resize(point_to_values.len(), false);
         deleted.bitor_assign(deleted_payloads_bitslice.as_ref());
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs` around
lines 173 - 181, The code currently expands the in-memory deleted mask `deleted`
using deleted.resize(point_to_values.len(), true), which treats missing
id-tracker bits as deleted; change this to default missing bits to live by
resizing with false (e.g., call deleted.resize(point_to_values.len(), false))
before OR-ing with the external `MmapBitSlice`
(`deleted_payload_mmap.read_all()` and subsequent deleted.bitor_assign(...)) so
points beyond the external mask are considered live until marked deleted by
`deleted.bin`; ensure references remain to `deleted_points`, `point_to_values`,
`MmapBitSlice`, `deleted.resize`, and `deleted.bitor_assign`.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs`:
- Around line 173-181: The code currently expands the in-memory deleted mask
`deleted` using deleted.resize(point_to_values.len(), true), which treats
missing id-tracker bits as deleted; change this to default missing bits to live
by resizing with false (e.g., call deleted.resize(point_to_values.len(), false))
before OR-ing with the external `MmapBitSlice`
(`deleted_payload_mmap.read_all()` and subsequent deleted.bitor_assign(...)) so
points beyond the external mask are considered live until marked deleted by
`deleted.bin`; ensure references remain to `deleted_points`, `point_to_values`,
`MmapBitSlice`, `deleted.resize`, and `deleted.bitor_assign`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 252d0247-f708-4f82-9d5f-856293a9d596

📥 Commits

Reviewing files that changed from the base of the PR and between b311b43 and 2394846.

📒 Files selected for processing (4)
  • lib/common/common/src/universal_io/wrappers/typed.rs
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/field_index/stored_point_to_values.rs
✅ Files skipped from review due to trivial changes (1)
  • lib/common/common/src/universal_io/wrappers/typed.rs

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

🧹 Nitpick comments (1)
lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs (1)

236-238: Document the in-memory-only deletion contract on the public API.

flusher() is a no-op and remove_point() mutates only the in-memory deleted BitVec — a substantial contract change from the previous mmap-backed deletion storage. The expectation is now that callers must re-supply deletions via the &BitSlice argument to open() (typically id_tracker.deleted_point_bitslice()); without that, runtime deletions made via remove_point are lost on reload.

This invariant is currently only documented inside a test comment (tests.rs:665-670). A reader of MmapNumericIndex in isolation will incorrectly assume flusher persists deletions. Please add a brief doc comment on both methods (and ideally on the struct itself) so callers outside the segment integration path don't get caught out.

📝 Suggested doc comments
+    /// Returns a no-op flusher.
+    ///
+    /// Deletions made via [`Self::remove_point`] are kept only in memory; they
+    /// are not persisted to `deleted.bin`. The authoritative deletion state is
+    /// re-supplied via the `deleted_points: &BitSlice` argument to
+    /// [`Self::open`] (typically the id-tracker's deleted-point bitslice).
     pub fn flusher(&self) -> Flusher {
         Box::new(|| Ok(()))
     }
@@
+    /// Marks `idx` as deleted in the in-memory bitmap.
+    ///
+    /// Note: this is **not** persisted. On reopen, deletions must be
+    /// re-supplied via the `deleted_points` argument to [`Self::open`].
     pub fn remove_point(&mut self, idx: PointOffsetType) {

Also applies to: 312-318

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

In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs` around
lines 236 - 238, Add clear doc comments to MmapNumericIndex, its flusher()
method, and remove_point() explaining that deletions are in-memory only and not
persisted: flusher() is a no-op and remove_point() only updates the in-memory
deleted BitVec; callers must re-supply the deleted BitSlice to open() (e.g.
id_tracker.deleted_point_bitslice()) when reloading to restore deletions.
Mention this contract succinctly on the struct and both methods so consumers do
not assume deletions are persisted.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs`:
- Around line 236-238: Add clear doc comments to MmapNumericIndex, its flusher()
method, and remove_point() explaining that deletions are in-memory only and not
persisted: flusher() is a no-op and remove_point() only updates the in-memory
deleted BitVec; callers must re-supply the deleted BitSlice to open() (e.g.
id_tracker.deleted_point_bitslice()) when reloading to restore deletions.
Mention this contract succinctly on the struct and both methods so consumers do
not assume deletions are persisted.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: fafb1f84-1069-4b9f-9b15-17e238d381b5

📥 Commits

Reviewing files that changed from the base of the PR and between de6c6a2 and 4fff5ea.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs
  • lib/segment/src/index/field_index/numeric_index/tests.rs

@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

🤖 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/index/field_index/numeric_index/mmap_numeric_index.rs`:
- Around line 186-195: The current code bitor_assigns the entire mapped
bit-slice (deleted_payloads_bitslice) into deleted, which can be longer than the
logical point count and causes panics for non-word-aligned segments; before
calling deleted.bitor_assign(...), truncate/slice the mapped bit slice to the
logical length point_to_values.len() (use deleted_payloads_bitslice.as_ref() or
equivalent view and take only the first point_to_values.len() bits) so the two
bitsets have equal lengths when calling bitor_assign on deleted_payload_mmap /
deleted_payloads_bitslice / deleted.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 56a1cc11-38fb-4e03-acdd-fdc5e9d1aa8b

📥 Commits

Reviewing files that changed from the base of the PR and between 4fff5ea and d765c28.

📒 Files selected for processing (1)
  • lib/segment/src/index/field_index/numeric_index/mmap_numeric_index.rs

Ivan Boldyrev and others added 8 commits April 27, 2026 16:00
Do not use a deleted mmap-ed storage, instead, reconstruct a bitmask
from the index and segment-level deleted mask.  It effectively makes
the mmap numeric index immutable, and immutable numeric index too as
it delegates the storage to mmap numeric index.
It is more compact than count data we read before to check for cleared
payloads.
* use bitwise operations instead of loop

* [AI] Only propagate bitslice

* fmt
It must be the same length as `point_to_values` length.
@agourlay
agourlay force-pushed the immutable-payload-index-storage-1-bis branch from d765c28 to 5324e41 Compare April 27, 2026 14:18
@agourlay
agourlay force-pushed the immutable-payload-index-storage-1-bis branch from 5324e41 to 99f5bf1 Compare April 27, 2026 14:22
@agourlay agourlay removed the do not merge Pull requests blocked on an external event label Apr 27, 2026
@agourlay
agourlay merged commit ca4ed7a into dev Apr 27, 2026
25 of 27 checks passed
@agourlay
agourlay deleted the immutable-payload-index-storage-1-bis branch April 27, 2026 17:30
@agourlay agourlay added this to the Immutable payload index milestone Apr 28, 2026
timvisee pushed a commit that referenced this pull request May 8, 2026
* Immutable storage for mmap numeric index

Do not use a deleted mmap-ed storage, instead, reconstruct a bitmask
from the index and segment-level deleted mask.  It effectively makes
the mmap numeric index immutable, and immutable numeric index too as
it delegates the storage to mmap numeric index.

* Index reload tests

* Make clippy happy

* Restore deletion bitmask to reduce IO on index load

It is more compact than count data we read before to check for cleared
payloads.

* immutable payload index storage 1 bis review (#8638)

* use bitwise operations instead of loop

* [AI] Only propagate bitslice

* fmt

* Fix deleted bitmask length

It must be the same length as `point_to_values` length.

* account for ram usage

* Default missing external deletion bits to live, not deleted.

* clear doc for flush

---------

Co-authored-by: Andrey Vasnetsov <[email protected]>
Co-authored-by: Arnaud Gourlay <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants