Skip to content

refactor split of struct_payload_index.rs - #8967

Merged
generall merged 2 commits into
devfrom
split-struct-payload-index
May 9, 2026
Merged

generall merged 2 commits into
devfrom
split-struct-payload-index

Conversation

@generall

@generall generall commented May 9, 2026

Copy link
Copy Markdown
Member

No description provided.

@coderabbitai

coderabbitai Bot commented May 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack
No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b871fa7e-46c4-48a0-b84a-76acd74f3f39

📥 Commits

Reviewing files that changed from the base of the PR and between 15f8b88 and 8ac5665.

📒 Files selected for processing (2)
  • lib/segment/src/index/struct_payload_index/payload_index.rs
  • lib/segment/src/index/struct_payload_index/tests.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/segment/src/index/struct_payload_index/tests.rs
  • lib/segment/src/index/struct_payload_index/payload_index.rs

📝 Walkthrough

Walkthrough

This PR replaces a single monolithic StructPayloadIndex implementation with a modular six-file layout: mod.rs (lifecycle and wiring), build.rs (index construction and point removal), filtering.rs (condition-to-cardinality and primary iterators), payload_index_read.rs (PayloadIndexRead trait/read-side logic), payload_index.rs (PayloadIndex trait/mutation-side logic), and tests.rs (integration test verifying config persistence and rebuild behavior).

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • qdrant/qdrant#8966: Splits field-index traits into read/write halves that the refactored StructPayloadIndex uses.
  • qdrant/qdrant#8858: Introduces/changes PayloadIndexRead-related APIs closely related to this restructuring.
  • qdrant/qdrant#8841: Modifies payload-index read APIs (formula_scorer, iter_filtered_points) implemented here.

Suggested reviewers

  • JojiiOfficial
  • timvisee
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.61% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No pull request description was provided by the author, making it impossible to assess relevance to the changeset. Add a description explaining the purpose and benefits of splitting the module into separate concerns.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'refactor split of struct_payload_index.rs' accurately describes the main change: refactoring a monolithic module into multiple focused files.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split-struct-payload-index

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

18-33: 💤 Low value

Avoid re-borrowing id_tracker when an active borrow already exists.

id_tracker_borrow from line 19 is live throughout this block, so the second self.id_tracker.borrow() on line 31 is redundant. While AtomicRefCell permits concurrent shared borrows, reusing the existing guard makes the lifetime obvious and avoids an extra atomic read.

♻️ Proposed cleanup
-        let total_point_count = self.id_tracker.borrow().total_point_count();
+        let total_point_count = id_tracker_borrow.total_point_count();
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/index/struct_payload_index/build.rs` around lines 18 - 33,
The code re-borrows id_tracker with self.id_tracker.borrow() when an active
borrow id_tracker_borrow is already held; replace the second borrow by using the
existing id_tracker_borrow to get total_point_count (call
id_tracker_borrow.total_point_count()) and pass that into
selector.null_builder(field, total_point_count) so you avoid the redundant
atomic borrow and make lifetimes explicit for the id_tracker borrow used with
selector.null_builder and builders.push(null_index).

56-66: 💤 Low value

Minor: prefer values_mut() over iter_mut() with _ key.

Since the key is unused, self.field_indexes.values_mut() reads cleaner.

♻️ Proposed cleanup
-        for (_, field_indexes) in self.field_indexes.iter_mut() {
-            for index in field_indexes {
+        for field_indexes in self.field_indexes.values_mut() {
+            for index in field_indexes {
                 index.remove_point(point_id)?;
             }
         }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/segment/src/index/struct_payload_index/build.rs` around lines 56 - 66, In
