Skip to content

refactor: introduce FieldIndexRead trait - #8975

Merged
generall merged 1 commit into
devfrom
field-index-read-trait
May 10, 2026
Merged

generall merged 1 commit into
devfrom
field-index-read-trait

Conversation

@generall

Copy link
Copy Markdown
Member

Summary

Mirror the PayloadFieldIndex / PayloadFieldIndexRead split (#8966) one layer up at the FieldIndex enum level. FieldIndexRead names the uniform read-only surface that StructPayloadIndexReadView and its helpers reach through IndexesMap:

  • count_indexed_points, filter, estimate_cardinality, for_each_payload_block
  • get_telemetry_data, values_count, values_is_empty, special_check_condition
  • as_numeric, as_facet_index

Lifecycle / disk methods (flusher, files, is_on_disk, populate, clear_cache, ram_usage_bytes, get_full_index_type) and write methods (add_point, remove_point, wipe) stay off the trait — they have no read-side callers.

This PR is trait declaration only — no impl, no consumers, purely additive. Two follow-up PRs (already planned) will:

  1. impl FieldIndexRead for FieldIndex and remove the now-duplicated inherent methods so call sites resolve through the trait.
  2. Migrate get_fallback_is_empty_checker to a FieldIndexRead bound. Variant-destructuring helpers (field_condition_index, match_converter, get_range_*, get_geo_*, indexed_variable_retriever) keep &FieldIndex — they reach into variant-specific predicates on the underlying typed indexes that aren't on the uniform trait.

Why generics on as_numeric / as_facet_index

Both methods use return-position impl Trait (Option<impl NumericFieldIndexRead + '_> / Option<impl FacetIndex + '_>), matching the shape PayloadIndexRead::numeric_index_for / facet_index_for already use. The concrete numeric/facet types stay opaque per implementation. Consequence: FieldIndexRead is not object-safe; follow-up consumers will use a generic bound (<I: FieldIndexRead + ?Sized>) rather than &dyn FieldIndexRead. Static dispatch, no v-table — same approach as PayloadIndexRead.

Test plan

  • cargo build -p segment
  • cargo build --workspace
  • No new tests in this PR — trait has no callers yet. Coverage lands with the impl in the follow-up.

🤖 Generated with Claude Code

Mirror the PayloadFieldIndex / PayloadFieldIndexRead split (#8966) one layer
up at the FieldIndex enum level. FieldIndexRead names the uniform read-only
surface (filter, estimate_cardinality, count_indexed_points,
for_each_payload_block, get_telemetry_data, values_count, values_is_empty,
special_check_condition, as_numeric, as_facet_index) — the methods that
StructPayloadIndexReadView and its helpers reach through IndexesMap.

Trait declaration only. No impl, no callers in this PR — this is purely
additive. Follow-up PRs will impl it on FieldIndex, then migrate
non-destructuring helpers to a FieldIndexRead bound.

as_numeric and as_facet_index use return-position impl Trait
(impl NumericFieldIndexRead + '_, impl FacetIndex + '_), matching how
PayloadIndexRead exposes the same shapes. The trait is therefore not
object-safe; consumers will use a generic bound rather than
&dyn FieldIndexRead.

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

coderabbitai Bot commented May 10, 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: f14fce6c-8fb1-4603-b8cf-4bc7a904b330

📥 Commits

Reviewing files that changed from the base of the PR and between 39d32bb and 7a9c3c5.

📒 Files selected for processing (2)
  • lib/segment/src/index/field_index/field_index_base/field_index_read.rs
  • lib/segment/src/index/field_index/field_index_base/mod.rs

📝 Walkthrough

Walkthrough

This PR introduces a new read-only trait FieldIndexRead that abstracts uniform query operations across field index variants. The trait exposes 10 methods: counting indexed points, filtering point offsets by conditions, estimating cardinality, iterating payload blocks, retrieving telemetry, inspecting per-point values, performing special condition checks, and providing borrowed views for numeric and facet indices. The new trait is declared in a dedicated submodule field_index_read and publicly re-exported from field_index_base.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • qdrant/qdrant#8966: Introduces a separate read-only trait (PayloadFieldIndexRead) and splits read/query methods from write/lifecycle methods, paralleling the FieldIndexRead abstraction in this PR.
  • qdrant/qdrant#8965: Restructures field_index_base module by splitting files into submodules and introducing read-only index traits (NumericFieldIndexRead), directly related to this PR's module reorganization.
  • qdrant/qdrant#8967: Restructures StructPayloadIndex to depend on per-field read interfaces (numeric/facet views and block iteration), likely to wire StructPayloadIndex to the new FieldIndexRead surface.

Suggested reviewers

  • dancixx
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: introducing the FieldIndexRead trait as a refactoring effort.
Description check ✅ Passed The description is well-detailed and directly related to the changeset, explaining the trait's purpose, methods, design decisions, and planned follow-ups.
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 field-index-read-trait

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.

@generall
generall merged commit 393f059 into dev May 10, 2026
15 checks passed
@generall
generall deleted the field-index-read-trait branch May 10, 2026 12:56
generall added a commit that referenced this pull request May 10, 2026
The helpers in query_optimization/condition_converter{,/match_converter}.rs
and the bulk of query_optimization/rescore_formula/value_retriever.rs were
only ever called from struct_payload_index/read_view/. Move them next to
their callers.

The trait split work (#8975, #8976) showed why these helpers can't migrate
to a uniform FieldIndexRead bound: every branch in field_condition_index,
match_converter, get_range_*, get_geo_*, indexed_variable_retriever
destructures FieldIndex variants and reaches into variant-specific
predicates on the underlying typed indexes (MapIndex::check_values_any,
FullTextIndex::parse_*_query, NumericIndex::get_values, …). The variant
match is the whole point of these helpers; co-locating them with the read
view is the right shape.

New layout:
- read_view/condition_converter/{mod.rs, helpers.rs, match_converter.rs}
  (was a flat read_view/condition_converter.rs + scattered query_optimization
  files)
- read_view/value_retriever/{mod.rs, helpers.rs}
  (was a flat read_view/value_retriever.rs + query_optimization/rescore_formula/
  value_retriever.rs)

VariableRetrieverFn type alias stays in query_optimization/rescore_formula/
value_retriever.rs (now a 6-line file): formula_scorer.rs in the same module
uses it as a struct field, so the type belongs there. Only the helper
functions and their tests move.

Visibility tightened where natural: cross-file entry points are
pub(super), purely-local helpers are private, public-API surface is
unchanged.

No behavioural change. cargo test -p segment: 666 unit + 120 integration
tests pass.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 22, 2026
Mirror the PayloadFieldIndex / PayloadFieldIndexRead split (#8966) one layer
up at the FieldIndex enum level. FieldIndexRead names the uniform read-only
surface (filter, estimate_cardinality, count_indexed_points,
for_each_payload_block, get_telemetry_data, values_count, values_is_empty,
special_check_condition, as_numeric, as_facet_index) — the methods that
StructPayloadIndexReadView and its helpers reach through IndexesMap.

Trait declaration only. No impl, no callers in this PR — this is purely
additive. Follow-up PRs will impl it on FieldIndex, then migrate
non-destructuring helpers to a FieldIndexRead bound.

as_numeric and as_facet_index use return-position impl Trait
(impl NumericFieldIndexRead + '_, impl FacetIndex + '_), matching how
PayloadIndexRead exposes the same shapes. The trait is therefore not
object-safe; consumers will use a generic bound rather than
&dyn FieldIndexRead.

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
generall added a commit that referenced this pull request May 22, 2026
The helpers in query_optimization/condition_converter{,/match_converter}.rs
and the bulk of query_optimization/rescore_formula/value_retriever.rs were
only ever called from struct_payload_index/read_view/. Move them next to
their callers.

The trait split work (#8975, #8976) showed why these helpers can't migrate
to a uniform FieldIndexRead bound: every branch in field_condition_index,
match_converter, get_range_*, get_geo_*, indexed_variable_retriever
destructures FieldIndex variants and reaches into variant-specific
predicates on the underlying typed indexes (MapIndex::check_values_any,
FullTextIndex::parse_*_query, NumericIndex::get_values, …). The variant
match is the whole point of these helpers; co-locating them with the read
view is the right shape.

New layout:
- read_view/condition_converter/{mod.rs, helpers.rs, match_converter.rs}
  (was a flat read_view/condition_converter.rs + scattered query_optimization
  files)
- read_view/value_retriever/{mod.rs, helpers.rs}
  (was a flat read_view/value_retriever.rs + query_optimization/rescore_formula/
  value_retriever.rs)

VariableRetrieverFn type alias stays in query_optimization/rescore_formula/
value_retriever.rs (now a 6-line file): formula_scorer.rs in the same module
uses it as a struct field, so the type belongs there. Only the helper
functions and their tests move.

Visibility tightened where natural: cross-file entry points are
pub(super), purely-local helpers are private, public-API surface is
unchanged.

No behavioural change. cargo test -p segment: 666 unit + 120 integration
tests pass.

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