← Back to Pull requests

feat: allow training results to create multiple writers #87

Open
unknown opened this pull request with 369 lines diff across 4 files
View on GitHub
unknown unknown commented on Sep 02, 2026 08:21 UTC
Author

Summary

Allow one completed VectorIndexTraining to create multiple independent writers. Callers building several segment or file indexes from the same data distribution can train once and reuse the trained centroids, quantizers, and rotations instead of repeating training for every writer.

The existing consuming APIs remain unchanged for one-shot callers. Reusable writer creation is explicit and opt-in.

Closes #86.

Changes

  • Add VectorIndexTraining::create_writer() for IVF-Flat, IVF-SQ, IVF-PQ, IVF-RQ, and DiskANN.

  • Initialize each reusable writer with the trained model and empty segment-local IDs, vectors, codes, and graph state.

  • Expose equivalent non-consuming entry points through C, C++, Java/JNI, and Python while retaining the existing consuming forms.

  • Document both lifecycle choices without changing the primary one-shot examples.

  • Cover independent writer payloads with write/open/search round trips and keep binding tests focused on their ownership and ABI boundaries.
  • Benchmark

    Release-mode synthetic benchmark on an Intel Xeon Platinum 8575C host with 32 logical CPUs and 60 GiB RAM. The workload used 128-dimensional vectors, 64 IVF lists, 8,192 training rows, eight segments, and 2,048 vectors per segment. retrain trains separately for every segment; reuse trains once and creates eight writers. The table reports the median of three alternating process runs.

    | Index | Prepare: retrain -> reuse | Speedup | Full build: retrain -> reuse | Speedup |
    | --- | ---: | ---: | ---: | ---: |
    | IVF-Flat | 112 -> 18 ms | 6.2x | 138 -> 33 ms | 4.2x |
    | IVF-SQ | 123 -> 20 ms | 6.2x | 140 -> 27 ms | 5.2x |
    | IVF-PQ | 1,355 -> 173 ms | 7.8x | 1,384 -> 194 ms | 7.1x |
    | IVF-RQ | 109 -> 16 ms | 6.8x | 132 -> 28 ms | 4.7x |
    | DiskANN | 1,240 -> 161 ms | 7.7x | 1,485 -> 407 ms | 3.6x |

    The preparation measurement isolates training and writer creation. The full-build measurement also adds and serializes all segment vectors. Serialized output sizes were unchanged for each index type. This benchmark measures the removal of repeated training work; it does not claim an index-algorithm speedup.

    Testing

  • cargo fmt --all -- --check

  • cargo test --workspace --locked (487 passed, 2 ignored)

  • cargo clippy --all-targets --workspace --locked -- -D warnings -A clippy::chunks-exact-to-as-chunks

  • C tests (10 passed)

  • C++ tests (8 passed)

  • Java Maven tests and JNI native validation

  • Python 3.12 tests (29 passed)
  • The Clippy allow is limited to the chunks_exact_to_as_chunks lint newly enabled by Rust 1.98; strict Clippy currently reports it at 28 unchanged locations on main. No call site introduced by this PR requires the allow.

    Compatibility

  • No default behavior change; reuse requires an explicit new API call.

  • Existing consuming APIs remain source compatible.

  • No on-disk format change.

  • No cross-process training-model serialization or index merging.
  • Diff: 369 lines (+276 / -93) across 4 files Reviewer: wangzhigang1999 Review duration: 101186m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.50) × (1 − Review Confidence (0.45)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 369 lines diff across 4 files
    0.50
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    44%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.354
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #87"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 44.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 49.8% (MEDIUM) · Higher = larger blast radius
    49.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 44.7% · Lower = rushed or shallow review
    44.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.5% · Safe to merge
    27.5%