Skip to content

refactor: relocate read-view-exclusive helpers under read_view/ - #8977

Merged
generall merged 1 commit into
devfrom
read-view-relocate-helpers
May 10, 2026
Merged

generall merged 1 commit into
devfrom
read-view-relocate-helpers

Conversation

@generall

Copy link
Copy Markdown
Member

Summary

Step 3 of the StructPayloadIndexReadView ➜ FieldIndexRead track. After #8975 / #8976 introduced FieldIndexRead, the original step-3 plan was to migrate variant-destructuring helpers in query_optimization/condition_converter* and rescore_formula/value_retriever.rs to a FieldIndexRead bound. That migration isn't possible — every branch in those helpers reaches into a variant-specific predicate on the underlying typed index (MapIndex::check_values_any, FullTextIndex::parse_text_query, NumericIndex::get_values, …), and the variant match is the entire point.

The right shape is to co-locate the helpers with their only callers. Call-graph audit (grep -rn across the workspace) showed that:

  • field_condition_index, the entire match_converter submodule, get_range_*, get_geo_*, get_is_empty_indexes, get_null_index_is_empty_checker, get_fallback_is_empty_checker, get_is_null_checker, and variable_retriever (+ its payload_variable_retriever / indexed_variable_retriever siblings) are only called from struct_payload_index/read_view/.
  • check_field_condition and select_nested_indexes (in payload_storage/query_checker.rs) stay where they are — they have non-view callers.

Layout change

Before:

query_optimization/
├── condition_converter.rs           ←  helpers, called only from read view
├── condition_converter/
│   └── match_converter.rs           ←  match helpers, called only from read view
└── rescore_formula/
    └── value_retriever.rs           ←  VariableRetrieverFn + helpers

After:

struct_payload_index/read_view/
├── condition_converter/
│   ├── mod.rs                       ←  was read_view/condition_converter.rs
│   ├── helpers.rs                   ←  moved from query_optimization/
│   └── match_converter.rs           ←  moved from query_optimization/
└── value_retriever/
    ├── mod.rs                       ←  was read_view/value_retriever.rs
    └── helpers.rs                   ←  helpers from query_optimization/

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 move.

Visibility tightening

Cross-file entry points become pub(super). Purely-local helpers (get_range_checkers, get_float_range_checkers, get_datetime_range_checkers, get_geo_radius_checkers, get_geo_bounding_box_checkers, get_geo_polygon_checkers, get_is_empty_checker) become private. No public-API surface change.

Test plan

  • cargo build --workspace --tests (clean)
  • cargo test -p segment — 666 unit + 120 integration tests pass
  • cargo +nightly fmt --all -- --check (pre-push hook)
  • No behavioural change — pure file-move + import-path refactor

🤖 Generated with Claude Code

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

coderabbitai Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors the Qdrant codebase to localize condition_converter and value_retriever implementations from the query_optimization module hierarchy into struct_payload_index/read_view. The condition_converter is removed from public exports in query_optimization/mod.rs. Helper functions in condition_converter/helpers.rs are reduced from public to internal visibility (pub(super) or private). A new value_retriever/helpers.rs is created that implements index-based and payload-based value extraction with array flattening logic and type conversions for multiple FieldIndex variants. Both modules are rewired to source their helpers locally instead of from query_optimization.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • qdrant/qdrant#8841: Directly overlaps with this PR's refactoring that moves condition/value retriever logic out of query_optimization into struct_payload_index/read_view.
  • qdrant/qdrant#8969: Both PRs relocate condition_converter/value_retriever and update imports to use StructPayloadIndexReadView for helper sourcing.
  • qdrant/qdrant#8967: Related through the struct_payload_index module refactoring and the relocation of condition_converter/value_retriever helpers into local read_view modules.

Suggested reviewers

  • timvisee
  • dancixx
  • xzfc
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.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 accurately summarizes the main change: relocating read-view-exclusive helpers under the read_view directory structure as a refactoring effort.
Description check ✅ Passed The description thoroughly explains the rationale, layout changes, visibility tightening, and test plan for relocating helpers from query_optimization to struct_payload_index/read_view.
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 read-view-relocate-helpers

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.

🧹 Nitpick comments (1)
lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs (1)

221-229: ⚡ Quick win

Replace wildcard arm in get_is_empty_indexes with explicit FieldIndex variants.

Line 226 uses _, which can silently absorb future enum variants and hide behavior changes in this selection logic.

Suggested patch
     for index in indexes {
         match index {
             FieldIndex::NullIndex(null_index) => {
                 primary_null_index = Some(null_index);
             }
-            _ => {
+            FieldIndex::BoolIndex(_)
+            | FieldIndex::DatetimeIndex(_)
+            | FieldIndex::FloatIndex(_)
+            | FieldIndex::FullTextIndex(_)
+            | FieldIndex::GeoIndex(_)
+            | FieldIndex::IntIndex(_)
+            | FieldIndex::IntMapIndex(_)
+            | FieldIndex::KeywordIndex(_)
+            | FieldIndex::UuidIndex(_)
+            | FieldIndex::UuidMapIndex(_) => {
                 fallback_index = Some(index);
             }
         }
     }

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.”

🤖 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/struct_payload_index/read_view/condition_converter/helpers.rs`
around lines 221 - 229, The match in get_is_empty_indexes currently uses a
wildcard arm (_) which can hide new FieldIndex variants; update the match to
enumerate all existing FieldIndex variants explicitly (e.g.,
FieldIndex::NullIndex and each other current variant) and for each non-NullIndex
arm preserve the current behavior of assigning fallback_index = Some(index) (or
specific handling if a variant needs different logic), so that adding new
variants will force compile-time handling rather than being silently absorbed.
🤖 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.

Nitpick comments:
In
`@lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs`:
- Around line 221-229: The match in get_is_empty_indexes currently uses a
wildcard arm (_) which can hide new FieldIndex variants; update the match to
enumerate all existing FieldIndex variants explicitly (e.g.,
FieldIndex::NullIndex and each other current variant) and for each non-NullIndex
arm preserve the current behavior of assigning fallback_index = Some(index) (or
specific handling if a variant needs different logic), so that adding new
variants will force compile-time handling rather than being silently absorbed.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3c86e376-3855-4723-acf9-43f4882784b4

📥 Commits

Reviewing files that changed from the base of the PR and between b91c857 and b5b5ecb.

📒 Files selected for processing (7)
  • lib/segment/src/index/query_optimization/mod.rs
  • lib/segment/src/index/query_optimization/rescore_formula/value_retriever.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/helpers.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/match_converter.rs
  • lib/segment/src/index/struct_payload_index/read_view/condition_converter/mod.rs
  • lib/segment/src/index/struct_payload_index/read_view/value_retriever/helpers.rs
  • lib/segment/src/index/struct_payload_index/read_view/value_retriever/mod.rs
💤 Files with no reviewable changes (1)
  • lib/segment/src/index/query_optimization/mod.rs

@generall
generall merged commit 4a76439 into dev May 10, 2026
15 checks passed
@generall
generall deleted the read-view-relocate-helpers branch May 10, 2026 14:49
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