feat(cli): train pq-codebook --from-index samples committed vectors (#920 sub-item 1) - #938
Merged
Merged
Conversation
…refs #920) Add a --from-index flag to `laurus train pq-codebook` that samples the vectors already committed to the index instead of requiring a separate JSONL export. Sampling is deterministic (ascending doc_id, first N under --sample-size), backed by two new public APIs: - VectorStore::sample_field_vectors: reader-based, doc_id-sorted, limit-truncated (the fan-out's newest-segment-first order alone would bias "first N" toward the latest commits) - Engine::sample_committed_vectors: thin delegation returning Vec<Vector> Exactly one of --input / --from-index must be given; the empty-index case gets its own error naming both remedies. Sub-items 2 (FastScan) and 3 (create-time convenience flag) of #920 remain open.
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
create index --train-pq-codebook) remain open.--from-indexflag tolaurus train pq-codebook: sample the vectors already committed to the index instead of requiring a separate JSONL export. Modeled as a boolean (not a path) because the CLI has exactly one open index per invocation via the globalindex_dir.Changes
VectorStore::sample_field_vectors(field, limit) -> Result<Vec<(u64, Vector)>>(new): reader →get_vectors_by_field→ sort by ascending doc_id → truncate. The fan-out's underlying order is newest-segment-first, so sorting is what makes the "first N, deterministic" semantics (shared with the JSONL path) meaningful rather than biased toward the latest commits. Unknown field yieldsOk(vec![]), matchingget_vectors_by_field's convention.Engine::sample_committed_vectors(field, sample_size) -> Result<Vec<Vector>>(new): thin delegation.--inputbecame optional, new--from-indexflag; exactly-one-source validation up front; only the vector-collection step branches — the train call and--update-schemahandling stay shared. The empty-index case errors with a message naming both remedies.laurus-cli/commands.mdusage/argument table/example (including the lossy-reconstruction caveat for already-PQ-encoded fields);vector_indexing.mdshared-codebook section.Tests
vector/store.rs): doc_id-ascending ordering,limittruncation /Nonereturns all, unknown field → empty not error.laurus-cli/src/commands/train.rs): from-index e2e (ingest+commit 300 → train →--update-schema→ reopened tiny commit encodes against the shared codebook, which would hard-error without one);--sample-sizeunder from-index; both-sources / no-source rejection; empty-index error.sample_committed_vectorsto returnvec![]fails both from-index e2e tests; restored to green.Verification
cargo fmt --check/cargo clippy --all-targets -- -D warnings: clean on stable and 1.97.0.cargo test -p laurus --lib: 1273 passed (+3).-p laurus-cli --bin laurus: 13 passed (+4). Full-p laurus --tests: green.cargo check -p laurus-wasm: clean.cargo doc: 73 warnings (unchanged baseline). markdownlint EN+JA: 0 errors; both mdBooks build.