Repository navigation
feat: add open for read only numeric index - #9213
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds read-only lifecycle entrypoints for numeric indexes: a Gridstore-backed appendable open that rebuilds in-memory state by iterating stored points, mmap/immutable open paths, storage-variant lifecycle wiring, mutability-querying methods, module wiring (new lifecycle submodules), expanded docs, and a round-trip test verifying persistence and recovery. Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
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 |
edc5e85 to
c8a41b1
Compare
c8eb8b5 to
9aa4851
Compare
There was a problem hiding this comment.
🧹 Nitpick comments (1)
lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs (1)
41-54: ⚡ Quick winFix iterator-bound concern:
max_point_offset()is the correct upper bound foriter.
GridstoreReader::iter(max_id, ...)forwardsmax_idtotracker.iter_pointers(from, max), which iteratesfrom..min(next_pointer_offset, max.saturating_add(1))(somaxis inclusive). Sincemax_point_offset()returnspointer_count == next_pointer_offset,storage.iter(storage.max_point_offset(), ...)covers all valid offsets0..pointer_count-1, matching the writableMutableNumericIndex::open_gridstorewhich iterates the whole gridstore.
- Using
ref_payload_index_io_write_counter()on the read path is semantically odd but low-impact.🤖 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/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs` around lines 41 - 54, Ensure the iterator uses storage.max_point_offset() as the inclusive upper bound when calling storage.iter so it covers offsets 0..pointer_count-1 (leave the storage.iter(storage.max_point_offset(), ...) call and in_memory_index.add_many_to_list as-is), and replace the semantically odd hw_counter.ref_payload_index_io_write_counter() with a read-specific counter (e.g., hw_counter.ref_payload_index_io_read_counter()) on this read path to reflect correct I/O metrics.
🤖 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/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs`:
- Around line 41-54: Ensure the iterator uses storage.max_point_offset() as the
inclusive upper bound when calling storage.iter so it covers offsets
0..pointer_count-1 (leave the storage.iter(storage.max_point_offset(), ...) call
and in_memory_index.add_many_to_list as-is), and replace the semantically odd
hw_counter.ref_payload_index_io_write_counter() with a read-specific counter
(e.g., hw_counter.ref_payload_index_io_read_counter()) on this read path to
reflect correct I/O metrics.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 346dec91-2d42-4da7-bd66-850c69b24b46
📒 Files selected for processing (4)
lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rslib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/mod.rslib/segment/src/index/field_index/numeric_index/read_only/lifecycle.rslib/segment/src/index/field_index/numeric_index/storage/read_only/lifecycle.rs
88683a8 to
f0308c1
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs (1)
28-30: 💤 Low valueDoc intra-link
[Ok(None)]likely won't resolve.
[Ok(None)](Lines 28) is not a valid intra-doc link target and may trigger arustdoc::broken_intra_doc_linkswarning. Use inline code instead.Proposed tweak
- /// Returns [`Ok(None)`] when the on-disk directory doesn't exist, matching + /// Returns `Ok(None)` when the on-disk directory doesn't exist, matching🤖 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/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs` around lines 28 - 30, The doc comment containing "Returns [`Ok(None)`] when the on-disk directory doesn't exist…" uses an invalid intra-doc link; replace the bracketed link with an inline code span (e.g. `Ok(None)`) in lifecycle.rs so rustdoc won't emit broken_intra_doc_links, and update any other similar bracketed return mentions in the same comment to use inline code instead.
🤖 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/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs`:
- Around line 28-30: The doc comment containing "Returns [`Ok(None)`] when the
on-disk directory doesn't exist…" uses an invalid intra-doc link; replace the
bracketed link with an inline code span (e.g. `Ok(None)`) in lifecycle.rs so
rustdoc won't emit broken_intra_doc_links, and update any other similar
bracketed return mentions in the same comment to use inline code instead.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro
Run ID: 66a0d2be-cba9-4f41-90d3-dbcff23c1615
📒 Files selected for processing (6)
lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rslib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/mod.rslib/segment/src/index/field_index/numeric_index/read_only/lifecycle.rslib/segment/src/index/field_index/numeric_index/read_only/mod.rslib/segment/src/index/field_index/numeric_index/storage/read_only/lifecycle.rslib/segment/src/index/field_index/numeric_index/storage/read_only/mod.rs
✅ Files skipped from review due to trivial changes (2)
- lib/segment/src/index/field_index/numeric_index/storage/read_only/mod.rs
- lib/segment/src/index/field_index/numeric_index/read_only/mod.rs
🚧 Files skipped from review as they are similar to previous changes (3)
- lib/segment/src/index/field_index/numeric_index/read_only/lifecycle.rs
- lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/mod.rs
- lib/segment/src/index/field_index/numeric_index/storage/read_only/lifecycle.rs
| storage | ||
| .iter::<_, OperationError>( | ||
| storage.max_point_offset(), | ||
| |idx, values: Vec<T>| { | ||
| in_memory_index.add_many_to_list(idx, values); | ||
| Ok(true) | ||
| }, | ||
| hw_counter.ref_payload_index_io_read_counter(), | ||
| ) |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Inspect gridstore Reader::iter signature and doc on the bound argument
fd -t f -e rs . | xargs rg -nP -C5 '\bfn\s+iter\b' | rg -nC8 'iter|max_point_offset|offset|until' || true
echo "----- max_point_offset definition -----"
ast-grep --pattern 'fn max_point_offset($$$) { $$$ }'
echo "----- writable open_gridstore reconstruction (compare bound usage) -----"
rg -nP -C12 '\bfn\s+open_gridstore\b'Repository: qdrant/qdrant
Length of output: 45048
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "----- gridstore/mod.rs: iter + max_point_offset implementation -----"
rg -n "pub fn iter\\b|pub fn max_point_offset\\b" lib/gridstore/src/gridstore/mod.rs
rg -n "pub fn iter\\b" -n lib/gridstore/src/gridstore/mod.rs && sed -n '360,460p' lib/gridstore/src/gridstore/mod.rs
sed -n '380,430p' lib/gridstore/src/gridstore/mod.rs
echo "----- gridstore/reader.rs: iter signature/usage (if any) -----"
sed -n '60,130p' lib/gridstore/src/gridstore/reader.rs
echo "----- gridstore/view.rs: iter loop semantics (inclusive/exclusive) -----"
rg -n "pub fn iter\\b" lib/gridstore/src/gridstore/view.rs
sed -n '130,220p' lib/gridstore/src/gridstore/view.rs
echo "----- find where max_iters/max_id bounds are applied -----"
rg -n "max_id|max_iters|until|<=|<\s*max_id" lib/gridstore/src/gridstore/view.rs
echo "----- payload_storage uses storage.max_point_offset() with storage.iter; show that iter signature -----"
sed -n '1,120p' lib/segment/src/payload_storage/payload_storage_base.rs
sed -n '30,90p' lib/segment/src/payload_storage/read_only/payload_storage_read.rs
echo "----- segment: numeric mutable read-only lifecycle open: show exact call site region -----"
sed -n '1,120p' lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs
sed -n '120,220p' lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rsRepository: qdrant/qdrant
Length of output: 18068
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "----- locate tracker.iter_pointers -----"
rg -n "iter_pointers\\b" lib/gridstore/src/gridstore -S
echo "----- locate pointer_count definition/semantics -----"
rg -n "fn pointer_count\\b|pointer_count\\(" lib/gridstore/src/gridstore -S
echo "----- inspect tracker iter_pointers + pointer_count code -----"
# Print a small surrounding window for any hits
rg -n "iter_pointers\\b" lib/gridstore/src/gridstore -S -n -C6
# If tracker is in another module, also search under lib/gridstore/src
rg -n "iter_pointers\\b" lib/gridstore/src -S -C6
rg -n "pointer_count\\b" lib/gridstore/src -S -C6Repository: qdrant/qdrant
Length of output: 12253
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '400,450p' lib/gridstore/src/tracker.rs
sed -n '240,290p' lib/gridstore/src/tracker.rsRepository: qdrant/qdrant
Length of output: 3173
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "----- occurrences of rustdoc link syntax [\`Ok(None)\`]"
rg -n "\\[`Ok\\(None\\)`\\]" lib/segment | head -n 50 || true
echo "----- check referenced open_gridstore path exists -----"
rg -n "MutableNumericIndex::open_gridstore\\b|fn\\s+open_gridstore\\b" lib/segment/src/index/field_index/numeric_index -SRepository: qdrant/qdrant
Length of output: 5689
🏁 Script executed:
#!/bin/bash
set -euo pipefail
sed -n '1,200p' .github/review-rules.mdRepository: qdrant/qdrant
Length of output: 2362
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "----- search for rustdoc pattern [\`Ok(None)\`]"
rg -n --fixed-string "[`Ok(None)`]" lib/segment || true
rg -n --fixed-string "[`Ok(Some(`" lib/segment || true
rg -n --fixed-string "Returns [`Ok(None)`]" lib/segment || true
rg -n --fixed-string "Ok(None)" lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs || true
echo "----- locate definition of MutableNumericIndex in numeric_index module tree -----"
rg -n "MutableNumericIndex" lib/segment/src/index/field_index/numeric_index -S
echo "----- show top of read_only lifecycle.rs for module context -----"
sed -n '1,120p' lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs
echo "----- confirm open_gridstore exists on referenced type -----"
rg -n "open_gridstore\\b" lib/segment/src/index/field_index/numeric_index -SRepository: qdrant/qdrant
Length of output: 7493
🏁 Script executed:
#!/bin/bash
set -euo pipefail
echo "----- exact occurrences of rustdoc link syntax [\`Ok(None)\`]"
rg -n '\[`Ok\(None\)`\]' lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs || true
rg -n '\[`Ok\(None\)`\]' lib/segment/src/index/field_index/numeric_index/mutable_numeric_index -S || true
echo "----- check whether broken intra-doc links are warned/denied -----"
rg -n "rustdoc::broken_intra_doc_links|broken_intra_doc_links" -S . || trueRepository: qdrant/qdrant
Length of output: 443
🏁 Script executed:
#!/bin/bash
set -euo pipefail
rg -n "rustdoc::broken_intra_doc_links|broken_intra_doc_links" -S . || true
rg -n "#!\\[(deny|warn)\\(rustdoc::broken_intra_doc_links\\)\\]" -S . || true
rg -n "broken_intra_doc_links" Cargo.toml .github -S || trueRepository: qdrant/qdrant
Length of output: 39
Clarify iter(storage.max_point_offset(), ...) bounds: no off-by-one data-loss risk
storage.max_point_offset()returnstracker.pointer_count()(=next_pointer_offset).tracker.iter_pointers(from, max)computesto = next_pointer_offset.min(max.saturating_add(1))and iterates(from..to), so withmax == next_pointer_offsetit coversnext_pointer_offset - 1(the last possible stored offset).- Rustdoc:
/// Returns [Ok(None)] ...uses intra-doc link syntax but doesn’t point to an item; safer to write it as plain code:`Ok(None)`.
There was a problem hiding this comment.
this is intrinsic to gridstore, we can take a look later
There was a problem hiding this comment.
@coszio, understood — the iter bound semantics are tied to gridstore internals and better addressed there. Would you like me to open a follow-up GitHub issue to track this (covering the bounds clarification and the minor rustdoc [Ok(None)] nit)?
🧠 Learnings used
Learnt from: IvanPleshkov
Repo: qdrant/qdrant PR: 8246
File: lib/segment/src/segment/segment_ops.rs:691-696
Timestamp: 2026-02-27T19:23:23.760Z
Learning: In code that computes offsets or casts counts to PointOffsetType (u32), avoid unsafe or unchecked casts from usize to PointOffsetType. Do not cast unless you can guarantee the value is < PointOffsetType::MAX, for example by assertions or by design constraints (as in versions_store.rs and segment internal IDs). When such a cast is necessary, validate the bound first and add an explicit assertion or guard, documenting the invariant to prevent overflow and maintain correctness across segments.
Learnt from: generall
Repo: qdrant/qdrant PR: 8322
File: lib/edge/src/lib.rs:213-237
Timestamp: 2026-03-08T01:28:03.360Z
Learning: Use SaveOnDisk<T> from common::save_on_disk for atomic persist-then-swap semantics when a config or in-memory struct must be kept in memory and persisted atomically on mutation. Prefer SaveOnDisk<T> over combining parking_lot::RwLock<T> with manual save() calls. Note: write_optional (returns Option<T>) is appropriate for fallible mutations where returning None skips both save and swap. In the qdrant/qdrant repo, the type is located at lib/common/common/src/save_on_disk.rs; migrate relevant in-memory config mutations to use SaveOnDisk<T> to ensure atomic persistence.
Learnt from: generall
Repo: qdrant/qdrant PR: 8368
File: lib/common/common/src/disk_cache/controller.rs:129-129
Timestamp: 2026-03-17T19:36:24.259Z
Learning: In this repository, all builds target 64-bit systems. Do not flag casts from u64 to usize (for example file length via f.metadata()?.len() as usize) as potentially unsafe. These casts are acceptable because 32-bit targets are not supported. Apply this guidance across all Rust sources in the codebase unless explicit overrides exist.
Learnt from: JojiiOfficial
Repo: qdrant/qdrant PR: 9172
File: lib/segment/src/segment_constructor/segment_constructor_base.rs:124-126
Timestamp: 2026-05-28T14:11:02.811Z
Learning: In qdrant/qdrant Rust code, it is acceptable to use `unimplemented!()` as an intentional placeholder in stub/draft code paths (e.g., for new datatypes not yet wired up). During review, do not suggest replacing `unimplemented!()` with `OperationError::service_error(...)` when the stub arm is (1) guarded by upstream validation such that it should be unreachable at runtime for supported inputs and (2) explicitly marked/annotated as “not yet implemented” (e.g., via comments, feature gates, or draft/DPR scaffolding). Only flag `unimplemented!()` if it can be reached for valid inputs or lacks clear “not-yet-implemented” intent/guards.
| storage | ||
| .iter::<_, OperationError>( | ||
| storage.max_point_offset(), | ||
| |idx, values: Vec<T>| { | ||
| in_memory_index.add_many_to_list(idx, values); | ||
| Ok(true) | ||
| }, | ||
| hw_counter.ref_payload_index_io_read_counter(), | ||
| ) |
There was a problem hiding this comment.
this is intrinsic to gridstore, we can take a look later
* feat: add open for read only numeric index * feat: add parent open_*, get_mutability_type for ReadOnlyNumericIndex * fix: naming and generic fs * feat: detect not-found via error in numeric index open * fix: hw counter write -> read
All Submissions:
devbranch (notmaster) and my branch was created fromdev.New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --workspace --all-featurescommand?Changes to Core Features: