Repository navigation
refactor(segment): migrate search, retrieve, fill_query_context (step 9) - #8880
Merged
Merged
Conversation
…drop indexed_vectors Adds \`fill_idf_statistics\` to the \`VectorIndexRead\` trait with a no-op default (only sparse-vector indexes track IDF). \`VectorIndexEnum\` overrides it with the per-variant dispatch that previously lived as an inherent method. The inherent \`indexed_vectors\` is removed: it returned the same value as the trait method \`indexed_vector_count\` for every variant (sparse's \`indexed_vector_count\` is itself \`inverted_index.vector_count()\`). The remaining caller in \`fill_query_context\` will use \`indexed_vector_count\` after the next commit moves it to the view. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…o SegmentReadView Step 9 of the SegmentReadView migration. New \`read_view/search.rs\` hosts: * \`retrieve\` — full body (deferred filtering, vector enrichment, payload attachment). * \`process_search_result\` — converts internal \`ScoredPointOffset\`s into user-facing \`ScoredPoint\`s; calls the new \`view.retrieve\`. * \`search_batch\` — \`ReadSegmentEntry\` orchestrator. * \`fill_query_context\` — uses the trait \`VectorIndexRead::fill_idf_statistics\` (added in the prior commit) and the existing \`indexed_vector_count\`. The \`Segment\`-side trait method bodies for \`search_batch\`, \`retrieve\`, and \`fill_query_context\` collapse to single \`with_view\` delegators. \`rescore_with_formula\` (whose body still uses Segment-side \`do_rescore_with_formula\`, migrated in step 11) routes its \`process_search_result\` call through \`with_view\`. \`segment/search.rs\` is trimmed to just the \`#[cfg(feature = "testing")] pub fn search\` helper, which calls \`search_batch\` (now a \`with_view\` delegator) — no migration needed. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…impl A new index implementation should never silently skip IDF wiring. Make \`VectorIndexRead::fill_idf_statistics\` a required method (no default) and provide explicit no-op impls for the dense indexes: * \`PlainVectorIndex\` — no-op. * \`HNSWIndex\` — no-op. \`SparseVectorIndex\` keeps the real implementation: moved from a sibling \`pub fn\` (inherent) into the \`VectorIndexRead\` trait impl block, so there is now exactly one definition. \`VectorIndexEnum\` already overrides per-variant from the previous commit; nothing changes there. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
2 of 3 tasks
dancixx
approved these changes
May 4, 2026
dancixx
approved these changes
May 4, 2026
A read-only payload index implementation will have its own concrete formula scorer type, so PayloadIndexRead can't return the appendable \`FormulaScorer<'a>\` directly. * New \`FormulaScorerRead\` trait next to \`FormulaScorer\` exposing only what the rescore code path consumes (\`score(point_id)\`). Implemented for \`FormulaScorer<'_>\` by moving its inherent \`score\` into the trait impl. * \`PayloadIndexRead::formula_scorer\` returns \`OperationResult<impl FormulaScorerRead + 'q>\` (RPITIT). * The inherent \`StructPayloadIndex::formula_scorer\` (which lived in \`formula_scorer.rs\`) is moved into the trait impl block in \`struct_payload_index.rs\`, with the body delegating to a new \`FormulaScorer::new\` constructor (fields stay private). * \`PlainPayloadIndex\` always returns \`Err::<FormulaScorer<'q>, _>(...)\` — formula scoring is not supported there. The turbofish supplies the placeholder type tag. * Re-export \`FormulaScorer\` and \`FormulaScorerRead\` from \`rescore_formula::mod\`. \`retrievers_map\` bumped from \`pub(super)\` to \`pub(crate)\` so the trait impl can call it. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Step 10 of the SegmentReadView migration. Move \`segment/formula_rescore.rs\` → \`read_view/formula_rescore.rs\`: * \`do_rescore_with_formula\` (private helper). * \`rescore_with_formula\` (\`ReadSegmentEntry\` orchestrator). Both now use the trait-method \`PayloadIndexRead::formula_scorer\` (added in the prior commit) and \`IdTrackerRead::internal_id\` instead of inherent calls. \`Segment::rescore_with_formula\` collapses to a single \`with_view(|v| v.rescore_with_formula(...))\` delegator. The legacy \`segment/formula_rescore.rs\` is deleted; \`mod formula_rescore;\` removed from \`segment/mod.rs\`. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
\`FormulaScorer<'a>\` is already self-contained — it holds the parsed formula, prefetch scores, retrievers and condition checkers, all owned or borrowed independently of any payload index. Wrapping it in a trait adds nothing (a future ReadOnlySegment can construct one too). * Remove the \`FormulaScorerRead\` trait. \`score(point_id)\` goes back to being an inherent method on \`FormulaScorer\`. * \`PayloadIndexRead::formula_scorer\` returns \`OperationResult<FormulaScorer<'q>>\` directly. * \`StructPayloadIndex\` and \`PlainPayloadIndex\` updated to match. * \`PlainPayloadIndex\` no longer needs the turbofish placeholder — \`Err(...)\` is enough. * View's \`formula_rescore.rs\` drops the \`FormulaScorerRead\` import. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
Leftovers from moving \`StructPayloadIndex::formula_scorer\` out of this file. Caught by clippy. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
…w (step 11) (#8882) * refactor(index): extend VectorIndexRead and PayloadIndexRead for telemetry/info Two trait extensions (no defaults — every implementor must opt in): * \`VectorIndexRead::is_index\` — distinguishes a real index from a plain full-scan one. Used by reporting code. Moved out of inherent \`VectorIndexEnum::is_index\` into the trait. Explicit impls on Plain (false), HNSW (true), Sparse* (true). * \`PayloadIndexRead::get_telemetry_data\` — per-field-index telemetry. Moved out of inherent \`StructPayloadIndex::get_telemetry_data\` into the trait impl. \`PlainPayloadIndex\` returns an empty Vec. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> * refactor(segment): migrate info/size_info/telemetry to SegmentReadView Step 11 of the SegmentReadView migration — the final logical step. New \`read_view/info.rs\` exposes builder methods: * \`build_size_info(uuid, segment_type, is_appendable)\` * \`build_info(uuid, segment_type, is_appendable)\` — same plus \`index_schema\` * \`build_telemetry(uuid, segment_type, is_appendable, config, detail)\` The trivial segment-level fields (\`uuid\`, \`segment_type\`, \`is_appendable\`, \`config\`) are passed in by the caller — they stay direct on each segment-type rather than going through the view. Everything else (vector data breakdown, payloads size, deferred counts, vector-index telemetry, payload-field telemetry, …) is computed once inside the view through the read traits. \`Segment::size_info\`, \`info\`, and \`get_telemetry_data\` collapse to one-line \`with_view\` delegators that pass in the trivial fields. Cleanup: \`Segment::deferred_deleted_count\` is now unused (the view has its own equivalent helper); deleted. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]> --------- Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Step 9 of the
SegmentReadViewmigration. Stacked on top of #8879.Two commits.
1.
VectorIndexReadtrait extensionfill_idf_statisticswith a no-op default (only sparse-vector indexes track IDF).VectorIndexEnumoverrides with the per-variant dispatch that previously lived as an inherent method.indexed_vectors— for every variant it returns the same value as the trait methodindexed_vector_count(sparse'sindexed_vector_countis itselfinverted_index.vector_count()).2. Step 9 — migrate search/retrieve/fill_query_context to view
New
read_view/search.rshosts:retrieve— full body (deferred filtering, vector enrichment, payload attachment).process_search_result— converts internalScoredPointOffsets into user-facingScoredPoints; callsview.retrieve.search_batch—ReadSegmentEntryorchestrator.fill_query_context— uses the new traitfill_idf_statisticsand the existingindexed_vector_count.Segment::search_batch/retrieve/fill_query_contextcollapse to singlewith_viewdelegators.rescore_with_formula(whose body still uses Segment-sidedo_rescore_with_formula, migrated in step 11) routes itsprocess_search_resultcall throughwith_view.segment/search.rsis trimmed to just the#[cfg(feature = "testing")] pub fn searchhelper, which callssearch_batch(now a delegator) — no further migration needed.Test plan
cargo check --workspace --all-targetscleancargo test -p segment --lib— 644 passed, 0 failed🤖 Generated with Claude Code