Skip to content

refactor(field_index): make FieldIndexRead a supertrait of PayloadFieldIndexRead - #8996

Merged
generall merged 3 commits into
devfrom
refactor/field-index-read-supertrait
May 12, 2026
Merged

generall merged 3 commits into
devfrom
refactor/field-index-read-supertrait

Conversation

@generall

Copy link
Copy Markdown
Member

Summary

  • Make FieldIndexRead: PayloadFieldIndexRead a supertrait. The five overlapping read methods (count_indexed_points, filter, estimate_cardinality, for_each_payload_block, condition_checker) now come from the supertrait directly.
  • Remove the get_payload_field_index_read() -> &dyn PayloadFieldIndexRead bridge method and the five default impls that delegated through it.
  • Add a direct impl PayloadFieldIndexRead for FieldIndex block with per-variant match arms (mirroring the existing style of get_telemetry_data / values_count / value_retriever). Dispatch is now fully static: FieldIndex::filter → variant match → concrete typed-index method, with no &dyn vtable hop.

FieldIndexRead keeps the seven enum-level methods that don't belong to any single typed-index variant (get_telemetry_data, values_count, values_is_empty, special_check_condition, value_retriever, as_numeric, as_facet_index).

Behavior unchanged — pure refactor.

Follow-up opportunities (out of scope)

PayloadFieldIndexRead no longer needs to be object-safe (no &dyn PayloadFieldIndexRead users remain), so two further dyn usages inside it become tractable as their own PRs:

  • filter returns Box<dyn Iterator<...> + 'a> — could become impl Iterator via RPITIT.
  • for_each_payload_block takes &mut dyn FnMut(...) — could become a generic impl FnMut(...).

Test plan

  • cargo build (full workspace)
  • cargo clippy -p segment --all-targets -- -D warnings
  • cargo test -p segment --lib — 666 passed
  • cargo test -p segment --test integration — 120 passed
  • cargo +nightly fmt --all -- --check

🤖 Generated with Claude Code

generall and others added 2 commits May 12, 2026 01:01
…ldIndexRead

Removes the `get_payload_field_index_read() -> &dyn PayloadFieldIndexRead`
bridge from `FieldIndexRead` and the five default impls that forwarded
through it. The overlapping read methods now come from the supertrait
directly, eliminating one layer of dynamic dispatch on the hot read path:
`FieldIndex::filter` → variant match → concrete typed-index method.

`FieldIndex` gains a direct `impl PayloadFieldIndexRead` block with
per-method match arms, mirroring the existing dispatch shape used by
`get_telemetry_data`, `values_count`, etc.

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

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1bb7aad3-2fb7-4682-b22c-dd1fa491c27d

📥 Commits

Reviewing files that changed from the base of the PR and between c2fb90d and 1c5ef05.

📒 Files selected for processing (13)
  • lib/segment/src/index/field_index/field_index_base/field_index_read.rs
  • lib/segment/src/index/field_index/field_index_base/field_index_read_impl.rs
  • lib/segment/src/index/field_index/field_index_base/payload_field_index.rs
  • lib/segment/src/index/field_index/full_text_index/tests/mod.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/index/field_index/numeric_index/builders.rs
  • lib/segment/src/index/field_index/numeric_index/index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/storage/mod.rs
  • lib/segment/src/index/field_index/numeric_index/storage/statistics.rs
  • lib/segment/src/index/field_index/numeric_index/storage/trait_impls.rs
  • lib/segment/src/index/field_index/numeric_index/tests.rs
  • lib/segment/src/index/field_index/numeric_index/value_indexer.rs

📝 Walkthrough

Walkthrough

FieldIndexRead now extends PayloadFieldIndexRead; FieldIndex implements PayloadFieldIndexRead directly and the previous delegating accessor and local condition_checker were removed. PayloadFieldIndexRead gained a default special_check_condition. FullTextIndex exposes special_check_condition. Numeric index was reorganized: added NumericIndex wrapper, NumericIndexInner storage dispatch, storage/statistics/trait_impls modules, builders for mutable/mmap/gridstore, a numeric value indexer with value_retrievers, and updated tests/imports.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

release:1.18.0