clear_index_for_point, replace the map iteration that uses
self.field_indexes.iter_mut() with self.field_indexes.values_mut() since the key
is unused; update the outer loop to iterate directly over the mutable values
(field_indexes) and keep the inner loop calling index.remove_point(point_id)?;
this makes the code clearer while preserving the same behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@lib/segment/src/index/struct_payload_index/payload_index.rs`:
- Line 5: Replace the private re-export import of serde_json in the payload
index module: the line importing schemars::_serde_json::Value should instead
import serde_json::Value directly (i.e., use serde_json::Value) so the code uses
the public serde_json crate; update any references to Value in payload_index.rs
as needed to reflect this import change.

In `@lib/segment/src/index/struct_payload_index/tests.rs`:
- Around line 56-92: The closure check_index_types currently returns a bool but
its results are ignored, so replace the two bare calls to
check_index_types(&schema.types) with assertions (e.g.,
assert!(check_index_types(&schema.types))) so the test fails if the index types
don't match; update both places where check_index_types is invoked (the one
before clearing schema.types and the one after re-loading via load_segment) to
assert the returned value, keeping the existing closure and function names
(check_index_types, PayloadConfig::load, load_segment, schema.types) intact.

---

Nitpick comments:
In `@lib/segment/src/index/struct_payload_index/build.rs`:
- Around line 18-33: The code re-borrows id_tracker with
self.id_tracker.borrow() when an active borrow id_tracker_borrow is already
held; replace the second borrow by using the existing id_tracker_borrow to get
total_point_count (call id_tracker_borrow.total_point_count()) and pass that
into selector.null_builder(field, total_point_count) so you avoid the redundant
atomic borrow and make lifetimes explicit for the id_tracker borrow used with
selector.null_builder and builders.push(null_index).
- Around line 56-66: In clear_index_for_point, replace the map iteration that
uses self.field_indexes.iter_mut() with self.field_indexes.values_mut() since
the key is unused; update the outer loop to iterate directly over the mutable
values (field_indexes) and keep the inner loop calling
index.remove_point(point_id)?; this makes the code clearer while preserving the
same behavior.
🪄 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: 1029b65f-13ad-4964-b0e8-3de0a135af0e

📥 Commits

Reviewing files that changed from the base of the PR and between a85ab22 and 15f8b88.

📒 Files selected for processing (7)
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/index/struct_payload_index/build.rs
  • lib/segment/src/index/struct_payload_index/filtering.rs
  • lib/segment/src/index/struct_payload_index/mod.rs
  • lib/segment/src/index/struct_payload_index/payload_index.rs
  • lib/segment/src/index/struct_payload_index/payload_index_read.rs
  • lib/segment/src/index/struct_payload_index/tests.rs
💤 Files with no reviewable changes (1)
  • lib/segment/src/index/struct_payload_index.rs

@generall
generall merged commit d91cee7 into dev May 9, 2026
12 checks passed
@generall
generall deleted the split-struct-payload-index branch May 9, 2026 16:31
generall added a commit that referenced this pull request May 10, 2026
Confirmed dead code — the function had no callers anywhere in the workspace.
It was preserved across recent refactors (most recently #8967) but was never
referenced. Removing it also drops the now-unused JsonPath and FacetIndexEnum
imports in struct_payload_index/mod.rs.

This obsoletes the inline variant match introduced in the previous commit:
that match existed solely to keep get_facet_index returning the concrete
FacetIndexEnum<'_> when as_facet_index moved to the FieldIndexRead trait
with an opaque return. With get_facet_index gone, no workaround is needed.

The OperationError::MissingMapIndexForFacet variant stays — it is still used
by segment::read_view::facet and lib/collection/src/operations/types.rs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 10, 2026
* refactor: implement FieldIndexRead for FieldIndex

Move the 10 read-only inherent methods on FieldIndex (special_check_condition,
count_indexed_points, filter, estimate_cardinality, for_each_payload_block,
get_telemetry_data, values_count, values_is_empty, as_numeric, as_facet_index)
into impl FieldIndexRead for FieldIndex. Bodies are unchanged.

Write/lifecycle methods (add_point, remove_point, wipe, flusher, files,
immutable_files, ram_usage_bytes, is_on_disk, populate, clear_cache,
get_full_index_type) stay inherent on FieldIndex.

Call sites that hold &FieldIndex now resolve through the trait — added
`use ... FieldIndexRead;` imports where the compiler asked
(read_view/{payload_index_read,filtering}.rs, query_optimization/
condition_converter.rs and match_converter.rs, payload_storage/
query_checker.rs, two integration tests, full_text_index tests module).

StructPayloadIndex::get_facet_index keeps its concrete
OperationResult<FacetIndexEnum<'_>> return: the trait method as_facet_index
returns Option<impl FacetIndex + '_> (RPITIT) which can't be downcast back
to FacetIndexEnum, so the function inlines the variant match. Same shape as
before, just expressed locally.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor: remove unused StructPayloadIndex::get_facet_index

Confirmed dead code — the function had no callers anywhere in the workspace.
It was preserved across recent refactors (most recently #8967) but was never
referenced. Removing it also drops the now-unused JsonPath and FacetIndexEnum
imports in struct_payload_index/mod.rs.

This obsoletes the inline variant match introduced in the previous commit:
that match existed solely to keep get_facet_index returning the concrete
FacetIndexEnum<'_> when as_facet_index moved to the FieldIndexRead trait
with an opaque return. With get_facet_index gone, no workaround is needed.

The OperationError::MissingMapIndexForFacet variant stays — it is still used
by segment::read_view::facet and lib/collection/src/operations/types.rs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 22, 2026
* refactor split of struct_payload_index.rs

* review fixes
generall added a commit that referenced this pull request May 22, 2026
* refactor: implement FieldIndexRead for FieldIndex

Move the 10 read-only inherent methods on FieldIndex (special_check_condition,
count_indexed_points, filter, estimate_cardinality, for_each_payload_block,
get_telemetry_data, values_count, values_is_empty, as_numeric, as_facet_index)
into impl FieldIndexRead for FieldIndex. Bodies are unchanged.

Write/lifecycle methods (add_point, remove_point, wipe, flusher, files,
immutable_files, ram_usage_bytes, is_on_disk, populate, clear_cache,
get_full_index_type) stay inherent on FieldIndex.

Call sites that hold &FieldIndex now resolve through the trait — added
`use ... FieldIndexRead;` imports where the compiler asked
(read_view/{payload_index_read,filtering}.rs, query_optimization/
condition_converter.rs and match_converter.rs, payload_storage/
query_checker.rs, two integration tests, full_text_index tests module).

StructPayloadIndex::get_facet_index keeps its concrete
OperationResult<FacetIndexEnum<'_>> return: the trait method as_facet_index
returns Option<impl FacetIndex + '_> (RPITIT) which can't be downcast back
to FacetIndexEnum, so the function inlines the variant match. Same shape as
before, just expressed locally.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

* refactor: remove unused StructPayloadIndex::get_facet_index

Confirmed dead code — the function had no callers anywhere in the workspace.
It was preserved across recent refactors (most recently #8967) but was never
referenced. Removing it also drops the now-unused JsonPath and FacetIndexEnum
imports in struct_payload_index/mod.rs.

This obsoletes the inline variant match introduced in the previous commit:
that match existed solely to keep get_facet_index returning the concrete
FacetIndexEnum<'_> when as_facet_index moved to the FieldIndexRead trait
with an opaque return. With get_facet_index gone, no workaround is needed.

The OperationError::MissingMapIndexForFacet variant stays — it is still used
by segment::read_view::facet and lib/collection/src/operations/types.rs.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[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.

1 participant