Skip to content

feat(cli): train pq-codebook --from-index samples committed vectors (#920 sub-item 1) - #938

Merged
mosuka merged 1 commit into
mainfrom
feat/920-pq-codebook-from-index
Aug 4, 2026
Merged

feat(cli): train pq-codebook --from-index samples committed vectors (#920 sub-item 1)#938
mosuka merged 1 commit into
mainfrom
feat/920-pq-codebook-from-index

Conversation

@mosuka

@mosuka mosuka commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Summary

Changes

  • VectorStore::sample_field_vectors(field, limit) -> Result<Vec<(u64, Vector)>> (new): reader → get_vectors_by_fieldsort 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 yields Ok(vec![]), matching get_vectors_by_field's convention.
  • Engine::sample_committed_vectors(field, sample_size) -> Result<Vec<Vector>> (new): thin delegation.
  • CLI: --input became optional, new --from-index flag; exactly-one-source validation up front; only the vector-collection step branches — the train call and --update-schema handling stay shared. The empty-index case errors with a message naming both remedies.
  • Docs (EN+JA): laurus-cli/commands.md usage/argument table/example (including the lossy-reconstruction caveat for already-PQ-encoded fields); vector_indexing.md shared-codebook section.

Tests

  • Unit ×3 (vector/store.rs): doc_id-ascending ordering, limit truncation / None returns all, unknown field → empty not error.
  • Integration ×4 (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-size under from-index; both-sources / no-source rejection; empty-index error.
  • RED proof: reversibly stubbing sample_committed_vectors to return vec![] 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.
  • wasm32 cargo check -p laurus-wasm: clean. cargo doc: 73 warnings (unchanged baseline). markdownlint EN+JA: 0 errors; both mdBooks build.

…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.
@mosuka
mosuka merged commit d9cafab into main Aug 4, 2026
22 checks passed
@mosuka
mosuka deleted the feat/920-pq-codebook-from-index branch August 4, 2026 14:48
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