Skip to content

Immutable storage null index - #8653

Merged
agourlay merged 11 commits into
devfrom
immutable-payload-index-storage-3-null
Apr 27, 2026
Merged

agourlay merged 11 commits into
devfrom
immutable-payload-index-storage-3-null

Conversation

@monoid

@monoid monoid commented Apr 13, 2026 •

Copy link
Copy Markdown
Contributor

Depends on #8625

Add ImmutableNullIndex type that uses immutable storage and segment's deleted bitmask.

It would reduce IO on serverless Qdrant instances.

Tasks

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 self-assigned this Apr 13, 2026
@timvisee timvisee added the do not merge Pull requests blocked on an external event label Apr 13, 2026
@timvisee
timvisee force-pushed the immutable-payload-index-storage-2-bool branch from 4b0ba85 to 5bf8ede Compare April 22, 2026 13:46
@timvisee
timvisee force-pushed the immutable-payload-index-storage-3-null branch from 623adba to f0f9cc3 Compare April 22, 2026 14:44
@timvisee timvisee changed the title [DO NOT MERGE] Immutable storage null index Immutable storage null index Apr 22, 2026
@timvisee timvisee assigned timvisee and unassigned monoid Apr 22, 2026
@timvisee
timvisee force-pushed the immutable-payload-index-storage-3-null branch from d08c453 to 394949b Compare April 22, 2026 15:07
Base automatically changed from immutable-payload-index-storage-2-bool to dev April 23, 2026 11:35
@timvisee
timvisee force-pushed the immutable-payload-index-storage-3-null branch from 6e21729 to d624076 Compare April 23, 2026 11:35
@timvisee
timvisee requested a review from ffuugoo April 23, 2026 11:35
@timvisee
timvisee marked this pull request as ready for review April 23, 2026 11:36

@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 (2)
lib/segment/src/index/struct_payload_index.rs (1)

165-206: Consolidate id_tracker borrow — currently borrowed three times.

The new id_tracker_borrow at Line 165 is only consumed once (Line 191). Line 175 still calls &self.id_tracker.borrow() inline, and Line 206 redundantly re-borrows (shadowing id_tracker_borrow). Reuse the single borrow across both branches.

