Skip to content

Propagate OperationResult [3/4]: estimate_cardinality - #8446

Merged
xzfc merged 1 commit into
devfrom
uio-propagate-result-3
Mar 23, 2026
Merged

xzfc merged 1 commit into
devfrom
uio-propagate-result-3

Conversation

@xzfc

@xzfc xzfc commented Mar 18, 2026

Copy link
Copy Markdown
Member

Fourth commit in the stack #8433.

@xzfc xzfc mentioned this pull request Mar 18, 2026
@xzfc
xzfc marked this pull request as ready for review March 18, 2026 09:52
@xzfc
xzfc force-pushed the uio-propagate-result-2 branch from ab9e869 to 99299a6 Compare March 18, 2026 10:22
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch 2 times, most recently from b61f902 to 11444ac Compare March 18, 2026 10:31
@xzfc
xzfc force-pushed the uio-propagate-result-2 branch from 99299a6 to f5ddf7c Compare March 18, 2026 13:17
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from 11444ac to 337bfdf Compare March 18, 2026 13:17
@xzfc
xzfc force-pushed the uio-propagate-result-2 branch from f5ddf7c to c73b359 Compare March 18, 2026 13:32
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from 337bfdf to 7f74a36 Compare March 18, 2026 13:32
@xzfc
xzfc force-pushed the uio-propagate-result-2 branch from c73b359 to 70f5f6b Compare March 18, 2026 13:47
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from 7f74a36 to a047ac3 Compare March 18, 2026 13:47
@xzfc
xzfc force-pushed the uio-propagate-result-2 branch from 70f5f6b to d6f69f8 Compare March 18, 2026 15:23
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from a047ac3 to e5d91c8 Compare March 18, 2026 15:23
Base automatically changed from uio-propagate-result-2 to dev March 19, 2026 05:40
@xzfc
xzfc force-pushed the uio-propagate-result-3 branch from e5d91c8 to c9c1cca Compare March 19, 2026 05:48
@coderabbitai

coderabbitai Bot commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

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: 17397528-c03e-47f3-8695-f596c458fdce

📥 Commits

Reviewing files that changed from the base of the PR and between c9c1cca and c232229.

📒 Files selected for processing (33)
  • lib/collection/src/collection_manager/segments_searcher.rs
  • lib/segment/benches/boolean_filtering.rs
  • lib/segment/benches/conditional_search.rs
  • lib/segment/benches/range_filtering.rs
  • lib/segment/src/index/field_index/bool_index/mod.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/index/field_index/bool_index/simple_bool_index.rs
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/index/field_index/geo_index/mod.rs
  • lib/segment/src/index/field_index/map_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/hnsw_index/hnsw.rs
  • lib/segment/src/index/payload_index_base.rs
  • lib/segment/src/index/plain_payload_index.rs
  • lib/segment/src/index/plain_vector_index.rs
  • lib/segment/src/index/query_estimator.rs
  • lib/segment/src/index/query_optimization/optimizer.rs
  • lib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rs
  • lib/segment/src/index/sparse_index/sparse_vector_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/facet.rs
  • lib/segment/src/segment/formula_rescore.rs
  • lib/segment/src/segment/order_by.rs
  • lib/segment/src/segment/sampling.rs
  • lib/segment/src/segment/scroll.rs
  • lib/segment/tests/integration/exact_search_test.rs
  • lib/segment/tests/integration/filtering_context_check.rs
  • lib/segment/tests/integration/filtrable_hnsw_test.rs
  • lib/segment/tests/integration/nested_filtering_test.rs
  • lib/segment/tests/integration/payload_index_test.rs
✅ Files skipped from review due to trivial changes (3)
  • lib/segment/tests/integration/exact_search_test.rs
  • lib/segment/benches/range_filtering.rs
  • lib/segment/tests/integration/payload_index_test.rs
🚧 Files skipped from review as they are similar to previous changes (14)
  • lib/segment/tests/integration/filtering_context_check.rs
  • lib/segment/tests/integration/filtrable_hnsw_test.rs
  • lib/segment/src/segment/formula_rescore.rs
  • lib/segment/benches/conditional_search.rs
  • lib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rs
  • lib/segment/src/index/field_index/bool_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/index/field_index/bool_index/simple_bool_index.rs
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/query_estimator.rs
  • lib/segment/src/index/query_optimization/optimizer.rs

📝 Walkthrough

Walkthrough

This PR converts many previously infallible payload/index/query APIs to return OperationResult, changing return types across PayloadIndex and PayloadFieldIndex traits and their concrete implementations (field indices, geo/map/numeric/bool/full-text, HNSW, plain/sparse/struct indices). Call sites are updated to propagate errors with ? or to unwrap in tests/benches. Numerous segment, sampling, scroll, search, and optimization modules are adjusted to handle fallible cardinality estimation, filter contexts, and point queries. Tests and benchmarks are updated to .unwrap() on newly fallible calls.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Possibly related issues

Possibly related PRs

Suggested reviewers

  • xzfc
  • generall
  • agourlay
🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 74.02% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive The description 'Fourth commit in the stack #8433' is vague and does not meaningfully convey information about the changeset itself. Expand the description to explain what changes are being made, which APIs are being modified, and why OperationResult propagation is needed for estimate_cardinality.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The PR title 'Propagate OperationResult [3/4]: estimate_cardinality' clearly and specifically describes the main change: making the estimate_cardinality operation fallible by propagating OperationResult errors throughout the codebase.

✏️ 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 uio-propagate-result-3

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.

Tip

You can enable review details to help with troubleshooting, context usage and more.

Enable the reviews.review_details setting to include review details such as the model used, the time taken for each step and more in the review comments.

@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 (5)
lib/segment/src/index/field_index/map_index/mod.rs (1)

809-863: Please enumerate the unsupported Match cases explicitly.

All three updated estimators still end with _ => None, which means a newly added Match variant will be ignored by cardinality planning instead of triggering a compile-time review in these index routers.

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

Also applies to: 981-1056, 1154-1208

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/map_index/mod.rs` around lines 809 - 863,
The match on condition.r#match currently ends with a catch-all `_ => None`;
replace that catch-all with explicit arms for every remaining Match enum variant
not already handled (i.e., add explicit Match::X(...) => None stubs or real
handling) instead of `_`, so new variants trigger compile-time review; update
the same change in the other two similar match blocks referenced (the blocks
around the other ranges) and keep the existing handled arms (Match::Value,
Match::Any, Match::Except) unchanged while adding explicit unsupported arms with
a short comment like "unsupported by map_index".
lib/segment/src/index/field_index/full_text_index/text_index.rs (1)

618-623: Make the Match dispatch explicit here.

This new estimator path uses a catch-all _ arm, so a future Match variant will silently fall into Ok(None) instead of forcing an explicit decision in full-text routing.

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 the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/full_text_index/text_index.rs` around lines
618 - 623, The match over condition.r#match currently uses a catch-all `_` arm
which hides future Match variants; replace the `_` arm with explicit match arms
for every current Match variant (e.g., Match::Text =>
self.parse_text_query(text, hw_counter), Match::Phrase =>
self.parse_phrase_query(phrase, hw_counter), plus explicit arms for any other
existing Match::... variants) and have each arm either call the appropriate
parser or return Ok(None) as intended so new variants will force you to handle
them at compile time (remove the wildcard to ensure exhaustiveness).
lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs (1)

399-420: Prefer an explicit match here instead of _ => None.