Suggested reviewers

  • coszio
  • ffuugoo
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main refactoring change: making FieldIndexRead a supertrait of PayloadFieldIndexRead, which is the core architectural change reflected across all modified files.
Description check ✅ Passed The description clearly explains the refactoring objectives, the specific methods involved, the removal of the bridge method, and the addition of direct PayloadFieldIndexRead implementation for FieldIndex, with comprehensive test coverage details.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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/field-index-read-supertrait

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.

* refactor(numeric_index): split mod.rs into focused submodules

`numeric_index/mod.rs` was 1308 lines mixing the storage-dispatch enum,
the public `NumericIndex<T, P>` wrapper, three builders, per-(T, P)
`ValueIndexer` impls, and the `Encodable`/`StreamRange` traits — hard
to navigate.

Split into:
- `mod.rs` keeps the shared traits (`Encodable`, `StreamRange`),
  `Range<T>::as_index_key_bounds`, and re-exports.
- `wrapper.rs` — `NumericIndex<T, P>` + inherent impl + `NumericIndexIntoInnerValue` trait.
- `builders.rs` — `NumericIndexBuilder`, `NumericIndexMmapBuilder`, `NumericIndexGridstoreBuilder`.
- `value_indexer.rs` — `ValueIndexer` and per-(T, P) `value_retriever` inherent impls.
- `storage/` — the `NumericIndexInner` dispatch enum:
  - `storage/mod.rs` — enum + simple match-and-forward (constructors, lifecycle, telemetry, per-point access).
  - `storage/statistics.rs` — histogram-driven cardinality and point-count helpers.
  - `storage/trait_impls.rs` — `PayloadFieldIndex`, `PayloadFieldIndexRead`, `StreamRange` impls.

Pure code reorganization — no behavior change. A few inherent methods
on `NumericIndexInner` had to widen from private to `pub(super)` /
`pub(in crate::index::field_index::numeric_index)` to remain reachable
across the new module boundaries (and from `tests.rs`); the new
constructors (`NumericIndexMmapBuilder::new`,
`NumericIndexGridstoreBuilder::new`) replace direct field
construction across files.

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

* refactor(numeric_index): rename wrapper.rs -> numeric_index.rs, move point_ids_by_value out of statistics

- Renamed `wrapper.rs` to `numeric_index.rs`, matching the central
  `NumericIndex` type and the surrounding module name.
- Moved `point_ids_by_value` from `storage/statistics.rs` to
  `storage/mod.rs` next to `get_values`. It is an exact value->points
  lookup primitive, not a cardinality estimate; the statistics module
  is left to the histogram-driven helpers.

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

* fix(clippy): rename numeric_index submodule to index to fix module_inception lint

Clippy's module_inception rule disallows a module with the same name as
its containing module. Rename numeric_index.rs -> index.rs and update
the three internal references.

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

