Skip to content

refactor(map_index): split monolithic mod.rs into focused submodules - #8999

Merged
generall merged 2 commits into
devfrom
refactor/split-map-index-module
May 12, 2026
Merged

generall merged 2 commits into
devfrom
refactor/split-map-index-module

Conversation

@qdrant-cloud-bot

Copy link
Copy Markdown
Contributor

Summary

  • Split the ~2150-line lib/segment/src/index/field_index/map_index/mod.rs into 7 focused submodules while preserving all logic and public API
  • New files: key.rs (MapIndexKey trait), builders.rs (index builders), payload_index_impl_str.rs / payload_index_impl_int.rs / payload_index_impl_uuid.rs (per-type PayloadFieldIndex impls), facet_index_impl.rs (FacetIndex impl), value_indexer_impl.rs (ValueIndexer impls + value retrievers)
  • mod.rs retains the MapIndex enum, core inherent methods, type aliases, constants, and tests

Test plan

  • cargo check -p segment passes with zero warnings
  • All 17 map_index::tests pass
  • CI passes

Made with Cursor

The ~2150-line map_index/mod.rs was difficult to navigate. Split it into
focused files while preserving all logic and public API:

- key.rs: MapIndexKey trait and impls for str, IntPayloadType, UuidIntType
- builders.rs: MapIndexBuilder, MapIndexMmapBuilder, MapIndexGridstoreBuilder
- payload_index_impl_str.rs: PayloadFieldIndex/Read for MapIndex<str>
- payload_index_impl_int.rs: PayloadFieldIndex/Read for MapIndex<IntPayloadType>
- payload_index_impl_uuid.rs: PayloadFieldIndex/Read for MapIndex<UuidIntType>
- facet_index_impl.rs: FacetIndex impl for MapIndex<N>
- value_indexer_impl.rs: ValueIndexer impls and value_retriever methods

mod.rs retains the MapIndex enum, its core inherent methods, type aliases,
constants, and tests.

Co-authored-by: Cursor <[email protected]>
@coderabbitai

coderabbitai Bot commented May 12, 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: a576f740-47f2-4cf4-978a-9e02f21c90e3

📥 Commits

Reviewing files that changed from the base of the PR and between c51220a and c90f9c4.

📒 Files selected for processing (1)
  • lib/segment/src/index/field_index/map_index/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • lib/segment/src/index/field_index/map_index/mod.rs

📝 Walkthrough

Walkthrough

Adds a MapIndexKey trait and implements builders (mutable, mmap, gridstore), FacetIndex, PayloadFieldIndex/PayloadFieldIndexRead for str/Int/UUID keys, and ValueIndexer/value_retriever methods. Exposes multiple MapIndex internals as crate-visible helpers and updates mmap-related tests and payload IO/hw-counter assertions.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • qdrant/qdrant#8977: Related changes that move/readjust helpers calling variant-specific MapIndex internals used by this PR.
  • qdrant/qdrant#8766: Similar API change in map_index (iterator → for_each_payload_block) also touched by this PR.
  • qdrant/qdrant#8890: Touches MapIndex mmap/immutable loading and values→points mapping, overlapping with mmap builder/load changes here.

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 55.81% 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 and concisely describes the main change: refactoring a monolithic module into focused submodules. It is specific, clear, and directly summarizes the primary objective of the changeset.
Description check ✅ Passed The description comprehensively explains the refactoring: it lists the new files with their purposes, clarifies what mod.rs retains, and includes testing confirmation. It is directly related to the changeset and provides meaningful context.
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 refactor/split-map-index-module

Tip

💬 Introducing Slack Agent: The best way for teams to turn conversations into code.

Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.

  • Generate code and open pull requests
  • Plan features and break down work
  • Investigate incidents and troubleshoot customer tickets together
  • Automate recurring tasks and respond to alerts with triggers
  • Summarize progress and report instantly

Built for teams:

  • Shared memory across your entire org—no repeating context
  • Per-thread sandboxes to safely plan and execute work
  • Governance built-in—scoped access, auditability, and budget controls

One agent for your entire SDLC. Right inside Slack.

👉 Get started


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/field_index/map_index/payload_index_impl_uuid.rs (1)

120-121: ⚡ Quick win

Replace catch-all arms with explicit variants in match handling.

Line 120 and Line 205 use _ => None. Please enumerate unsupported variants explicitly so new Match variants don’t get silently ignored.

