Repository navigation
Propagate OperationResult [1/4]: payload_blocks - #8444
Conversation
| let blocks: Vec<_> = indexes | ||
| .iter() | ||
| .map(|field_index| field_index.payload_blocks(threshold, field_clone.clone())) | ||
| .process_results(|iter| iter.collect_vec())?; | ||
| Ok(Box::new(blocks.into_iter().flatten())) |
There was a problem hiding this comment.
this is questionable. I would prefer to avoid collect
There was a problem hiding this comment.
I though it's acceptable to collect these because:
- It's only used during HNSW building, and I took an assumption that the total number of payload blocks shouldn't be that high.
- Many payload indices do something like
.collect_vec().into_iter()anyway internally.
But fixed anyway (now it's an iterator of results).
672931b to
232e5d0
Compare
📝 WalkthroughWalkthroughThis PR systematically updates the Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
lib/segment/src/index/field_index/bool_index/simple_bool_index.rs (1)
395-424:⚠️ Potential issue | 🔴 CriticalUpdate
SimpleBoolIndex::payload_blockssignature and error handling to match the trait contract.The return type and error wrapping are incorrect. The trait expects
Box<dyn Iterator<Item = OperationResult<PayloadBlockCondition>> + '_>, but this impl returnsOperationResult<Box<dyn Iterator<Item = PayloadBlockCondition> + '_>>. All other trait implementations (MapIndex, MutableNullIndex, FullTextIndex) have been updated. Wrap individual items withOk()and remove the outerOk()around the iterator.Suggested fix
fn payload_blocks( &self, threshold: usize, key: PayloadKeyType, - ) -> OperationResult<Box<dyn Iterator<Item = PayloadBlockCondition> + '_>> { + ) -> Box<dyn Iterator<Item = OperationResult<PayloadBlockCondition>> + '_> { let make_block = |count, value, key: PayloadKeyType| { if count > threshold { - Some(PayloadBlockCondition { + Some(Ok(PayloadBlockCondition { condition: FieldCondition::new_match( key, Match::Value(MatchValue { value: ValueVariants::Bool(value), }), ), cardinality: count, - }) + })) } else { None } }; // just two possible blocks: true and false let iter = [ make_block(self.memory.trues_count(), true, key.clone()), make_block(self.memory.falses_count(), false, key), ] .into_iter() .flatten(); - Ok(Box::new(iter)) + Box::new(iter) }🤖 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 395 - 424, The implementation of SimpleBoolIndex::payload_blocks currently returns OperationResult<Box<dyn Iterator<Item = PayloadBlockCondition> + '_>> but must match the trait and return Box<dyn Iterator<Item = OperationResult<PayloadBlockCondition>> + '_>; change the function signature accordingly, modify the local make_block closure to produce Option<OperationResult<PayloadBlockCondition>> (i.e., wrap each constructed PayloadBlockCondition in Ok(...)), remove the outer Ok(...) wrapping the iterator, and ensure the iterator yields Ok(PayloadBlockCondition) items for true and false branches (referencing make_block, PayloadBlockCondition, FieldCondition::new_match, Match::Value, and OperationResult).lib/segment/src/index/field_index/geo_index/mod.rs (1)
1240-1251:⚠️ Potential issue | 🔴 CriticalFix
.unwrap()calls that are now on iterators yieldingOperationResultitems.
large_hashesandpayload_blocksnow return iterators where each yielded item is anOperationResult, not a direct value. Calling.unwrap()on the iterator itself will not compile. Unwrap each item as you consume it using.map(Result::unwrap):Affected locations
- let block_hashes = field_index.large_hashes(100).unwrap().collect_vec(); + let block_hashes = field_index + .large_hashes(100) + .map(Result::unwrap) + .collect_vec();- let blocks = field_index - .payload_blocks(100, JsonPath::new("test")) - .unwrap() - .collect_vec(); + let blocks = field_index + .payload_blocks(100, JsonPath::new("test")) + .map(Result::unwrap) + .collect_vec();- .large_hashes(20) - .unwrap() - .map(|(hash, _)| hash) + .large_hashes(20) + .map(Result::unwrap) + .map(|(hash, _)| hash)🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@lib/segment/src/index/field_index/geo_index/mod.rs` around lines 1240 - 1251, The tests call field_index.large_hashes(100) and field_index.payload_blocks(100, JsonPath::new("test")) but those iterators now yield OperationResult items, so calling .unwrap() on the iterator is wrong; change the consumption to unwrap each yielded item (e.g., chain .map(Result::unwrap) or equivalent) before collecting/using values so you get the inner values for assertions; update the block_hashes and blocks usage to map each item through Result::unwrap (or handle errors) when iterating over large_hashes and payload_blocks.
🧹 Nitpick comments (1)
lib/segment/src/index/field_index/map_index/mod.rs (1)
881-883: Use explicit conversions instead of.into()in these new match builders.These call sites hide the target type and violate the repo's Rust conversion rule. Please switch them to the concrete
...::from(...)expected byFieldCondition::new_match.As per coding guidelines, "Prefer explicit
SomeType::from(x)over implicitx.into()in Rust".Also applies to: 1068-1073, 1220-1222
🤖 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 881 - 883, Replace the implicit .into() conversions used when constructing PayloadBlockCondition/FieldCondition (e.g., in the closure mapping that calls FieldCondition::new_match with key.clone() and value.to_string().into()) with the concrete From conversion type expected by FieldCondition::new_match (call the appropriate concrete type::from(value.to_string()) instead of .into()); apply the same change to the other occurrences mentioned around the other match builders (the map sites at the other ranges), so all implicit .into() calls are explicit SomeConcreteType::from(...) matching FieldCondition::new_match's parameter type.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@lib/segment/src/index/field_index/bool_index/mod.rs`:
- Around line 551-554: payload_blocks now returns a boxed iterator over
OperationResult items, so calling .unwrap() on the iterator and then
.collect_vec() fails; instead unwrap the Result around payload_blocks to get the
Box<dyn Iterator<Item = OperationResult<_>>> and then map each yielded
OperationResult to unwrap it before collecting — e.g. call
index.payload_blocks(0, JsonPath::new(FIELD_NAME)).unwrap().map(|r|
r.unwrap()).collect_vec() (i.e., use payload_blocks, JsonPath::new, FIELD_NAME
and unwrap each OperationResult yielded).
In `@lib/segment/src/index/field_index/map_index/mod.rs`:
- Around line 1511-1514: The code calls .unwrap() on the iterator returned by
index.payload_blocks(50, PayloadKeyType::new("test_uuid")) but payload_blocks
returns Box<dyn Iterator<Item = OperationResult<PayloadBlockCondition>>>, so
move the unwrap to each yielded item: iterate over index.payload_blocks(...)
without .unwrap(), and inside the loop call .unwrap() (or handle the error) on
the loop variable (e.g., let block = block.unwrap();), referencing the
payload_blocks function, PayloadKeyType::new("test_uuid"), and the
OperationResult<PayloadBlockCondition> item type.
In `@lib/segment/tests/integration/exact_search_test.rs`:
- Around line 96-99: The code calls unwrap() on the Box<dyn Iterator< Item =
OperationResult<PayloadBlockCondition> >> returned by
PayloadIndex::payload_blocks, but unwrap() must be applied to each
OperationResult item instead of the iterator; update the chain so you first
obtain the iterator from
borrowed_payload_index.payload_blocks(&JsonPath::new(int_key),
indexing_threshold) (no unwrap), then map or collect the iterator while
unwrapping each item (e.g. .map(|r| r.unwrap()).collect_vec() or collect into a
Result and handle errors) so you unwrap each
OperationResult<PayloadBlockCondition> rather than the iterator itself.
In `@lib/segment/tests/integration/filtrable_hnsw_test.rs`:
- Around line 119-122: The current code calls .unwrap() on the boxed iterator
returned by borrowed_payload_index.payload_blocks(...) but the iterator yields
OperationResult<PayloadBlockCondition>, so you must instead unwrap each item;
replace the direct .unwrap() on the Box with mapping the iterator items to
unwrap (e.g., .map(Result::unwrap) or .map(|r| r.unwrap())) before
collecting—apply the same fix to the other occurrence at the later call (the one
around line 306) so both uses of payload_blocks (called with
JsonPath::new(int_key) and indexing_threshold) unwrap each Result item rather
than the iterator itself.
---
Outside diff comments:
In `@lib/segment/src/index/field_index/bool_index/simple_bool_index.rs`:
- Around line 395-424: The implementation of SimpleBoolIndex::payload_blocks
currently returns OperationResult<Box<dyn Iterator<Item = PayloadBlockCondition>
+ '_>> but must match the trait and return Box<dyn Iterator<Item =
OperationResult<PayloadBlockCondition>> + '_>; change the function signature
accordingly, modify the local make_block closure to produce
Option<OperationResult<PayloadBlockCondition>> (i.e., wrap each constructed
PayloadBlockCondition in Ok(...)), remove the outer Ok(...) wrapping the
iterator, and ensure the iterator yields Ok(PayloadBlockCondition) items for
true and false branches (referencing make_block, PayloadBlockCondition,
FieldCondition::new_match, Match::Value, and OperationResult).
In `@lib/segment/src/index/field_index/geo_index/mod.rs`:
- Around line 1240-1251: The tests call field_index.large_hashes(100) and
field_index.payload_blocks(100, JsonPath::new("test")) but those iterators now
yield OperationResult items, so calling .unwrap() on the iterator is wrong;
change the consumption to unwrap each yielded item (e.g., chain
.map(Result::unwrap) or equivalent) before collecting/using values so you get
the inner values for assertions; update the block_hashes and blocks usage to map
each item through Result::unwrap (or handle errors) when iterating over
large_hashes and payload_blocks.
---
Nitpick comments:
In `@lib/segment/src/index/field_index/map_index/mod.rs`:
- Around line 881-883: Replace the implicit .into() conversions used when
constructing PayloadBlockCondition/FieldCondition (e.g., in the closure mapping
that calls FieldCondition::new_match with key.clone() and
value.to_string().into()) with the concrete From conversion type expected by
FieldCondition::new_match (call the appropriate concrete
type::from(value.to_string()) instead of .into()); apply the same change to the
other occurrences mentioned around the other match builders (the map sites at
the other ranges), so all implicit .into() calls are explicit
SomeConcreteType::from(...) matching FieldCondition::new_match's parameter type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5495bcbd-6ecd-4b5f-95f7-1fa6eb82146d
📒 Files selected for processing (21)
lib/segment/src/index/field_index/bool_index/mod.rslib/segment/src/index/field_index/bool_index/mutable_bool_index.rslib/segment/src/index/field_index/bool_index/simple_bool_index.rslib/segment/src/index/field_index/field_index_base.rslib/segment/src/index/field_index/full_text_index/inverted_index/mod.rslib/segment/src/index/field_index/full_text_index/tests/test_congruence.rslib/segment/src/index/field_index/full_text_index/text_index.rslib/segment/src/index/field_index/geo_index/immutable_geo_index.rslib/segment/src/index/field_index/geo_index/mmap_geo_index.rslib/segment/src/index/field_index/geo_index/mod.rslib/segment/src/index/field_index/geo_index/mutable_geo_index.rslib/segment/src/index/field_index/map_index/mod.rslib/segment/src/index/field_index/null_index/mutable_null_index.rslib/segment/src/index/field_index/numeric_index/mod.rslib/segment/src/index/field_index/numeric_index/tests.rslib/segment/src/index/hnsw_index/hnsw.rslib/segment/src/index/payload_index_base.rslib/segment/src/index/plain_payload_index.rslib/segment/src/index/struct_payload_index.rslib/segment/tests/integration/exact_search_test.rslib/segment/tests/integration/filtrable_hnsw_test.rs
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/segment/src/index/field_index/map_index/mod.rs (1)
880-880:⚠️ Potential issue | 🟡 MinorInconsistent threshold comparison across
MapIndexvariants.
MapIndex<str>uses strict greater-than (*count > threshold) at line 880, whileMapIndex<UuidIntType>andMapIndex<IntPayloadType>use greater-than-or-equal (*count >= threshold) at lines 1067 and 1219.This inconsistency means the same
thresholdvalue yields different block filtering behavior depending on the index type. Please verify whether this is intentional or if all variants should use the same comparison operator.Also applies to: 1067-1067, 1219-1219
🤖 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` at line 880, MapIndex variants currently use inconsistent count comparisons: MapIndex<str> uses "*count > threshold" while MapIndex<UuidIntType> and MapIndex<IntPayloadType> use "*count >= threshold"; decide which semantics is correct and make all variants consistent by updating the filter closure used in the MapIndex block-filtering logic (the closure ".filter(move |(_value, count)| ... )" inside the MapIndex implementations) to use the chosen operator across MapIndex<str>, MapIndex<UuidIntType>, and MapIndex<IntPayloadType> so all three use the same comparison against threshold.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@lib/segment/src/index/field_index/map_index/mod.rs`:
- Line 880: MapIndex variants currently use inconsistent count comparisons:
MapIndex<str> uses "*count > threshold" while MapIndex<UuidIntType> and
MapIndex<IntPayloadType> use "*count >= threshold"; decide which semantics is
correct and make all variants consistent by updating the filter closure used in
the MapIndex block-filtering logic (the closure ".filter(move |(_value, count)|
... )" inside the MapIndex implementations) to use the chosen operator across
MapIndex<str>, MapIndex<UuidIntType>, and MapIndex<IntPayloadType> so all three
use the same comparison against threshold.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 41b1cb83-1092-414c-90c2-6895b38972f8
📒 Files selected for processing (18)
lib/segment/src/index/field_index/bool_index/mod.rslib/segment/src/index/field_index/bool_index/mutable_bool_index.rslib/segment/src/index/field_index/bool_index/simple_bool_index.rslib/segment/src/index/field_index/field_index_base.rslib/segment/src/index/field_index/full_text_index/inverted_index/mod.rslib/segment/src/index/field_index/full_text_index/tests/test_congruence.rslib/segment/src/index/field_index/full_text_index/text_index.rslib/segment/src/index/field_index/geo_index/mod.rslib/segment/src/index/field_index/map_index/mod.rslib/segment/src/index/field_index/null_index/mutable_null_index.rslib/segment/src/index/field_index/numeric_index/mod.rslib/segment/src/index/field_index/numeric_index/tests.rslib/segment/src/index/hnsw_index/hnsw.rslib/segment/src/index/payload_index_base.rslib/segment/src/index/plain_payload_index.rslib/segment/src/index/struct_payload_index.rslib/segment/tests/integration/exact_search_test.rslib/segment/tests/integration/filtrable_hnsw_test.rs
🚧 Files skipped from review as they are similar to previous changes (11)
- lib/segment/src/index/field_index/full_text_index/inverted_index/mod.rs
- lib/segment/src/index/struct_payload_index.rs
- lib/segment/tests/integration/filtrable_hnsw_test.rs
- lib/segment/src/index/field_index/numeric_index/mod.rs
- lib/segment/src/index/field_index/field_index_base.rs
- lib/segment/tests/integration/exact_search_test.rs
- lib/segment/src/index/hnsw_index/hnsw.rs
- lib/segment/src/index/field_index/bool_index/simple_bool_index.rs
- lib/segment/src/index/field_index/full_text_index/tests/test_congruence.rs
- lib/segment/src/index/field_index/bool_index/mutable_bool_index.rs
- lib/segment/src/index/field_index/null_index/mutable_null_index.rs
232e5d0 to
16e919f
Compare
16e919f to
9040672
Compare
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
lib/segment/src/index/field_index/map_index/mod.rs (1)
1053-1077:⚠️ Potential issue | 🟡 MinorKeep the threshold boundary consistent across map payload blocks.
These two specializations include blocks with
count == threshold, whileMapIndex<str>in the same module and the otherpayload_blocksimplementations in this PR still use a strict>check. That makes HNSW block generation depend on field type at the exact boundary.🛠️ Minimal fix if the strict boundary is still intended
- .filter(move |(_value, count)| *count >= threshold) + .filter(move |(_value, count)| *count > threshold) - .filter(move |(_value, count)| *count >= threshold) + .filter(move |(_value, count)| *count > threshold)Also applies to: 1205-1226
🤖 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 1053 - 1077, The payload_blocks implementation for MapIndex<Uuid> uses a >= threshold check causing inclusive boundary behavior that differs from MapIndex<str> and other payload_blocks variants; change the filter in payload_blocks (the closure using get_count_for_value and filtering on count) from "*count >= threshold" to a strict "*count > threshold" so HNSW block selection is consistent across types; apply the same change to the other payload_blocks occurrence noted in the file (the other payload_blocks specialization) to keep behavior uniform.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@lib/segment/src/index/field_index/map_index/mod.rs`:
- Around line 1053-1077: The payload_blocks implementation for MapIndex<Uuid>
uses a >= threshold check causing inclusive boundary behavior that differs from
MapIndex<str> and other payload_blocks variants; change the filter in
payload_blocks (the closure using get_count_for_value and filtering on count)
from "*count >= threshold" to a strict "*count > threshold" so HNSW block
selection is consistent across types; apply the same change to the other
payload_blocks occurrence noted in the file (the other payload_blocks
specialization) to keep behavior uniform.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: eb83fb02-f96c-420e-b3f3-2d90fc465d8d
📒 Files selected for processing (18)
lib/segment/src/index/field_index/bool_index/mod.rslib/segment/src/index/field_index/bool_index/mutable_bool_index.rslib/segment/src/index/field_index/bool_index/simple_bool_index.rslib/segment/src/index/field_index/field_index_base.rslib/segment/src/index/field_index/full_text_index/inverted_index/mod.rslib/segment/src/index/field_index/full_text_index/tests/test_congruence.rslib/segment/src/index/field_index/full_text_index/text_index.rslib/segment/src/index/field_index/geo_index/mod.rslib/segment/src/index/field_index/map_index/mod.rslib/segment/src/index/field_index/null_index/mutable_null_index.rslib/segment/src/index/field_index/numeric_index/mod.rslib/segment/src/index/field_index/numeric_index/tests.rslib/segment/src/index/hnsw_index/hnsw.rslib/segment/src/index/payload_index_base.rslib/segment/src/index/plain_payload_index.rslib/segment/src/index/struct_payload_index.rslib/segment/tests/integration/exact_search_test.rslib/segment/tests/integration/filtrable_hnsw_test.rs
🚧 Files skipped from review as they are similar to previous changes (5)
- 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/index/field_index/numeric_index/tests.rs
- lib/segment/tests/integration/exact_search_test.rs
- lib/segment/tests/integration/filtrable_hnsw_test.rs
Second commit in the stack #8433.