* refactor(field_index): push PayloadFieldIndexRead through NumericIndex and move special_check_condition per-variant (#8998)

Two related cleanups that share a theme — drop enum-level read dispatch
in favor of per-variant trait impls:

1. `NumericIndex<T, P>` now implements `PayloadFieldIndexRead` directly
   (forwarding to its inner storage enum). The four numeric arms in
   `FieldIndex`'s `impl PayloadFieldIndexRead` drop their `.inner()`
   calls, so all eleven variants now use a uniform `idx.<method>(...)`
   form.

2. `special_check_condition` moves from `FieldIndexRead` to
   `PayloadFieldIndexRead` with a default `Ok(None)` body.
   `FullTextIndex` (the only variant with non-trivial logic) overrides
   it. `NumericIndex<T, P>` forwards through to the inner enum, and
   the `FieldIndex` enum's match dispatch moves out of `FieldIndexRead`
   into `PayloadFieldIndexRead` for consistency with the other five
   trait methods. Removed the now-redundant declaration from
   `FieldIndexRead` (inherited via the supertrait).

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Cursor <[email protected]>
@generall
generall merged commit 295e65e into dev May 12, 2026
12 checks passed
@generall
generall deleted the refactor/field-index-read-supertrait branch May 12, 2026 11:09
generall added a commit that referenced this pull request May 22, 2026
…ldIndexRead (#8996)

* refactor(field_index): make FieldIndexRead a supertrait of PayloadFieldIndexRead

Removes the `get_payload_field_index_read() -> &dyn PayloadFieldIndexRead`
bridge from `FieldIndexRead` and the five default impls that forwarded
through it. The overlapping read methods now come from the supertrait
directly, eliminating one layer of dynamic dispatch on the hot read path:
`FieldIndex::filter` → variant match → concrete typed-index method.

`FieldIndex` gains a direct `impl PayloadFieldIndexRead` block with
per-method match arms, mirroring the existing dispatch shape used by
`get_telemetry_data`, `values_count`, etc.

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

* chore: apply nightly rustfmt

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

* refactor(numeric_index): split mod.rs into focused submodules (#8997)

* refactor(numeric_index): split mod.rs into focused submodules

`numeric_index/mod.rs` was 1308 lines mixing the storage-dispatch enum,
the public `NumericIndex<T, P>` wrapper, three builders, per-(T, P)
`ValueIndexer` impls, and the `Encodable`/`StreamRange` traits — hard
to navigate.

Split into:
- `mod.rs` keeps the shared traits (`Encodable`, `StreamRange`),
  `Range<T>::as_index_key_bounds`, and re-exports.
- `wrapper.rs` — `NumericIndex<T, P>` + inherent impl + `NumericIndexIntoInnerValue` trait.
- `builders.rs` — `NumericIndexBuilder`, `NumericIndexMmapBuilder`, `NumericIndexGridstoreBuilder`.
- `value_indexer.rs` — `ValueIndexer` and per-(T, P) `value_retriever` inherent impls.
- `storage/` — the `NumericIndexInner` dispatch enum:
  - `storage/mod.rs` — enum + simple match-and-forward (constructors, lifecycle, telemetry, per-point access).
  - `storage/statistics.rs` — histogram-driven cardinality and point-count helpers.
  - `storage/trait_impls.rs` — `PayloadFieldIndex`, `PayloadFieldIndexRead`, `StreamRange` impls.

Pure code reorganization — no behavior change. A few inherent methods
on `NumericIndexInner` had to widen from private to `pub(super)` /
`pub(in crate::index::field_index::numeric_index)` to remain reachable
across the new module boundaries (and from `tests.rs`); the new
constructors (`NumericIndexMmapBuilder::new`,
`NumericIndexGridstoreBuilder::new`) replace direct field
construction across files.

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

* refactor(numeric_index): rename wrapper.rs -> numeric_index.rs, move point_ids_by_value out of statistics

- Renamed `wrapper.rs` to `numeric_index.rs`, matching the central
  `NumericIndex` type and the surrounding module name.
- Moved `point_ids_by_value` from `storage/statistics.rs` to
  `storage/mod.rs` next to `get_values`. It is an exact value->points
  lookup primitive, not a cardinality estimate; the statistics module
  is left to the histogram-driven helpers.

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

* fix(clippy): rename numeric_index submodule to index to fix module_inception lint

Clippy's module_inception rule disallows a module with the same name as
its containing module. Rename numeric_index.rs -> index.rs and update
the three internal references.

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

* refactor(field_index): push PayloadFieldIndexRead through NumericIndex and move special_check_condition per-variant (#8998)

Two related cleanups that share a theme — drop enum-level read dispatch
in favor of per-variant trait impls:

1. `NumericIndex<T, P>` now implements `PayloadFieldIndexRead` directly
   (forwarding to its inner storage enum). The four numeric arms in
   `FieldIndex`'s `impl PayloadFieldIndexRead` drop their `.inner()`
   calls, so all eleven variants now use a uniform `idx.<method>(...)`
   form.

2. `special_check_condition` moves from `FieldIndexRead` to
   `PayloadFieldIndexRead` with a default `Ok(None)` body.
   `FullTextIndex` (the only variant with non-trivial logic) overrides
   it. `NumericIndex<T, P>` forwards through to the inner enum, and
   the `FieldIndex` enum's match dispatch moves out of `FieldIndexRead`
   into `PayloadFieldIndexRead` for consistency with the other five
   trait methods. Removed the now-redundant declaration from
   `FieldIndexRead` (inherited via the supertrait).

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

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
Co-authored-by: Cursor Agent <[email protected]>
Co-authored-by: Cursor <[email protected]>

---------

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

1 participant