Repository navigation
refactor(field_index): make FieldIndexRead a supertrait of PayloadFieldIndexRead - #8996
Conversation
…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]>
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
📝 WalkthroughWalkthroughFieldIndexRead 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
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
* 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]>
…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]>
Summary
FieldIndexRead: PayloadFieldIndexReada supertrait. The five overlapping read methods (count_indexed_points,filter,estimate_cardinality,for_each_payload_block,condition_checker) now come from the supertrait directly.get_payload_field_index_read() -> &dyn PayloadFieldIndexReadbridge method and the five default impls that delegated through it.impl PayloadFieldIndexRead for FieldIndexblock with per-variant match arms (mirroring the existing style ofget_telemetry_data/values_count/value_retriever). Dispatch is now fully static:FieldIndex::filter→ variant match → concrete typed-index method, with no&dynvtable hop.FieldIndexReadkeeps 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)
PayloadFieldIndexReadno longer needs to be object-safe (no&dyn PayloadFieldIndexReadusers remain), so two furtherdynusages inside it become tractable as their own PRs:filterreturnsBox<dyn Iterator<...> + 'a>— could becomeimpl Iteratorvia RPITIT.for_each_payload_blocktakes&mut dyn FnMut(...)— could become a genericimpl FnMut(...).Test plan
cargo build(full workspace)cargo clippy -p segment --all-targets -- -D warningscargo test -p segment --lib— 666 passedcargo test -p segment --test integration— 120 passedcargo +nightly fmt --all -- --check🤖 Generated with Claude Code