♻️ Suggested refactor
         let mut indexes = if payload_schema.types.is_empty() {
             let selector = self.selector(&payload_schema.schema);
             let indexes = selector.new_index(
                 field,
                 &payload_schema.schema,
                 create_if_missing,
-                &self.id_tracker.borrow(),
+                &id_tracker_borrow,
             )?;

             if let Some(mut indexes) = indexes {
                 debug_assert!(
                     !indexes
                         .iter()
                         .any(|index| matches!(index, FieldIndex::NullIndex(_))),
                     "index selector is not expected to provide null index",
                 );

                 // Special null index complements every index.
                 if let Some(null_index) = selector.new_null_index(
                     &self.path,
                     field,
                     create_if_missing,
                     &id_tracker_borrow,
                 )? {
                     indexes.push(null_index);
                 }

                 // Persist exact payload index types
                 is_dirty = true;
                 payload_schema.types = indexes.iter().map(|i| i.get_full_index_type()).collect();

                 indexes
             } else {
                 rebuild = true;
                 vec![]
             }
         } else {
-            let id_tracker_borrow = self.id_tracker.borrow();
             payload_schema
                 .types
                 .iter()
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/struct_payload_index.rs` around lines 165 - 206, The
code borrows self.id_tracker three times; create one borrow named
id_tracker_borrow before the if and reuse it in both branches instead of calling
&self.id_tracker.borrow() inline and re-borrowing/shadowing later; update calls
to selector.new_index(..., &id_tracker_borrow) and selector.new_null_index(...,
&id_tracker_borrow) and remove the redundant let id_tracker_borrow =
self.id_tracker.borrow() in the else branch so the single borrow lives across
the entire payload_schema.types.is_empty() block and prevents multiple borrows.
lib/segment/src/index/field_index/null_index/mutable_null_index.rs (1)

195-196: Nit: doc typo — "is not not changed".

📝 Suggested fix
-        // N.B. We do not update total_point_count because it comes from the id tracker and is not not changed
-        // in non-appendable segments.
+        // N.B. We do not update total_point_count because it comes from the id tracker and is not changed
+        // in non-appendable segments.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/null_index/mutable_null_index.rs` around
lines 195 - 196, Fix the doc comment typo in mutable_null_index.rs: remove the
duplicated "not" so the comment reads "...and is not changed in non-appendable
segments." Locate the comment in the MutableNullIndex area (the block
referencing total_point_count and id tracker) and update the text 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/index/field_index/null_index/immutable_null_index.rs`:
- Around line 403-444: The test test_remove_reopen currently clears the deleted
bit twice (once via index.remove_point(1) and again via the deleted BitVec), so
it never exercises the reopen-with-deletion path; change the test to let the
deleted BitVec be the sole remover by removing the call to
ImmutableNullIndex::remove_point (the index.remove_point(1) line) and only set
deleted.set(1, true) before drop(index), then call ImmutableNullIndex::open(...)
to verify reopen behavior (this ensures MutableNullIndex::open_immutable /
remove_point_immutable actually runs for the bit supplied via deleted).

---

Nitpick comments:
In `@lib/segment/src/index/field_index/null_index/mutable_null_index.rs`:
- Around line 195-196: Fix the doc comment typo in mutable_null_index.rs: remove
the duplicated "not" so the comment reads "...and is not changed in
non-appendable segments." Locate the comment in the MutableNullIndex area (the
block referencing total_point_count and id tracker) and update the text
accordingly.

In `@lib/segment/src/index/struct_payload_index.rs`:
- Around line 165-206: The code borrows self.id_tracker three times; create one
borrow named id_tracker_borrow before the if and reuse it in both branches
instead of calling &self.id_tracker.borrow() inline and re-borrowing/shadowing
later; update calls to selector.new_index(..., &id_tracker_borrow) and
selector.new_null_index(..., &id_tracker_borrow) and remove the redundant let
id_tracker_borrow = self.id_tracker.borrow() in the else branch so the single
borrow lives across the entire payload_schema.types.is_empty() block and
prevents multiple borrows.
🪄 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: e6569e0b-60c4-44e0-9b98-d7645e4e251b

📥 Commits

Reviewing files that changed from the base of the PR and between dd8c99b and d624076.

📒 Files selected for processing (7)
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/field_index/index_selector.rs
  • lib/segment/src/index/field_index/null_index/immutable_null_index.rs
  • lib/segment/src/index/field_index/null_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/query_optimization/condition_converter.rs
  • lib/segment/src/index/struct_payload_index.rs

@timvisee

Copy link
Copy Markdown
Member

Note: needs the same treatment as in #8785

Ivan Boldyrev and others added 7 commits April 24, 2026 16:00
@agourlay
agourlay force-pushed the immutable-payload-index-storage-3-null branch from d624076 to 2a9296c Compare April 24, 2026 14:01
coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot Apr 24, 2026
Comment on lines 428 to 444
match self {
IndexSelector::Mmap(_) => Ok(ImmutableNullIndex::open(
&null_dir(dir, field),
total_point_count,
id_tracker.deleted_point_bitslice(),
)?
.map(NullIndex::Immutable)
.map(FieldIndex::NullIndex)),
IndexSelector::Gridstore(_) => Ok(MutableNullIndex::open(
&null_dir(dir, field),
total_point_count,
create_if_missing,
)?
.map(NullIndex::Mutable)
.map(FieldIndex::NullIndex)),
// `MutableNullIndex` and `ImmutableNullIndex` share the same on-disk
// format; stored mutability picks which in-memory wrapper to build.
IndexSelector::Mmap(_) => match mutability {
IndexMutability::Immutable => Ok(ImmutableNullIndex::open(
&null_dir,
total_point_count,
id_tracker.deleted_point_bitslice(),
)?
.map(NullIndex::Immutable)
.map(FieldIndex::NullIndex)),
IndexMutability::Mutable => open_mutable(),
},
// Gridstore segments are always appendable, so the null index is
// always mutable regardless of the stored mutability marker.
IndexSelector::Gridstore(_) => open_mutable(),
}

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.

If you do match (self, mutability) you can use a single

    (IndexSelector::Mmap(_), IndexMutability::Mutable)
    | (IndexSelector::Gridstore(_), _) => {}

branch to get rid of the open_mutable closure.

@coderabbitai

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

The PR introduces a unified NullIndex enum that wraps either MutableNullIndex or a new ImmutableNullIndex, adds ImmutableNullIndex and its builder (backed by MutableNullIndex), and extends MutableNullIndex with an immutable-open/remove path. FieldIndex and FieldIndexBuilder variants are updated to use NullIndex. IndexSelector, payload index loading, and query optimization logic are refactored to choose and open null indexes based on selector storage and mutability. An integration test verifies appendable null-index persistence and reopen/update behavior.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ffuugoo
  • coszio
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 42.65% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding an ImmutableNullIndex type for immutable storage, which is the primary focus across multiple modified files.
Description check ✅ Passed The description clearly explains the purpose of the changes (adding ImmutableNullIndex to reduce IO on serverless instances), references a dependency, and documents completed tasks and quality checks.
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-3-null

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.

Actionable comments posted: 2

🧹 Nitpick comments (3)
lib/segment/src/index/struct_payload_index.rs (2)

334-340: Nit: duplicate comment line after the refactor.

Line 339 (// Special null index complements every index.) repeats the first sentence of the comment block at lines 334-337. Looks like a leftover from replacing the old call site — safe to drop.

♻️ Proposed cleanup
         let total_point_count = self.id_tracker.borrow().total_point_count();
-        // Special null index complements every index.
         let null_index = selector.null_builder(&self.path, field, total_point_count)?;
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/struct_payload_index.rs` around lines 334 - 340, Remove
the duplicated comment line by deleting the redundant "// Special null index
complements every index." immediately above the call to selector.null_builder in
struct_payload_index.rs; keep the initial explanatory comment block that
mentions seeding the null index with total_point_count and leave the call that
computes total_point_count via self.id_tracker.borrow().total_point_count() and
the subsequent let null_index = selector.null_builder(&self.path, field,
total_point_count)?; unchanged.

