Skip to content

read only map index - #9025

Merged
generall merged 4 commits into
devfrom
read-only-map-index
May 13, 2026
Merged

generall merged 4 commits into
devfrom
read-only-map-index

Conversation

@generall

Copy link
Copy Markdown
Member

Implement

pub enum ReadOnlyMapIndex<N: MapIndexKey + ?Sized, S: UniversalRead>
where
    Vec<<N as MapIndexKey>::Owned>: Blob + Send + Sync,
{
    /// Loads into RAM from appendable storage format
    Appendable(ReadOnlyAppendableMapIndex<N, S>),
    /// Directly reads from storage in immutable format
    Immutable(UniversalMapIndex<N, S>),
}

Which mirrors

pub enum MapIndex<N: MapIndexKey + ?Sized>
where
    Vec<<N as MapIndexKey>::Owned>: Blob + Send + Sync,
{
    /// Loaded in RAM, use mutable storage format
    Mutable(MutableMapIndex<N>),
    /// Loaded in RAM, use immutable storage format
    Immutable(ImmutableMapIndex<N>),
    /// Served directly from storage (via mmap), use immutable format
    Mmap(Box<UniversalMapIndex<N>>),
}

They also share implementations of the read methods, so no code duplication

coderabbitai[bot]

This comment was marked as resolved.

@qdrant qdrant deleted a comment from coderabbitai Bot May 13, 2026
Wires `ReadOnlyFieldIndex` into the read-only field-index surface that
`ReadOnlyMapIndex` and `ReadOnlyNullIndex` already provide, sharing the
non-trivial bodies with the existing `MapIndex` impls.

- Extracted per-`N` `PayloadFieldIndexRead` bodies (filter,
  estimate_cardinality, for_each_payload_block, condition_checker) in
  `payload_index_impl/{str,int,uuid}.rs` into free functions over
  `T: MapIndexRead<N>`. Both `MapIndex<N>` and `ReadOnlyMapIndex<N, S>`
  now impl `PayloadFieldIndexRead` via thin delegation to those bodies.
- Lifted `value_retriever` bodies in `value_indexer_impl.rs` the same
  way; `ReadOnlyMapIndex<N, S>` gets the per-K closure for free.
- Added `telemetry_index_type` (required) + `get_telemetry_data`
  (default) to `MapIndexRead`, mirroring the `NullIndexRead` pattern;
  every map-index variant now reports telemetry without an inherent
  method on the enum.
- Promoted `MapIndexRead` + its module to `pub` so
  `field_index_base/read_only/` can name them.
- Implemented `FacetIndex for ReadOnlyMapIndex<N, S>` and extended
  `FacetIndexEnum` with `S: UniversalRead = MmapFile` plus the three
  read-only variants. `FieldIndex::as_facet_index` pins
  `S = MmapFile` via turbofish to keep inference happy.
- `ReadOnlyFieldIndex::as_numeric` returns `None` for now; no concrete
  read-only numeric type exists yet (the doc on `NumericFieldIndexRead`
  already notes this is intended for a future `ReadOnlySegment`).
@generall
generall requested a review from dancixx May 13, 2026 10:03
@coderabbitai

coderabbitai Bot commented May 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR generalizes the mmap-specific map index implementation to support arbitrary storage backends and introduces a read-only abstraction layer. The core changes rename MmapMapIndex to UniversalMapIndex with a generic S: UniversalRead parameter, create a new ReadOnlyMapIndex<N, S> enum that dispatches between appendable RAM-loaded and immutable direct-storage variants, extend the MapIndexRead trait with public visibility and shared default methods, refactor payload index implementations to eliminate code duplication via shared generic helpers, and add read-only support throughout the field index hierarchy. All map index variants now implement telemetry_index_type() for observability, and readonly variants provide value_retriever methods for per-point value access.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • qdrant/qdrant#9020: Introduces ReadOnlyAppendableMapIndex backend that is dispatched by the new ReadOnlyMapIndex enum in this PR.
  • qdrant/qdrant#8955: Refactors UniversalRead trait to move element type to method generics, which this PR depends on for the new S: UniversalRead generic parameter.
  • qdrant/qdrant#8999: Overlaps on builders.rs and facet_index_impl.rs changes in the same map index restructuring effort.

Suggested labels

release:1.18.0

Suggested reviewers

  • timvisee
  • coszio
🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 27.73% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using only 4 words that don't clearly describe the main change in the changeset. Provide a more descriptive title that clearly explains the primary change, such as 'Implement ReadOnlyMapIndex enum with shared read implementations' or 'Add read-only map index abstraction with dual storage backends'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly relates to the changeset and explains the main purpose: implementing a ReadOnlyMapIndex enum that mirrors MapIndex with two variants.
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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch read-only-map-index

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.

🧹 Nitpick comments (1)
lib/segment/src/index/field_index/map_index/universal_map_index/read_ops.rs (1)

223-225: 💤 Low value

Consider renaming telemetry type identifier to match the new type name.

The method returns "mmap_map" but the type is now UniversalMapIndex. If this string is kept for backwards compatibility with existing telemetry collection, consider adding a comment explaining that. Otherwise, "universal_map" would better reflect the new type name.

🤖 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/map_index/universal_map_index/read_ops.rs`
around lines 223 - 225, The telemetry_index_type method currently returns
"mmap_map" which no longer matches the type name UniversalMapIndex; update
telemetry_index_type (in UniversalMapIndex) to return "universal_map" to reflect
the new type name, or if you must preserve existing telemetry values for
backwards compatibility, keep "mmap_map" but add a brief comment above
telemetry_index_type explaining that the string is intentionally unchanged for
telemetry compatibility.
🤖 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/map_index/universal_map_index/read_ops.rs`:
- Around line 223-225: The telemetry_index_type method currently returns
"mmap_map" which no longer matches the type name UniversalMapIndex; update
telemetry_index_type (in UniversalMapIndex) to return "universal_map" to reflect
the new type name, or if you must preserve existing telemetry values for
backwards compatibility, keep "mmap_map" but add a brief comment above
telemetry_index_type explaining that the string is intentionally unchanged for
telemetry compatibility.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: abc946f3-ea79-4efc-8a02-76bfb8f83269

📥 Commits

Reviewing files that changed from the base of the PR and between 71c0309 and 8c20284.

📒 Files selected for processing (15)
  • lib/segment/src/index/field_index/facet_index.rs
  • lib/segment/src/index/field_index/field_index_base/field_index_read_impl.rs
  • lib/segment/src/index/field_index/field_index_base/mod.rs
  • lib/segment/src/index/field_index/field_index_base/read_only/mod.rs
  • lib/segment/src/index/field_index/field_index_base/read_only/read_ops.rs
  • lib/segment/src/index/field_index/map_index/facet_index_impl.rs
  • lib/segment/src/index/field_index/map_index/immutable_map_index/read_ops.rs
  • lib/segment/src/index/field_index/map_index/mod.rs
  • lib/segment/src/index/field_index/map_index/mutable_map_index/inner.rs
  • lib/segment/src/index/field_index/map_index/mutable_map_index/read_only/read_ops.rs
  • lib/segment/src/index/field_index/map_index/mutable_map_index/read_ops.rs
  • lib/segment/src/index/field_index/map_index/read_only/read_ops.rs
  • lib/segment/src/index/field_index/map_index/read_ops.rs
  • lib/segment/src/index/field_index/map_index/universal_map_index/read_ops.rs
  • lib/segment/src/index/field_index/map_index/value_indexer_impl.rs
✅ Files skipped from review due to trivial changes (1)
  • lib/segment/src/index/field_index/field_index_base/mod.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • lib/segment/src/index/field_index/map_index/read_only/read_ops.rs
  • lib/segment/src/index/field_index/map_index/mod.rs

@generall
generall merged commit 5551853 into dev May 13, 2026
12 checks passed
@generall
generall deleted the read-only-map-index branch May 13, 2026 10:09
generall added a commit that referenced this pull request May 22, 2026
* rename mmap -> universal

* [AI] Introduce `ReadOnlyMapIndex` and implement `MapIndexRead` for it

* add missing file

* [AI] Implement read-only PayloadFieldIndexRead / FieldIndexRead (#9026)

Wires `ReadOnlyFieldIndex` into the read-only field-index surface that
`ReadOnlyMapIndex` and `ReadOnlyNullIndex` already provide, sharing the
non-trivial bodies with the existing `MapIndex` impls.

- Extracted per-`N` `PayloadFieldIndexRead` bodies (filter,
  estimate_cardinality, for_each_payload_block, condition_checker) in
  `payload_index_impl/{str,int,uuid}.rs` into free functions over
  `T: MapIndexRead<N>`. Both `MapIndex<N>` and `ReadOnlyMapIndex<N, S>`
  now impl `PayloadFieldIndexRead` via thin delegation to those bodies.
- Lifted `value_retriever` bodies in `value_indexer_impl.rs` the same
  way; `ReadOnlyMapIndex<N, S>` gets the per-K closure for free.
- Added `telemetry_index_type` (required) + `get_telemetry_data`
  (default) to `MapIndexRead`, mirroring the `NullIndexRead` pattern;
  every map-index variant now reports telemetry without an inherent
  method on the enum.
- Promoted `MapIndexRead` + its module to `pub` so
  `field_index_base/read_only/` can name them.
- Implemented `FacetIndex for ReadOnlyMapIndex<N, S>` and extended
  `FacetIndexEnum` with `S: UniversalRead = MmapFile` plus the three
  read-only variants. `FieldIndex::as_facet_index` pins
  `S = MmapFile` via turbofish to keep inference happy.
- `ReadOnlyFieldIndex::as_numeric` returns `None` for now; no concrete
  read-only numeric type exists yet (the doc on `NumericFieldIndexRead`
  already notes this is intended for a future `ReadOnlySegment`).
@coderabbitai coderabbitai Bot mentioned this pull request May 24, 2026
9 tasks done
@generall generall added this to the Live-reload milestone May 30, 2026
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.

1 participant