Skip to content

split read only vector store - #8852

Merged
generall merged 3 commits into
devfrom
split-read-only-vector-store
Apr 30, 2026
Merged

generall merged 3 commits into
devfrom
split-read-only-vector-store

Conversation

@generall

@generall generall commented Apr 30, 2026 •

Copy link
Copy Markdown
Member

Motivation

We are on the quest to implement read-only version of the segment without duplicating any code.
To achive this, we want to use view pattern:

  • we create an ephemeral View data strucure, which would only hold references to actual segment components in a form of impl Trait
  • This view data strucutre should be the only place where search functions are implemented, so we don't duplicate any search logic code
  • View data structure should be possible to construct from both: regular Segment and ReadOnlySegment.

Steps

Separate traits of segment components into Read + everything else

To achieve this, the first step would be to split traits of segment components into Read and EverythingElse traits.
The same way as it is done for IdTrackerRead and IdTracker: IdTrackerRead traits.
This way, we can achieve read-only version of the segment without duplicating any code.

Step 1: Vector Storage (this PR)

  • Investigate VectorStorage trait, split it into Read and EverythingElse traits same way as id tracker
  • investigate ReadSegmentEntry for Segment and check that there are no functions used from VectorStorage which are not part of Read trait

AI summary:

  Trait split in lib/segment/src/vector_storage/vector_storage_base.rs:
  - New VectorStorageRead trait with read-only methods: distance, datatype, is_on_disk, total_vector_count, available_vector_count, get_vector, read_vectors, get_vector_opt,
  is_deleted_vector, deleted_vector_count, deleted_vector_bitslice
  - VectorStorage: VectorStorageRead keeps mutating + persistence methods: insert_vector, update_from, flusher, files, immutable_files, delete_vector
  - Sub-traits DenseVectorStorage, SparseVectorStorage, MultiVectorStorage now bound on VectorStorageRead (they only have read methods)

  Impl splits for each storage (Empty/Volatile/Appendable + Dense/Sparse/Multi variants and VectorStorageEnum): each impl VectorStorage for X was split into a read-only impl
  VectorStorageRead for X and a mutating impl VectorStorage for X.

  Import updates across ~30 files to bring VectorStorageRead into scope where read methods are called.

  ReadSegmentEntry for Segment audit (lib/segment/src/segment/entry.rs): the only VectorStorage calls are read-only — available_vector_count, deleted_vector_count, total_vector_count,
  is_deleted_vector, read_vectors, is_on_disk, get_vector_opt, files, immutable_files — all of which now live on VectorStorageRead (or in the case of files/immutable_files, only used by
  snapshot paths, which are not part of ReadSegmentEntry). So the read trait is sufficient for read operations on a View.

@generall
generall requested a review from dancixx April 30, 2026 13:30
@coderabbitai

coderabbitai Bot commented Apr 30, 2026 •

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 000b2f95-c76b-4ed6-b465-4e5df8c82f3f

📥 Commits

Reviewing files that changed from the base of the PR and between 1a71b1f and 4d4a61f.

📒 Files selected for processing (1)
  • lib/segment/src/index/hnsw_index/gpu/gpu_vector_storage/mod.rs

📝 Walkthrough

Walkthrough

The PR splits the vector storage API by introducing VectorStorageRead for all read-only operations (including deletion inspection) and making VectorStorage a mutating trait that extends VectorStorageRead. The core trait definitions and VectorStorageEnum dispatch are updated in vector_storage_base.rs, and concrete storage implementations (dense, sparse, multi) are split to implement VectorStorageRead for read methods and VectorStorage for mutation methods. Many modules and tests update imports to use VectorStorageRead where applicable.

Estimated code review effort

🎯 5 (Critical) | ⏱️ ~120 minutes

Possibly related PRs

Suggested labels

release:1.18.0

Suggested reviewers

  • dancixx
  • xzfc
  • ffuugoo
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 18.89% 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 'split read only vector store' clearly summarizes the main change: splitting the VectorStorage trait into read-only and mutable parts.
Description check ✅ Passed The description provides detailed motivation, implementation steps, and summarizes the trait split and audit performed, directly relating to 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
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch split-read-only-vector-store

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
Review rate limit: 7/8 reviews remaining, refill in 7 minutes and 30 seconds.

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.

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/vector_storage/multi_dense/volatile_multi_dense_vector_storage.rs (1)

241-248: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Report the actual element datatype here.

VolatileMultiDenseVectorStorage<T> is generic, but this method always returns Float32. That breaks the new_volatile_multi_dense_vector_storage_byte and new_volatile_multi_dense_vector_storage_half variants defined in the same file, and any read-only caller that branches on VectorStorageRead::datatype() will now see the wrong storage type.