167-238: Consolidate the redundant id_tracker borrows.

Line 167 introduces id_tracker_borrow, but the function then takes two additional borrows on the same cell: line 177 (&self.id_tracker.borrow()) and line 213 (which also shadows the outer binding). AtomicRefCell tolerates concurrent shared borrows so this isn't a correctness issue, but it's inconsistent with the refactor's stated intent and leaves stale code paths behind.

♻️ Proposed cleanup
         let mut indexes = if payload_schema.types.is_empty() {
             let selector = self.selector(&payload_schema.schema);
             let indexes = selector.new_index(
                 field,
                 &payload_schema.schema,
                 create_if_missing,
-                &self.id_tracker.borrow(),
+                &id_tracker_borrow,
             )?;
@@
         } else {
-            let id_tracker_borrow = self.id_tracker.borrow();
             payload_schema
                 .types
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/struct_payload_index.rs` around lines 167 - 238, The
code creates multiple borrows of self.id_tracker (id_tracker_borrow at top, then
&self.id_tracker.borrow() and a shadowed id_tracker_borrow later); consolidate
to a single shared borrow by reusing the outer id_tracker_borrow when calling
selector.new_index, selector.new_null_index and selector.new_index_with_type,
and remove the inner shadowing declaration so no second borrow variable is
created; update calls that currently pass &self.id_tracker.borrow() or the
shadowed binding to use &id_tracker_borrow instead, keeping logic around
payload_schema.types, selector.new_null_index, selector.new_index_with_type and
the rebuild/is_dirty flow unchanged.
lib/segment/src/index/field_index/index_selector.rs (1)

121-133: Drop the redundant dir parameter — the selector already owns it.

Both null_builder and new_null_index take dir: &Path, but IndexSelector::{Mmap,Gridstore} already carry a dir field, and every call site (this file's new_index_with_type as well as struct_payload_index.rs::{load_from_db, build_field_indexes}) passes exactly that same path. In new_index_with_type the redundancy is particularly visible: the match at lines 122-125 extracts dir from self just to feed it back into new_null_index, which could read it off self directly.

Removing the parameter would simplify the API and eliminate the (currently safe, but easy to diverge) contract that callers pass the selector's own directory.

♻️ Proposed shape (signatures shown)
-    pub fn null_builder(
-        &self,
-        dir: &Path,
-        field: &JsonPath,
-        total_point_count: usize,
-    ) -> OperationResult<FieldIndexBuilder> {
-        let builder = match self {
-            IndexSelector::Mmap(_) => FieldIndexBuilder::ImmutableNullIndex(
-                ImmutableNullIndex::builder(&null_dir(dir, field), total_point_count)?,
-            ),
-            IndexSelector::Gridstore(_) => FieldIndexBuilder::MutableNullIndex(
-                MutableNullIndex::builder(&null_dir(dir, field), total_point_count)?,
-            ),
-        };
-        Ok(builder)
-    }
+    pub fn null_builder(
+        &self,
+        field: &JsonPath,
+        total_point_count: usize,
+    ) -> OperationResult<FieldIndexBuilder> {
+        let (dir, is_mmap) = match self {
+            IndexSelector::Mmap(IndexSelectorMmap { dir, is_on_disk: _ }) => (*dir, true),
+            IndexSelector::Gridstore(IndexSelectorGridstore { dir }) => (*dir, false),
+        };
+        let null_dir = null_dir(dir, field);
+        Ok(if is_mmap {
+            FieldIndexBuilder::ImmutableNullIndex(ImmutableNullIndex::builder(&null_dir, total_point_count)?)
+        } else {
+            FieldIndexBuilder::MutableNullIndex(MutableNullIndex::builder(&null_dir, total_point_count)?)
+        })
+    }

new_null_index and the NullIndex arm of new_index_with_type can follow the same pattern; the call sites then drop the dir / &self.path argument.

Also applies to: 394-445

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

In `@lib/segment/src/index/field_index/index_selector.rs` around lines 121 - 133,
The code redundantly passes a dir parameter even though IndexSelector variants
(IndexSelector::Mmap / IndexSelector::Gridstore) already own the directory;
change the APIs to remove the dir argument: update the signature of
new_null_index (and any null_builder helpers) to read the directory from &self
instead of receiving dir: &Path, update the NullIndex-related call sites in
new_index_with_type (the match arm currently extracting dir) and in
struct_payload_index.rs::{load_from_db, build_field_indexes} to stop passing
dir/&self.path, and adjust any callers and tests accordingly so the
selector-provided dir is used internally. Ensure you update all referenced
symbols: new_null_index, null_builder, IndexSelector::{Mmap,Gridstore},
new_index_with_type, load_from_db, build_field_indexes.
🤖 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/index_selector.rs`:
- Around line 121-133: The match arm destructures self with `..` which hides the
`is_on_disk` field; change the pattern to explicitly ignore that field (e.g.,
use `IndexSelector::Mmap(IndexSelectorMmap { dir, is_on_disk: _, .. })` style or
match the existing project convention used elsewhere) so both
IndexSelector::Mmap and IndexSelector::Gridstore destructurings use `is_on_disk:
_` instead of `..`; update the patterns around IndexSelector, IndexSelectorMmap,
and IndexSelectorGridstore in the PayloadIndexType::NullIndex arm that calls
self.new_null_index(field, create_if_missing, id_tracker, index_type.mutability)
accordingly.
- Around line 411-445: The ImmutableNullIndex open path doesn't honor
create_if_missing, causing missing null index dirs to be skipped; update
ImmutableNullIndex::open (and its helper open_immutable) to take a
create_if_missing: bool parameter and pass that flag through to
MutableNullIndex::open, and then update callers (notably
IndexSelector::new_null_index where ImmutableNullIndex::open(...) is invoked) to
forward the create_if_missing argument so the first-load path creates the
directory when requested.

---

Nitpick comments:
In `@lib/segment/src/index/field_index/index_selector.rs`:
- Around line 121-133: The code redundantly passes a dir parameter even though
IndexSelector variants (IndexSelector::Mmap / IndexSelector::Gridstore) already
own the directory; change the APIs to remove the dir argument: update the
signature of new_null_index (and any null_builder helpers) to read the directory
from &self instead of receiving dir: &Path, update the NullIndex-related call
sites in new_index_with_type (the match arm currently extracting dir) and in
struct_payload_index.rs::{load_from_db, build_field_indexes} to stop passing
dir/&self.path, and adjust any callers and tests accordingly so the
selector-provided dir is used internally. Ensure you update all referenced
symbols: new_null_index, null_builder, IndexSelector::{Mmap,Gridstore},
new_index_with_type, load_from_db, build_field_indexes.

In `@lib/segment/src/index/struct_payload_index.rs`:
- Around line 334-340: Remove the duplicated comment line by deleting the
redundant "// Special null index complements every index." immediately above the
call to selector.null_builder in struct_payload_index.rs; keep the initial
explanatory comment block that mentions seeding the null index with
total_point_count and leave the call that computes total_point_count via
self.id_tracker.borrow().total_point_count() and the subsequent let null_index =
selector.null_builder(&self.path, field, total_point_count)?; unchanged.
- Around line 167-238: The code creates multiple borrows of self.id_tracker
(id_tracker_borrow at top, then &self.id_tracker.borrow() and a shadowed
id_tracker_borrow later); consolidate to a single shared borrow by reusing the
outer id_tracker_borrow when calling selector.new_index, selector.new_null_index
and selector.new_index_with_type, and remove the inner shadowing declaration so
no second borrow variable is created; update calls that currently pass
&self.id_tracker.borrow() or the shadowed binding to use &id_tracker_borrow
instead, keeping logic around payload_schema.types, selector.new_null_index,
selector.new_index_with_type and the rebuild/is_dirty flow unchanged.
🪄 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: 2b047d69-4fc2-4f20-988b-0e607ca8f705

📥 Commits

Reviewing files that changed from the base of the PR and between 2a9296c and a761bc0.

📒 Files selected for processing (3)
  • lib/segment/src/index/field_index/index_selector.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/tests/integration/payload_index_test.rs

@timvisee timvisee removed the do not merge Pull requests blocked on an external event label Apr 24, 2026

@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/index_selector.rs (1)

121-133: Redundant dir extraction; derive it inside new_null_index.

Now that new_null_index (and null_builder) take &self, the dir can be derived from the selector inside the method. The manual destructuring in lines 122–125 just to forward dir is duplicative — null_dir(dir, field) could be computed once inside new_null_index from self, and the same applies to null_builder (Lines 394–409).

♻️ Proposed refactor
             (PayloadIndexType::NullIndex, _) => {
-                let dir = match self {
-                    IndexSelector::Mmap(IndexSelectorMmap { dir, is_on_disk: _ }) => *dir,
-                    IndexSelector::Gridstore(IndexSelectorGridstore { dir }) => *dir,
-                };
                 self.new_null_index(
-                    dir,
                     field,
                     create_if_missing,
                     id_tracker,
                     index_type.mutability,
                 )?
             }

And in new_null_index / null_builder, drop the dir: &Path parameter and compute it locally:

     pub fn new_null_index(
         &self,
-        dir: &Path,
         field: &JsonPath,
         create_if_missing: bool,
         id_tracker: &IdTrackerEnum,
         mutability: IndexMutability,
     ) -> OperationResult<Option<FieldIndex>> {
+        let dir = match self {
+            IndexSelector::Mmap(IndexSelectorMmap { dir, is_on_disk: _ }) => *dir,
+            IndexSelector::Gridstore(IndexSelectorGridstore { dir }) => *dir,
+        };
         let total_point_count = id_tracker.total_point_count();
         let null_dir = null_dir(dir, field);
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/index_selector.rs` around lines 121 - 133,
The code redundantly destructures IndexSelector to extract dir before calling
new_null_index; since new_null_index (and null_builder) now take &self they
should compute the directory from the selector internally. Remove the manual
match that extracts dir in the PayloadIndexType::NullIndex arm (the pattern
matching on IndexSelectorMmap/IndexSelectorGridstore) and update new_null_index
and null_builder to drop the dir: &Path parameter and derive the directory from
self (handling IndexSelectorMmap and IndexSelectorGridstore variants inside
those methods) so callers simply pass self, field, create_if_missing,
id_tracker, and index_type.mutability.
🤖 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/index_selector.rs`:
- Around line 121-133: The code redundantly destructures IndexSelector to
extract dir before calling new_null_index; since new_null_index (and
null_builder) now take &self they should compute the directory from the selector
internally. Remove the manual match that extracts dir in the
PayloadIndexType::NullIndex arm (the pattern matching on
IndexSelectorMmap/IndexSelectorGridstore) and update new_null_index and
null_builder to drop the dir: &Path parameter and derive the directory from self
(handling IndexSelectorMmap and IndexSelectorGridstore variants inside those
methods) so callers simply pass self, field, create_if_missing, id_tracker, and
index_type.mutability.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 09449c6f-b05d-41a3-b1cd-ed172977600f

📥 Commits

Reviewing files that changed from the base of the PR and between a761bc0 and 46f0b4a.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/index_selector.rs
  • lib/segment/src/index/field_index/null_index/immutable_null_index.rs
✅ Files skipped from review due to trivial changes (1)
  • lib/segment/src/index/field_index/null_index/immutable_null_index.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/struct_payload_index.rs (1)

189-198: Optional: extract the selector→default-mutability mapping into a helper.

The same mapping exists in index_selector.rs::new_index (the Bool arm, lines 181‑184) and is implicitly encoded again inside IndexSelector::new_null_index. A small IndexSelector::default_mutability(&self) -> IndexMutability method would dedupe the three call sites and make the intent clearer. Note also that for the Gridstore case the value passed here is effectively ignored (new_null_index always opens MutableNullIndex for Gridstore), so the explicit null_mutability here only matters for the Mmap branch.

♻️ Sketch

In index_selector.rs:

impl IndexSelector<'_> {
    pub fn default_mutability(&self) -> IndexMutability {
        match self {
            IndexSelector::Mmap(_) => IndexMutability::Immutable,
            IndexSelector::Gridstore(_) => IndexMutability::Mutable,
        }
    }
}

Then here:

-                let null_mutability = match &selector {
-                    IndexSelector::Mmap(_) => IndexMutability::Immutable,
-                    IndexSelector::Gridstore(_) => IndexMutability::Mutable,
-                };
                 if let Some(null_index) = selector.new_null_index(
                     field,
                     create_if_missing,
                     &id_tracker_borrow,
-                    null_mutability,
+                    selector.default_mutability(),
                 )? {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/struct_payload_index.rs` around lines 189 - 198, Add a
helper method IndexSelector::default_mutability(&self) -> IndexMutability that
returns the mapping (Mmap => Immutable, Gridstore => Mutable), then replace the
local null_mutability computation in struct_payload_index.rs (the variable
currently set from match &selector) with a call to
selector.default_mutability(); also update the other call sites
(index_selector.rs::new_index Bool arm and anywhere new_null_index is invoked)
to use this helper so the mapping is centralized (note new_null_index still
controls actual behavior for Gridstore).
🤖 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/struct_payload_index.rs`:
- Around line 189-198: Add a helper method
IndexSelector::default_mutability(&self) -> IndexMutability that returns the
mapping (Mmap => Immutable, Gridstore => Mutable), then replace the local
null_mutability computation in struct_payload_index.rs (the variable currently
set from match &selector) with a call to selector.default_mutability(); also
update the other call sites (index_selector.rs::new_index Bool arm and anywhere
new_null_index is invoked) to use this helper so the mapping is centralized
(note new_null_index still controls actual behavior for Gridstore).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 88c32de3-21c7-47e3-bb47-2186ad148484

📥 Commits

Reviewing files that changed from the base of the PR and between 46f0b4a and f55a9dd.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/index_selector.rs
  • lib/segment/src/index/struct_payload_index.rs

@agourlay
agourlay merged commit 8046c1c into dev Apr 27, 2026
15 checks passed
@agourlay
agourlay deleted the immutable-payload-index-storage-3-null branch April 27, 2026 10:26
@coderabbitai coderabbitai Bot mentioned this pull request Apr 27, 2026
8 of 9 tasks
@agourlay agourlay added this to the Immutable payload index milestone Apr 28, 2026
timvisee added a commit that referenced this pull request May 8, 2026
* Immutable null storage index

Add `ImmutableNullIndex` that uses segment-level deleted points to
update in-memory indexes without modifying the storage.

* Integrate `ImmutableNullIndex`

* Some refinements

* Fix merge conflicts

* Apply review suggestions

* [ai] Get rid of delegate

* Fix tests

* Fix reopen null index

* code review

* nitpicks

* cut duplication

---------

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

3 participants