Since this function is already being updated, expanding the match keeps future Match variants compiler-visible instead of silently treating them as unsupported. 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 the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs` around
lines 399 - 420, The match in estimate_cardinality currently uses a catch-all `_
=> None`; replace that with an explicit match over all Match enum variants
(e.g., Match::Value(...), Match::Range(...), Match::OneOf(...), etc.) so each
variant is spelled out and unsupported variants explicitly return None; update
the match arms in the estimate_cardinality function (referencing FieldCondition
and Match) to keep the compiler checking future enum additions rather than
silently matching `_`, leaving the existing handling for
Match::Value(ValueVariants::Bool(...)) intact and returning Some(estimation)
there while returning None in the other explicit arms.
lib/segment/src/index/field_index/bool_index/simple_bool_index.rs (1)

371-392: Prefer an explicit match here instead of _ => None.

Now that this function is being touched, the catch-all arm will silently accept future Match variants without forcing a decision on whether the bool index should support them. 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 the current code and only fix it if needed.

In `@lib/segment/src/index/field_index/bool_index/simple_bool_index.rs` around
lines 371 - 392, The match in estimate_cardinality currently uses a catch-all `_
=> None`; replace that with explicit arms for each current Match enum variant so
unsupported variants return None individually (e.g., add explicit arms like
Match::Range(..) => None, Match::Values(..) => None, etc.), ensuring the match
is exhaustive without a wildcard so future Match variants will force a
compile-time decision; keep the existing Bool arm (Match::Value with
ValueVariants::Bool) and the construction of CardinalityEstimation as-is.
lib/segment/src/index/struct_payload_index.rs (1)

120-127: Consider naming the transpose bridge.

find_map(...transpose()).transpose() is correct, but it takes a moment to reconstruct the Option<Result<_>> / Result<Option<_>> flow. A tiny helper or short comment here would make this new error-propagation path easier to maintain.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/segment/src/index/struct_payload_index.rs` around lines 120 - 127, The
expression using chained transposes (indexes.iter().find_map(|index|
index.estimate_cardinality(&full_path_condition,
hw_counter).transpose()).transpose()) is correct but confusing; introduce a
small named helper or intermediate variable (e.g., let transpose_bridge =
|opt_res: Option<Result<T, E>>| -> Result<Option<T>, E> { opt_res.transpose() }
or name the intermediate result like found_cardinality =
indexes.iter().find_map(...).transpose() ) or add a one-line comment explaining
the Option<Result<_>> → Result<Option<_>> conversion to make the intent clear
and reference estimate_cardinality, full_path_condition, hw_counter and the
find_map call when locating the code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs`:
- Around line 399-420: The match in estimate_cardinality currently uses a
catch-all `_ => None`; replace that with an explicit match over all Match enum
variants (e.g., Match::Value(...), Match::Range(...), Match::OneOf(...), etc.)
so each variant is spelled out and unsupported variants explicitly return None;
update the match arms in the estimate_cardinality function (referencing
FieldCondition and Match) to keep the compiler checking future enum additions
rather than silently matching `_`, leaving the existing handling for
Match::Value(ValueVariants::Bool(...)) intact and returning Some(estimation)
there while returning None in the other explicit arms.

In `@lib/segment/src/index/field_index/bool_index/simple_bool_index.rs`:
- Around line 371-392: The match in estimate_cardinality currently uses a
catch-all `_ => None`; replace that with explicit arms for each current Match
enum variant so unsupported variants return None individually (e.g., add
explicit arms like Match::Range(..) => None, Match::Values(..) => None, etc.),
ensuring the match is exhaustive without a wildcard so future Match variants
will force a compile-time decision; keep the existing Bool arm (Match::Value
with ValueVariants::Bool) and the construction of CardinalityEstimation as-is.

In `@lib/segment/src/index/field_index/full_text_index/text_index.rs`:
- Around line 618-623: The match over condition.r#match currently uses a
catch-all `_` arm which hides future Match variants; replace the `_` arm with
explicit match arms for every current Match variant (e.g., Match::Text =>
self.parse_text_query(text, hw_counter), Match::Phrase =>
self.parse_phrase_query(phrase, hw_counter), plus explicit arms for any other
existing Match::... variants) and have each arm either call the appropriate
parser or return Ok(None) as intended so new variants will force you to handle
them at compile time (remove the wildcard to ensure exhaustiveness).

In `@lib/segment/src/index/field_index/map_index/mod.rs`:
- Around line 809-863: The match on condition.r#match currently ends with a
catch-all `_ => None`; replace that catch-all with explicit arms for every
remaining Match enum variant not already handled (i.e., add explicit
Match::X(...) => None stubs or real handling) instead of `_`, so new variants
trigger compile-time review; update the same change in the other two similar
match blocks referenced (the blocks around the other ranges) and keep the
existing handled arms (Match::Value, Match::Any, Match::Except) unchanged while
adding explicit unsupported arms with a short comment like "unsupported by
map_index".

In `@lib/segment/src/index/struct_payload_index.rs`:
- Around line 120-127: The expression using chained transposes
(indexes.iter().find_map(|index|
index.estimate_cardinality(&full_path_condition,
hw_counter).transpose()).transpose()) is correct but confusing; introduce a
small named helper or intermediate variable (e.g., let transpose_bridge =
|opt_res: Option<Result<T, E>>| -> Result<Option<T>, E> { opt_res.transpose() }
or name the intermediate result like found_cardinality =
indexes.iter().find_map(...).transpose() ) or add a one-line comment explaining
the Option<Result<_>> → Result<Option<_>> conversion to make the intent clear
and reference estimate_cardinality, full_path_condition, hw_counter and the
find_map call when locating the code.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 75138cb0-1329-41a2-be2f-42aa509c0eee

📥 Commits

Reviewing files that changed from the base of the PR and between 9aaa7c6 and c9c1cca.

📒 Files selected for processing (33)
  • lib/collection/src/collection_manager/segments_searcher.rs
  • lib/segment/benches/boolean_filtering.rs
  • lib/segment/benches/conditional_search.rs
  • lib/segment/benches/range_filtering.rs
  • lib/segment/src/index/field_index/bool_index/mod.rs
  • lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
  • lib/segment/src/index/field_index/bool_index/simple_bool_index.rs
  • lib/segment/src/index/field_index/field_index_base.rs
  • lib/segment/src/index/field_index/full_text_index/text_index.rs
  • lib/segment/src/index/field_index/geo_index/mod.rs
  • lib/segment/src/index/field_index/map_index/mod.rs
  • lib/segment/src/index/field_index/null_index/mutable_null_index.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/hnsw_index/hnsw.rs
  • lib/segment/src/index/payload_index_base.rs
  • lib/segment/src/index/plain_payload_index.rs
  • lib/segment/src/index/plain_vector_index.rs
  • lib/segment/src/index/query_estimator.rs
  • lib/segment/src/index/query_optimization/optimizer.rs
  • lib/segment/src/index/query_optimization/rescore_formula/formula_scorer.rs
  • lib/segment/src/index/sparse_index/sparse_vector_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/facet.rs
  • lib/segment/src/segment/formula_rescore.rs
  • lib/segment/src/segment/order_by.rs
  • lib/segment/src/segment/sampling.rs
  • lib/segment/src/segment/scroll.rs
  • lib/segment/tests/integration/exact_search_test.rs
  • lib/segment/tests/integration/filtering_context_check.rs
  • lib/segment/tests/integration/filtrable_hnsw_test.rs
  • lib/segment/tests/integration/nested_filtering_test.rs
  • lib/segment/tests/integration/payload_index_test.rs

@xzfc
xzfc merged commit 6ddb81d into dev Mar 23, 2026
15 checks passed
@xzfc
xzfc deleted the uio-propagate-result-3 branch March 23, 2026 11:51
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.

2 participants