Skip to content

refactor: implement FieldIndexRead for FieldIndex - #8976

Merged
generall merged 2 commits into
devfrom
field-index-read-impl
May 10, 2026
Merged

generall merged 2 commits into
devfrom
field-index-read-impl

Conversation

@generall

@generall generall commented May 10, 2026 •

Copy link
Copy Markdown
Member

Summary

Follow-up to #8975. Move the 10 read-only inherent methods on FieldIndex into impl FieldIndexRead for FieldIndex. Bodies are unchanged. After this PR, every read-side caller resolves through the trait.

Methods moved onto the trait:

  • 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

Methods that stay inherent on FieldIndex (not on the trait):

  • Write: add_point, remove_point, wipe
  • Lifecycle / disk / metadata: flusher, files, immutable_files, ram_usage_bytes, is_on_disk, populate, clear_cache, get_full_index_type

Call-site fixes

Compiler-driven additions of use ... FieldIndexRead; in:

  • index/struct_payload_index/read_view/{payload_index_read,filtering}.rs
  • index/query_optimization/condition_converter.rs (and match_converter.rs)
  • payload_storage/query_checker.rs
  • index/field_index/full_text_index/tests/mod.rs
  • tests/integration/{payload_index_test,sparse_vector_index_search_tests}.rs

Drive-by cleanup (second commit)

StructPayloadIndex::get_facet_index had no callers anywhere in the workspace and was preserved across recent refactors. Removed in the second commit, along with the now-orphaned JsonPath and FacetIndexEnum imports. OperationError::MissingMapIndexForFacet stays — still used by segment::read_view::facet and lib/collection/src/operations/types.rs.

Test plan

  • cargo build --workspace --tests (clean)
  • cargo test -p segment (120/120 pass)
  • cargo +nightly fmt --all -- --check (pre-push hook)

🤖 Generated with Claude Code

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]>
@coderabbitai

coderabbitai Bot commented May 10, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors FieldIndex to adopt trait-based APIs. Query and inspection methods previously defined as inherent pub fns—including special_check_condition, filter, estimate_cardinality, get_telemetry_data, and value inspection—are moved into an impl FieldIndexRead for FieldIndex block. The adapters as_numeric and as_facet_index now return opaque impl Trait types (impl NumericFieldIndexRead and impl FacetIndex) instead of concrete types. StructPayloadIndex::get_facet_index was updated to pattern-match FieldIndex variants directly and construct FacetIndexEnum explicitly. Import statements across modules and tests were updated to include FieldIndexRead.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • qdrant/qdrant#8841: Introduced NumericFieldIndexRead and FacetIndex trait abstractions and related refactors.
  • qdrant/qdrant#8975: Completes FieldIndexRead trait implementation and caller updates.
  • qdrant/qdrant#8966: Similar extraction of read/query APIs into a separate read-only trait.

Suggested labels

release:1.18.0

Suggested reviewers

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

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% 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 'refactor: implement FieldIndexRead for FieldIndex' clearly and concisely summarizes the main change: moving read-only methods onto a new trait implementation.
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.
Description check ✅ Passed The PR description clearly describes the refactoring: moving 10 read-only inherent methods from FieldIndex to an impl FieldIndexRead trait block, with detailed call-site fixes and test plan provided.

✏️ 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-impl

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.

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
generall merged commit b91c857 into dev May 10, 2026
15 checks passed
@generall
generall deleted the field-index-read-impl branch May 10, 2026 13:54
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
* 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
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