Skip to content

[UIO] Universal load numeric index - #9234

Merged
generall merged 2 commits into
devfrom
universal-load-numeric-index
May 29, 2026
Merged

generall merged 2 commits into
devfrom
universal-load-numeric-index

Conversation

@coszio

@coszio coszio commented May 29, 2026

Copy link
Copy Markdown
Contributor

This PR propagates the S: UniversalRead to numeric index by:

  • Load the remaining parts of on-disk numeric index using UniversalRead, using read_via
  • Renaming the module to universal_numeric_index

@coszio
coszio requested review from ffuugoo, generall and xzfc May 29, 2026 17:03
@coderabbitai

coderabbitai Bot commented May 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR refactors the numeric index infrastructure to decouple from concrete memory-mapped filesystem backends. The public mmap_numeric_index module is replaced with a generic universal_numeric_index module. Histogram gains a backend-agnostic load_via method accepting a UniversalReadFs trait. The core UniversalNumericIndex::build and UniversalNumericIndex::open methods are generalized from concrete MmapFile specialization to a type parameter S: UniversalRead, accepting an fs: &S::Fs parameter. Downstream storage and builder layers wire the new generic APIs through to concrete MmapFs backends. Benchmarks and tests are updated to use the new method signatures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • qdrant/qdrant#8961: Related refactor of StoredBitSlice and UniversalRead I/O abstractions that align with the UIO backend changes in this PR.
  • qdrant/qdrant#9038: Overlapping numeric-index lifecycle and builder refactoring using the same generalized UniversalNumericIndex::build/open and histogram load_via patterns.
  • qdrant/qdrant#8594: Related changes to numeric-index deletion-mask plumbing through build and open paths that precedes this generic parameterization.

Suggested labels

release:1.18.0

Suggested reviewers

  • generall
  • ffuugoo
  • xzfc

Poem

🐰 From concrete paths to abstract streams,
The index now flows through generic dreams,
MmapFs no longer holds the only key—
Any backend now can set us free!
Storage abstraction hops ahead,
As tests embrace the new paths read. 🎉

🚥 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 '[UIO] Universal load numeric index' directly relates to the main objective of propagating UniversalRead to numeric index and renaming the module to universal_numeric_index.
Description check ✅ Passed The description clearly explains the PR's purpose: propagating S: UniversalRead to numeric index and loading on-disk components using UniversalRead, which aligns with the file changes throughout the changeset.
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.

@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: 2

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/numeric_index/universal_numeric_index/lifecycle.rs (1)

128-134: ⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Avoid Path::is_file() in the generic open path.

This existence check bypasses fs entirely, so open() will return Ok(None) for indexes that are visible through S::Fs but not through the host filesystem. Please make the “missing index” check backend-aware as well.