As per coding guidelines: "Prefer explicit exhaustive matches over catch-all _ arm in Rust match expressions, so we don't miss handling new enum variants when they are added later."

Also applies to: 205-206

🤖 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/field_index/map_index/payload_index_impl_uuid.rs`
around lines 120 - 121, The match expressions in payload_index_impl_uuid.rs that
currently end with `_ => None` should be changed to explicitly list each
unsupported enum variant and return None for them (instead of a catch-all) so
additions to the enum will produce a compile error; locate the two match sites
in the MapIndex/Uuid payload implementation (the matches in the
payload_index_impl_uuid module) and replace `_ => None` with explicit arms for
every enum variant (e.g., VariantA => None, VariantB => None, ...) or the exact
variant names from the matched enum, adding brief comments like `// unsupported`
if helpful; this ensures exhaustive matching and fails compilation if new
variants are introduced.
lib/segment/src/index/field_index/map_index/payload_index_impl_int.rs (1)

86-87: ⚡ Quick win

Use explicit variant arms instead of _ => None.

Line 86 and Line 150 use catch-all fallbacks. Please list unsupported Match variants explicitly to keep behavior reviewable when enum variants evolve.

As per coding guidelines: "Prefer explicit exhaustive matches over catch-all _ arm in Rust match expressions, so we don't miss handling new enum variants when they are added later."

Also applies to: 150-151

🤖 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/field_index/map_index/payload_index_impl_int.rs` around
lines 86 - 87, The match expressions in payload_index_impl_int.rs use a
catch-all `_ => None` for the `Match` enum; replace those with explicit arms for
every `Match` variant (e.g., list each variant and return None for unsupported
ones) so the compiler will require updates when new variants are added, and
remove the `_` fallback; update both occurrences that currently use `_ => None`
so all `Match::...` variants are handled explicitly.
lib/segment/src/index/field_index/map_index/payload_index_impl_str.rs (1)

87-88: ⚡ Quick win

Avoid wildcard fallback arms in production match logic.

Line 87 and Line 151 use _ => None. Please switch to explicit unsupported variants for forward-safe behavior when Match grows.

As per coding guidelines: "Prefer explicit exhaustive matches over catch-all _ arm in Rust match expressions, so we don't miss handling new enum variants when they are added later."

Also applies to: 151-152

🤖 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/field_index/map_index/builders.rs`:
- Around line 147-151: Replace the panic assert in the builder's init method
with an error return: check if self.index.is_some() and, instead of asserting,
return an Err(OperationError) via the existing OperationResult return type with
a clear message like "index already initialized"; otherwise proceed with
initialization. Update the init function (the method named init in this builder)
to produce an OperationError for the repeated-init path rather than calling
assert!, using whatever constructor/variant your OperationError type exposes so
callers can handle the misuse without aborting the process.

In `@lib/segment/src/index/field_index/map_index/payload_index_impl_str.rs`:
- Line 165: The conditional currently uses `if count > threshold` which excludes
blocks where count == threshold and causes a mismatch with int/uuid handling;
change the comparison to `if count >= threshold` in the payload block check (the
conditional that uses the `count` and `threshold` variables in
payload_index_impl_str) so string payload blocks include exact-threshold cases
and match the inclusive behavior of int/uuid code paths.

---

Nitpick comments:
In `@lib/segment/src/index/field_index/map_index/payload_index_impl_int.rs`:
- Around line 86-87: The match expressions in payload_index_impl_int.rs use a
catch-all `_ => None` for the `Match` enum; replace those with explicit arms for
every `Match` variant (e.g., list each variant and return None for unsupported
ones) so the compiler will require updates when new variants are added, and
remove the `_` fallback; update both occurrences that currently use `_ => None`
so all `Match::...` variants are handled explicitly.

In `@lib/segment/src/index/field_index/map_index/payload_index_impl_uuid.rs`:
- Around line 120-121: The match expressions in payload_index_impl_uuid.rs that
currently end with `_ => None` should be changed to explicitly list each
unsupported enum variant and return None for them (instead of a catch-all) so
additions to the enum will produce a compile error; locate the two match sites
in the MapIndex/Uuid payload implementation (the matches in the
payload_index_impl_uuid module) and replace `_ => None` with explicit arms for
every enum variant (e.g., VariantA => None, VariantB => None, ...) or the exact
variant names from the matched enum, adding brief comments like `// unsupported`
if helpful; this ensures exhaustive matching and fails compilation if new
variants are introduced.
🪄 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: 38f47961-34dc-4534-afe8-94a80833c6cf

