Skip to content

feat: add open for read only numeric index - #9213

Merged
dancixx merged 5 commits into
devfrom
feat/readonly-numeric-index-open
Jun 2, 2026
Merged

dancixx merged 5 commits into
devfrom
feat/readonly-numeric-index-open

Conversation

@dancixx

@dancixx dancixx commented May 27, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

⚠️ PRs must target the dev branch. If your PR targets master, please change the base branch to dev before requesting a review.

  • My PR targets the dev branch (not master) and my branch was created from dev.
  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same update/change?

New Feature Submissions:

  1. Does your submission pass tests?
  2. Have you formatted your code locally using cargo +nightly fmt --all command prior to submission?
  3. Have you checked your code using cargo clippy --workspace --all-features command?

Changes to Core Features:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your core changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@coderabbitai

coderabbitai Bot commented May 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds 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

  • qdrant/qdrant#9038: Adds core read-only numeric index types and initial Gridstore-backed open path, closely related to this PR’s lifecycle and open logic.
  • qdrant/qdrant#9210: Changes in GridstoreReader/pages/read-only opening behavior that affect the read-only open path used here.
  • qdrant/qdrant#9223: Adds a similar read-only open/rebuild flow for appendable map indexes; conceptually parallel changes.

Suggested reviewers

  • generall
  • coszio

Poem

I nibble bytes beneath the moon, 🐇
Rebuild the points from disk in tune,
Gridstore seeds sprout into RAM,
Mmap hums softly, steady, calm,
Tests hop by — the index blooms.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description consists entirely of the repository's standard submission checklist template with no meaningful content about the actual changes, making it impossible to understand what the PR accomplishes. Replace the checklist template with a substantive description explaining what features are added, why they're needed, and any relevant implementation details or design decisions.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding an open function for read-only numeric indexes, which matches the primary purpose of all the changes across multiple files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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

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.

@dancixx
dancixx marked this pull request as ready for review May 28, 2026 08:46
@dancixx
dancixx marked this pull request as draft May 28, 2026 20:38
@dancixx
dancixx marked this pull request as ready for review May 29, 2026 11:49
@dancixx
dancixx requested a review from generall May 29, 2026 11:50
@generall generall added this to the Live-reload milestone May 30, 2026
@dancixx
dancixx force-pushed the feat/readonly-geo-index-open branch from edc5e85 to c8a41b1 Compare June 2, 2026 08:31
Base automatically changed from feat/readonly-geo-index-open to dev June 2, 2026 08:56
@dancixx
dancixx force-pushed the feat/readonly-numeric-index-open branch 2 times, most recently from c8eb8b5 to 9aa4851 Compare June 2, 2026 12:33

@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/field_index/numeric_index/mutable_numeric_index/read_only/lifecycle.rs (1)

41-54: ⚡ Quick win

Fix iterator-bound concern: max_point_offset() is the correct upper bound for iter.

GridstoreReader::iter(max_id, ...) forwards max_id to tracker.iter_pointers(from, max), which iterates from..min(next_pointer_offset, max.saturating_add(1)) (so max is inclusive). Since max_point_offset() returns pointer_count == next_pointer_offset, storage.iter(storage.max_point_offset(), ...) covers all valid offsets 0..pointer_count-1, matching the writable MutableNumericIndex::open_gridstore which 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

📥 Commits

Reviewing files that changed from the base of the PR and between 9aa4851 and 88683a8.

📒 Files selected for processing (4)
  • lib/segment/src/index/field_index/numeric_index/mutable_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/read_only/lifecycle.rs
  • lib/segment/src/index/field_index/numeric_index/storage/read_only/lifecycle.rs

@dancixx
dancixx force-pushed the feat/readonly-numeric-index-open branch from 88683a8 to f0308c1 Compare June 2, 2026 14:38

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

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 value

Doc intra-link [Ok(None)] likely won't resolve.

[Ok(None)] (Lines 28) is not a valid intra-doc link target and may trigger a rustdoc::broken_intra_doc_links warning. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 88683a8 and bbb0489.

📒 Files selected for processing (6)
  • lib/segment/src/index/field_index/numeric_index/mutable_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/read_only/lifecycle.rs
  • lib/segment/src/index/field_index/numeric_index/read_only/mod.rs
  • lib/segment/src/index/field_index/numeric_index/storage/read_only/lifecycle.rs
  • lib/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

Comment on lines +41 to +49
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(),
)

@coderabbitai coderabbitai Bot Jun 2, 2026 •

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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 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.rs

Repository: 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 -C6

Repository: 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.rs

Repository: 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 -S

Repository: qdrant/qdrant

Length of output: 5689


🏁 Script executed:

#!/bin/bash
set -euo pipefail

sed -n '1,200p' .github/review-rules.md

Repository: 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 -S

Repository: 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 . || true

Repository: 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 || true

Repository: qdrant/qdrant

Length of output: 39


Clarify iter(storage.max_point_offset(), ...) bounds: no off-by-one data-loss risk

  • storage.max_point_offset() returns tracker.pointer_count() (= next_pointer_offset). tracker.iter_pointers(from, max) computes to = next_pointer_offset.min(max.saturating_add(1)) and iterates (from..to), so with max == next_pointer_offset it covers next_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)`.

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.

this is intrinsic to gridstore, we can take a look later

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.

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

@coszio
coszio self-requested a review June 2, 2026 16:30
Comment on lines +41 to +49
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(),
)

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.

this is intrinsic to gridstore, we can take a look later

@dancixx
dancixx merged commit c7e5703 into dev Jun 2, 2026
15 checks passed
@dancixx
dancixx deleted the feat/readonly-numeric-index-open branch June 2, 2026 17:18
@coderabbitai coderabbitai Bot mentioned this pull request Jun 2, 2026
9 tasks
timvisee pushed a commit that referenced this pull request Jun 3, 2026
* 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
@coderabbitai coderabbitai Bot mentioned this pull request Jul 1, 2026
10 of 11 tasks
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.

3 participants