Suggested fix
     fn datatype(&self) -> VectorStorageDatatype {
-        VectorStorageDatatype::Float32
+        T::datatype()
     }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@lib/segment/src/vector_storage/multi_dense/volatile_multi_dense_vector_storage.rs`
around lines 241 - 248, The datatype() impl on
VolatileMultiDenseVectorStorage<T> incorrectly always returns Float32; change it
to return the actual element datatype for T (used by
new_volatile_multi_dense_vector_storage_byte/half). Update
VectorStorageRead::datatype implementation in VolatileMultiDenseVectorStorage<T>
to return the datatype provided by the element type (e.g., use an associated
constant or method on the PrimitiveVectorElement trait such as T::DATATYPE /
T::vector_datatype() or similar) so callers see the correct
VectorStorageDatatype for the generic T.
🤖 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/vector_storage/multi_dense/volatile_multi_dense_vector_storage.rs`:
- Around line 241-248: The datatype() impl on VolatileMultiDenseVectorStorage<T>
incorrectly always returns Float32; change it to return the actual element
datatype for T (used by new_volatile_multi_dense_vector_storage_byte/half).
Update VectorStorageRead::datatype implementation in
VolatileMultiDenseVectorStorage<T> to return the datatype provided by the
element type (e.g., use an associated constant or method on the
PrimitiveVectorElement trait such as T::DATATYPE / T::vector_datatype() or
similar) so callers see the correct VectorStorageDatatype for the generic T.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2c19b67c-d214-4f7a-a5d7-9583547dc132

📥 Commits

Reviewing files that changed from the base of the PR and between 7486a57 and 1a71b1f.

📒 Files selected for processing (45)
  • lib/collection/src/collection_manager/optimizers/vacuum_optimizer.rs
  • lib/segment/benches/sparse_index_build.rs
  • lib/segment/benches/sparse_vector_storage.rs
  • lib/segment/src/fixtures/sparse_fixtures.rs
  • lib/segment/src/index/hnsw_index/graph_layers.rs
  • lib/segment/src/index/hnsw_index/graph_layers_builder.rs
  • lib/segment/src/index/hnsw_index/graph_layers_healer.rs
  • lib/segment/src/index/hnsw_index/hnsw.rs
  • lib/segment/src/index/hnsw_index/point_scorer.rs
  • lib/segment/src/index/plain_vector_index.rs
  • lib/segment/src/index/query_optimization/condition_converter.rs
  • lib/segment/src/index/sparse_index/sparse_vector_index.rs
  • lib/segment/src/index/struct_payload_index.rs
  • lib/segment/src/payload_storage/query_checker.rs
  • lib/segment/src/segment/entry.rs
  • lib/segment/src/segment/segment_ops.rs
  • lib/segment/src/segment/tests/test_vector_name_ops.rs
  • lib/segment/src/segment_constructor/batched_reader.rs
  • lib/segment/src/segment_constructor/segment_builder.rs
  • lib/segment/src/segment_constructor/segment_constructor_base.rs
  • lib/segment/src/vector_storage/dense/appendable_dense_vector_storage.rs
  • lib/segment/src/vector_storage/dense/dense_vector_storage.rs
  • lib/segment/src/vector_storage/dense/empty_dense_vector_storage.rs
  • lib/segment/src/vector_storage/dense/volatile_dense_vector_storage.rs
  • lib/segment/src/vector_storage/memory_reporter.rs
  • lib/segment/src/vector_storage/multi_dense/appendable_mmap_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/multi_dense/volatile_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/prefill_deleted.rs
  • lib/segment/src/vector_storage/quantized/quantized_vectors.rs
  • lib/segment/src/vector_storage/sparse/empty_sparse_vector_storage.rs
  • lib/segment/src/vector_storage/sparse/mmap_sparse_vector_storage.rs
  • lib/segment/src/vector_storage/sparse/volatile_sparse_vector_storage.rs
  • lib/segment/src/vector_storage/tests/async_raw_scorer.rs
  • lib/segment/src/vector_storage/tests/custom_query_scorer_equivalency.rs
  • lib/segment/src/vector_storage/tests/test_appendable_dense_vector_storage.rs
  • lib/segment/src/vector_storage/tests/test_appendable_multi_dense_vector_storage.rs
  • lib/segment/src/vector_storage/tests/test_appendable_sparse_vector_storage.rs
  • lib/segment/src/vector_storage/tests/utils.rs
  • lib/segment/src/vector_storage/vector_storage_base.rs
  • lib/segment/tests/integration/disbalanced_vectors_test.rs
  • lib/segment/tests/integration/multivector_filtrable_hnsw_test.rs
  • lib/segment/tests/integration/sparse_vector_index_search_tests.rs
  • lib/shard/src/optimizers/vacuum_optimizer.rs
  • lib/shard/src/query/mmr/lazy_matrix.rs
  • lib/shard/src/query/mmr/mod.rs

@generall
generall merged commit 144528d into dev Apr 30, 2026
11 of 12 checks passed
@generall
generall deleted the split-read-only-vector-store branch April 30, 2026 14:27
@coderabbitai coderabbitai Bot mentioned this pull request May 4, 2026
9 tasks
timvisee pushed a commit that referenced this pull request May 8, 2026
* [AI] split trait for vector store into read only

* fmt

* fix: trait import

---------

Co-authored-by: Daniel Boros <[email protected]>
@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.

2 participants