📥 Commits

Reviewing files that changed from the base of the PR and between 500c7cc and c51220a.

📒 Files selected for processing (8)
  • lib/segment/src/index/field_index/map_index/builders.rs
  • lib/segment/src/index/field_index/map_index/facet_index_impl.rs
  • lib/segment/src/index/field_index/map_index/key.rs
  • lib/segment/src/index/field_index/map_index/mod.rs
  • lib/segment/src/index/field_index/map_index/payload_index_impl_int.rs
  • lib/segment/src/index/field_index/map_index/payload_index_impl_str.rs
  • lib/segment/src/index/field_index/map_index/payload_index_impl_uuid.rs
  • lib/segment/src/index/field_index/map_index/value_indexer_impl.rs

Comment on lines +147 to +151
fn init(&mut self) -> OperationResult<()> {
assert!(
self.index.is_none(),
"index must be initialized exactly once",
);

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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid panic in builder init path; return an error instead.

Line 148 currently panics on repeated init(). This should be an OperationError to avoid process abort in recoverable misuse paths.

Suggested fix
     fn init(&mut self) -> OperationResult<()> {
-        assert!(
-            self.index.is_none(),
-            "index must be initialized exactly once",
-        );
+        if self.index.is_some() {
+            return Err(OperationError::service_error(
+                "MapIndexGridstoreBuilder: init called more than once",
+            ));
+        }
         self.index.replace(
             MapIndex::new_gridstore(self.dir.clone(), true)?.ok_or_else(|| {
                 OperationError::service_error("Failed to create mutable map index")
🤖 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/field_index/map_index/builders.rs` around lines 147 -
151, Replace the panic assert in the builder's init method with an error return:
check if self.index.is_some() and, instead of asserting, return an
Err(OperationError) via the existing OperationResult return type with a clear
message like "index already initialized"; otherwise proceed with initialization.
Update the init function (the method named init in this builder) to produce an
OperationError for the repeated-init path rather than calling assert!, using
whatever constructor/variant your OperationError type exposes so callers can
handle the misuse without aborting the process.

let count = self
.get_count_for_value(value, &HardwareCounterCell::disposable()) // Payload_blocks only used in HNSW building, which is unmeasured.
.unwrap_or(0);
if count > threshold {

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use inclusive threshold comparison for payload blocks.

Line 165 uses count > threshold, which excludes exact-threshold blocks and diverges from int/uuid behavior (>=). This creates type-dependent boundary behavior.

Suggested fix
-            if count > threshold {
+            if count >= threshold {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if count > threshold {
if count >= threshold {
🤖 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/field_index/map_index/payload_index_impl_str.rs` at
line 165, The conditional currently uses `if count > threshold` which excludes
blocks where count == threshold and causes a mismatch with int/uuid handling;
change the comparison to `if count >= threshold` in the payload block check (the
conditional that uses the `count` and `threshold` variables in
payload_index_impl_str) so string payload blocks include exact-threshold cases
and match the inclusive behavior of int/uuid code paths.

…ex-module

Co-authored-by: Cursor <[email protected]>

# Conflicts:
#	lib/segment/src/index/field_index/map_index/mod.rs
@generall
generall merged commit 7547e16 into dev May 12, 2026
15 checks passed
@generall
generall deleted the refactor/split-map-index-module branch May 12, 2026 11:10
generall pushed a commit that referenced this pull request May 22, 2026
…8999)

The ~2150-line map_index/mod.rs was difficult to navigate. Split it into
focused files while preserving all logic and public API:

- key.rs: MapIndexKey trait and impls for str, IntPayloadType, UuidIntType
- builders.rs: MapIndexBuilder, MapIndexMmapBuilder, MapIndexGridstoreBuilder
- payload_index_impl_str.rs: PayloadFieldIndex/Read for MapIndex<str>
- payload_index_impl_int.rs: PayloadFieldIndex/Read for MapIndex<IntPayloadType>
- payload_index_impl_uuid.rs: PayloadFieldIndex/Read for MapIndex<UuidIntType>
- facet_index_impl.rs: FacetIndex impl for MapIndex<N>
- value_indexer_impl.rs: ValueIndexer impls and value_retriever methods

mod.rs retains the MapIndex enum, its core inherent methods, type aliases,
constants, and tests.

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