🤖 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/universal_numeric_index/lifecycle.rs`
around lines 128 - 134, Remove the Path::is_file() shortcut and make the
“missing index” check backend-aware by attempting to read the JSON config via
read_json_via(fs, &config_path) and treating a not-found error as Ok(None); only
on success of read_json_via proceed to call Histogram::<T>::load_via(fs, path)
(or if load_via must run first, run load_via and read_json_via and treat any
backend-not-found error from either call as Ok(None)). Concretely: replace the
is_file() check with a call to read_json_via inside a match/Result handler that
maps the filesystem-specific NotFound/DoesNotExist error into Ok(None) and
propagates other errors, then continue to call Histogram::<T>::load_via and use
the returned config; reference functions/config_path, read_json_via,
Histogram::<T>::load_via and the open() path so the change is applied in the
generic open implementation.
🤖 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.

Inline comments:
In
`@lib/segment/src/index/field_index/numeric_index/universal_numeric_index/lifecycle.rs`:
- Around line 36-37: The build implementation for UniversalNumericIndex::<_,
S>::build currently hardcodes local-mmap persistence (using MmapFs/MmapBitSlice
and host-fs helpers) despite accepting any S: UniversalRead; either make
persistence backend-agnostic by routing all file writes and bit-slice writes
through the generic filesystem type S::Fs (replace uses of MmapFs/MmapBitSlice
and host-fs helpers with S::Fs-backed APIs and factory methods, and ensure any
bit-slice serialization uses a generic trait implemented by the chosen Fs), or
revert the public signature to require the mmap-specific backend (remove the
generic S: UniversalRead or bound S to the mmap Fs) until write support for
arbitrary S is implemented; update UniversalNumericIndex::build and the related
helper calls (the sections around lines referenced: 36-37, 50-57, 59-67, 81-109)
to consistently follow one of these two approaches.
- Around line 148-158: The call to StoredBitSlice::open for deleted_payload_mmap
sets OpenOptions { writeable: true }, but StoredBitSlice::open is implemented
for S: UniversalRead so using a writeable flag may require mutable FS capability
and break read-only backends; inspect StoredBitSlice::open and the UniversalRead
trait to confirm whether options.writeable is actually used for write operations
or requires Fs::write methods, and if it does, change the OpenOptions passed at
the call site to writeable: false (or provide a separate read-only open path) so
the call respects the UniversalRead contract; update references to OpenOptions
in lifecycle.rs where deleted_payload_mmap is opened and ensure tests cover
read-only backends.

---

Outside diff comments:
In
`@lib/segment/src/index/field_index/numeric_index/universal_numeric_index/lifecycle.rs`:
- Around line 128-134: Remove the Path::is_file() shortcut and make the “missing
index” check backend-aware by attempting to read the JSON config via
read_json_via(fs, &config_path) and treating a not-found error as Ok(None); only
on success of read_json_via proceed to call Histogram::<T>::load_via(fs, path)
(or if load_via must run first, run load_via and read_json_via and treat any
backend-not-found error from either call as Ok(None)). Concretely: replace the
is_file() check with a call to read_json_via inside a match/Result handler that
maps the filesystem-specific NotFound/DoesNotExist error into Ok(None) and
propagates other errors, then continue to call Histogram::<T>::load_via and use
the returned config; reference functions/config_path, read_json_via,
Histogram::<T>::load_via and the open() path so the change is applied in the
generic open implementation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: dfa2187a-134f-44d5-a746-eef8349037fd

📥 Commits

Reviewing files that changed from the base of the PR and between 5bc9847 and d0282d5.

📒 Files selected for processing (14)
  • lib/segment/benches/numeric_index_check_values.rs
  • lib/segment/src/index/field_index/histogram.rs
  • lib/segment/src/index/field_index/numeric_index/builders.rs
  • lib/segment/src/index/field_index/numeric_index/immutable_numeric_index/lifecycle.rs
  • lib/segment/src/index/field_index/numeric_index/immutable_numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/mutable_numeric_index/lifecycle.rs
  • lib/segment/src/index/field_index/numeric_index/storage/lifecycle.rs
  • lib/segment/src/index/field_index/numeric_index/storage/mod.rs
  • lib/segment/src/index/field_index/numeric_index/storage/read_only/mod.rs
  • lib/segment/src/index/field_index/numeric_index/universal_numeric_index/lifecycle.rs
  • lib/segment/src/index/field_index/numeric_index/universal_numeric_index/mod.rs
  • lib/segment/src/index/field_index/numeric_index/universal_numeric_index/read_ops.rs
  • lib/segment/src/index/field_index/tests/histogram_tests.rs

Comment on lines +36 to 37
/// TODO: save using `S::Fs` too
pub fn build(

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 | 🟠 Major | 🏗️ Heavy lift

build still hardcodes mmap/local-disk writes despite exposing arbitrary S.

UniversalNumericIndex::<_, S>::build now accepts any S: UniversalRead, but this implementation still persists state through host-fs helpers and MmapFs/MmapBitSlice. That means the new signature advertises backend-agnostic construction while the body still only builds a local mmap layout.

Either push these writes behind S::Fs too, or keep build specialized to the mmap backend until write support exists.

Also applies to: 50-57, 59-67, 81-109

🤖 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/universal_numeric_index/lifecycle.rs`
around lines 36 - 37, The build implementation for UniversalNumericIndex::<_,
S>::build currently hardcodes local-mmap persistence (using MmapFs/MmapBitSlice
and host-fs helpers) despite accepting any S: UniversalRead; either make
persistence backend-agnostic by routing all file writes and bit-slice writes
through the generic filesystem type S::Fs (replace uses of MmapFs/MmapBitSlice
and host-fs helpers with S::Fs-backed APIs and factory methods, and ensure any
bit-slice serialization uses a generic trait implemented by the chosen Fs), or
revert the public signature to require the mmap-specific backend (remove the
generic S: UniversalRead or bound S to the mmap Fs) until write support for
arbitrary S is implemented; update UniversalNumericIndex::build and the related
helper calls (the sections around lines referenced: 36-37, 50-57, 59-67, 81-109)
to consistently follow one of these two approaches.

Comment on lines +148 to 158
let deleted_payload_mmap = StoredBitSlice::<S>::open(
fs,
&deleted_path,
OpenOptions {
writeable: true,
need_sequential: false,
populate: Populate::Auto,
advice: AdviceSetting::Global,
},
(),
Default::default(),
)?;

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 | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Inspect StoredBitSlice::open definition:"
fd -a 'stored_bitslice\.rs$' . | xargs -r rg -n -C3 'fn open\(|struct StoredBitSlice|impl .*StoredBitSlice'

echo
echo "Inspect call sites using StoredBitSlice::<...>::open:"
rg -n -C2 'StoredBitSlice::<.*>::open\('

Repository: qdrant/qdrant

Length of output: 2441


Fix OpenOptions usage vs UniversalRead contract

StoredBitSlice::open is implemented under impl<S: UniversalRead>, but the call site opens deleted_payload_mmap with OpenOptions { writeable: true, ... }. Inspect StoredBitSlice::open to see whether options.writeable actually requires mutable filesystem/backends (trait bounds or Fs operations); otherwise this may be a harmless flag. If it does require write-capable backends, this would indeed break read-only backends and should be set to writeable: false (or split the API by capability).

🤖 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/universal_numeric_index/lifecycle.rs`
around lines 148 - 158, The call to StoredBitSlice::open for
deleted_payload_mmap sets OpenOptions { writeable: true }, but
StoredBitSlice::open is implemented for S: UniversalRead so using a writeable
flag may require mutable FS capability and break read-only backends; inspect
StoredBitSlice::open and the UniversalRead trait to confirm whether
options.writeable is actually used for write operations or requires Fs::write
methods, and if it does, change the OpenOptions passed at the call site to
writeable: false (or provide a separate read-only open path) so the call
respects the UniversalRead contract; update references to OpenOptions in
lifecycle.rs where deleted_payload_mmap is opened and ensure tests cover
read-only backends.

@generall
generall merged commit fe28339 into dev May 29, 2026
15 checks passed
@generall
generall deleted the universal-load-numeric-index branch May 29, 2026 20:12
@generall generall added this to the Live-reload milestone May 30, 2026
timvisee pushed a commit that referenced this pull request Jun 3, 2026
* rename module, use read_via

* propagate S to `UniversalNumericIndex<T, S>`
@xzfc xzfc mentioned this pull request Jun 3, 2026
34 of 36 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.

2 participants